UNPKG

@serwist/webpack-plugin

Version:

A plugin for your webpack build process, helping you generate a manifest of local files that should be precached.

38 lines (33 loc) 1.36 kB
import path from 'node:path'; const toUnix = (p)=>{ return p.replace(/\\/g, "/").replace(/(?<!^)\/+/g, "/"); }; const relativeToOutputPath = (compilation, originalPath)=>{ if (path.resolve(originalPath) === path.normalize(originalPath)) { return toUnix(path.relative(compilation.options.output.path, originalPath)); } return originalPath; }; const performChildCompilation = async (compiler, compilation, name, src, dest, plugins)=>{ const childCompiler = compilation.createChildCompiler(name, { filename: dest }, plugins); new compiler.webpack.webworker.WebWorkerTemplatePlugin().apply(childCompiler); new compiler.webpack.EntryPlugin(compiler.context, src, name).apply(childCompiler); await new Promise((resolve, reject)=>{ childCompiler.runAsChild((error, _entries, childCompilation)=>{ if (error) { reject(error); } else { if (childCompilation?.warnings) { compilation.warnings.push(...childCompilation.warnings); } if (childCompilation?.errors) { compilation.errors.push(...childCompilation.errors); } resolve(); } }); }); }; export { performChildCompilation as p, relativeToOutputPath as r, toUnix as t };