Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function generate(opts = {}) {
const { paths, plugins, libraryName, config } = opts;
const { absTmpDirPath, absPagesPath } = paths;
const routeConfig = getRouteConfig(absPagesPath);
applyPlugins(plugins, 'generateEntry', null, opts);
// 缓存一次
const routerContent = getRouterContent({
...opts,
routeConfig,
libraryName,
config,
});
if (cachedRouterContent !== routerContent) {
writeFileSync(join(absTmpDirPath, 'router.js'), routerContent, 'utf-8');
cachedRouterContent = routerContent;
}
// library js 不会变化,生成一次即可
if (process.env.DISABLE_UMIJS_G_CACHE || !libraryJSGenerated) {
let entryContent = readFileSync(
const {
routeConfig,
tplPath = join(__dirname, `../template/router.js`),
libraryName,
config,
paths,
plugins,
} = opts;
if (!exists(tplPath)) {
throw new Error('tplPath 不存在');
}
let tpl = readFile(tplPath, 'utf-8');
const routeComponents = getRouteComponents(routeConfig, config, paths);
tpl = applyPlugins(plugins, 'preBuildRouterContent', tpl, {
config,
});
return tpl
.replace(/<%= codeForPlugin %>/g, '')
.replace(/<%= routeComponents %>/g, routeComponents)
.replace(/<%= libraryName %>/g, libraryName);
}