Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
generateRouterJS() {
const { paths } = this.service;
const { absRouterJSPath } = paths;
this.RoutesManager.fetchRoutes();
const routesContent = this.getRouterJSContent();
// 避免文件写入导致不必要的 webpack 编译
if (this.routesContent !== routesContent) {
writeFileSync(absRouterJSPath, prettierFile(`${routesContent.trim()}\n`), 'utf-8');
this.routesContent = routesContent;
this.service.applyPlugins('onRouteChange');
}
}
let history = this.service.applyPlugins('modifyEntryHistory', {
initialValue: initialHistory,
});
if (config.ssr) {
history = `
__IS_BROWSER ? ${initialHistory} : require('history').createMemoryHistory({
// for history object in dva
initialEntries: [global.req ? global.req.url : '/']
})
`.trim();
}
const content = Mustache.render(tpl, {
globalVariables: !this.service.config.disableGlobalVariables,
history,
});
writeContent(join(paths.absTmpDirPath, 'history.js'), prettierFile(`${content.trim()}\n`));
}
initialValue: [],
}),
).join('\n'),
polyfillImports: importsToStr(
this.service.applyPlugins('addEntryPolyfillImports', {
initialValue: [],
}),
).join('\n'),
moduleBeforeRenderer,
render: initialRender,
plugins,
validKeys,
htmlTemplateMap: htmlTemplateMap.join('\n'),
findRoutePath: winPath(require.resolve('./findRoute')),
});
writeContent(paths.absLibraryJSPath, prettierFile(`${entryContent.trim()}\n`));
}