How to use the umi-plugin.applyPlugins function in umi-plugin

To help you get started, we’ve selected a few umi-plugin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github umijs / umi / packages / umi-build-dev / src / generateEntry.js View on Github external
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(
github umijs / umi / packages / umi-build-dev / src / getRouterContent.js View on Github external
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);
}

umi-plugin

Simple plugin system for umi.

MIT
Latest version published 7 years ago

Package Health Score

66 / 100
Full package analysis

Popular umi-plugin functions

Similar packages