Skip to content

Commit

Permalink
fix(plugin): mark assets as minimized only when minified (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber authored Aug 29, 2023
1 parent 7d6e482 commit a5fddd0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -106,7 +113,7 @@ const transformAssets = async (
) as any,

Check warning on line 113 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Test

Unexpected any. Specify a different type

Check warning on line 113 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / Release

Unexpected any. Specify a different type
{
...asset.info,
minimized: true,
minimized,
},
);
}));
Expand Down
18 changes: 18 additions & 0 deletions tests/specs/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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': `
Expand Down

0 comments on commit a5fddd0

Please sign in to comment.