UNPKG

@serwist/webpack-plugin

Version:

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

35 lines (31 loc) 1.3 kB
import path from 'node:path'; import { toUnix } from '@serwist/utils'; 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(); } }); }); }; const relativeToOutputPath = (compilation, originalPath)=>{ if (path.resolve(originalPath) === path.normalize(originalPath)) { return toUnix(path.relative(compilation.options.output.path, originalPath)); } return originalPath; }; export { performChildCompilation as p, relativeToOutputPath as r };