export default async()

in packages/plugin-dll/src/buildDll.ts [12:59]


export default async (api: PluginAPI, option: IOption) => {
  const { dllLib, dllOutputDir = resolve(api.getCwd(), 'dll') } = option;

  const depNames = sortedUniq([
    ...VENDER,
    ...dllLib ? dllLib : [],
  ]);

  let deps = getDeps(dllOutputDir);

  if (deps) {
    const cachedFiles = deps.deps;
    if (cachedFiles && cachedFiles.join(', ') === depNames.join(', ')) {
      return;
    }
  } else {
    deps = {
      dllName: '',
      deps: depNames
    };
  }

  deps.dllName = option.dllName ? `${option.dllName}.js` : `breezr.${Date.now()}.dll.js`;

  // dll only build in NODE_ENV=production
  // tmp set env to prod mode
  // and it will restore env after build dll
  const cachedEnv = process.env.NODE_ENV;
  process.env.NODE_ENV = 'production';

  try {
    info('building dll');

    await buildDll(api, dllOutputDir, deps);
    writeDeps(dllOutputDir, {
      ...deps,
      deps: depNames
    });

    info('dll build successfully!');
  } catch(e) {
    error(e.toString());
    debug('dll', e.stack);
    exit(0);
  }

  process.env.NODE_ENV = cachedEnv;
};