Merge pull request #9559 from tschaub/minify-worker

Minify worker
This commit is contained in:
Tim Schaub
2019-05-16 14:20:11 -06:00
committed by GitHub
2 changed files with 24 additions and 15 deletions
+9 -1
View File
@@ -3,7 +3,15 @@ const build = require('../../tasks/serialize-workers').build;
function loader() { function loader() {
const callback = this.async(); const callback = this.async();
build(this.resource, {minify: false}) let minify = false;
// TODO: remove when https://github.com/webpack/webpack/issues/6496 is addressed
const compilation = this._compilation;
if (compilation) {
minify = compilation.compiler.options.mode === 'production';
}
build(this.resource, {minify})
.then(chunk => { .then(chunk => {
for (const filePath in chunk.modules) { for (const filePath in chunk.modules) {
this.addDependency(filePath); this.addDependency(filePath);
+9 -8
View File
@@ -29,8 +29,14 @@ async function build(input, {minify = true} = {}) {
} }
] ]
] ]
}), })
{ ];
if (minify) {
plugins.push(terser());
}
plugins.push({
name: 'serialize worker and export create function', name: 'serialize worker and export create function',
renderChunk(code) { renderChunk(code) {
return ` return `
@@ -42,12 +48,7 @@ async function build(input, {minify = true} = {}) {
} }
`; `;
} }
} });
];
if (minify) {
plugins.push(terser());
}
const bundle = await rollup.rollup({input, plugins}); const bundle = await rollup.rollup({input, plugins});
const {output} = await bundle.generate({format: 'es'}); const {output} = await bundle.generate({format: 'es'});