diff --git a/src/plugin.ts b/src/plugin.ts index f992d42..eecadfd 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -37,6 +37,13 @@ const transformAssets = async ( ...transformOptions } = options; + const minimized = ( + transformOptions.minify + || transformOptions.minifyWhitespace + || transformOptions.minifyIdentifiers + || transformOptions.minifySyntax + ); + const assets = (compilation.getAssets() as Asset[]).filter(asset => ( // Filter out already minimized @@ -106,7 +113,7 @@ const transformAssets = async ( ) as any, { ...asset.info, - minimized: true, + minimized, }, ); })); diff --git a/tests/specs/plugin.ts b/tests/specs/plugin.ts index 96dda7c..3c95d05 100644 --- a/tests/specs/plugin.ts +++ b/tests/specs/plugin.ts @@ -176,6 +176,24 @@ export default testSuite(({ describe }, webpack: typeof webpack4 | typeof webpac expect(code).not.toMatch('return '); }); + test('should minify when used alongside plugin', async () => { + const built = await build( + fixtures.minification, + (config) => { + configureEsbuildMinifyPlugin(config); + config.plugins?.push(new EsbuildPlugin()); + }, + webpack, + ); + + expect(built.stats.hasWarnings()).toBe(false); + expect(built.stats.hasErrors()).toBe(false); + + const exportedFunction = built.require('/dist/'); + expect(exportedFunction('hello world')).toBe('hello world'); + assertMinified(exportedFunction.toString()); + }); + test('minify chunks & filter using include/exclude', async () => { const built = await build({ '/src/index.js': `