Skip to content

Commit a5fddd0

Browse files
fix(plugin): mark assets as minimized only when minified (#338)
1 parent 7d6e482 commit a5fddd0

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/plugin.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ const transformAssets = async (
3737
...transformOptions
3838
} = options;
3939

40+
const minimized = (
41+
transformOptions.minify
42+
|| transformOptions.minifyWhitespace
43+
|| transformOptions.minifyIdentifiers
44+
|| transformOptions.minifySyntax
45+
);
46+
4047
const assets = (compilation.getAssets() as Asset[]).filter(asset => (
4148

4249
// Filter out already minimized
@@ -106,7 +113,7 @@ const transformAssets = async (
106113
) as any,
107114
{
108115
...asset.info,
109-
minimized: true,
116+
minimized,
110117
},
111118
);
112119
}));

tests/specs/plugin.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,24 @@ export default testSuite(({ describe }, webpack: typeof webpack4 | typeof webpac
176176
expect(code).not.toMatch('return ');
177177
});
178178

179+
test('should minify when used alongside plugin', async () => {
180+
const built = await build(
181+
fixtures.minification,
182+
(config) => {
183+
configureEsbuildMinifyPlugin(config);
184+
config.plugins?.push(new EsbuildPlugin());
185+
},
186+
webpack,
187+
);
188+
189+
expect(built.stats.hasWarnings()).toBe(false);
190+
expect(built.stats.hasErrors()).toBe(false);
191+
192+
const exportedFunction = built.require('/dist/');
193+
expect(exportedFunction('hello world')).toBe('hello world');
194+
assertMinified(exportedFunction.toString());
195+
});
196+
179197
test('minify chunks & filter using include/exclude', async () => {
180198
const built = await build({
181199
'/src/index.js': `

0 commit comments

Comments
 (0)