Skip to content

Commit

Permalink
Merge pull request #44 from shinnoki/feature/fix-replace-minimizer
Browse files Browse the repository at this point in the history
Fix replaceMinimizer to preserve the original config
  • Loading branch information
Karibash committed Oct 1, 2022
2 parents 154060c + 8866f93 commit bfaca66
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-penguins-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"storybook-addon-swc": patch
---

Fix replaceMinimizer to preserve the original config (Fix #43)
1 change: 1 addition & 0 deletions src/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const replaceMinimizer = (options: JsMinifyOptions): (config: Configurati
return (config: Configuration) => ({
...config,
optimization: {
...config.optimization,
minimizer: 0 < config.optimization?.minimizer?.length
? [new TerserPlugin({
minify: TerserPlugin.swcMinify,
Expand Down
5 changes: 5 additions & 0 deletions test/transformers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ describe('replaceMinimizer', () => {
const minimizer = config.optimization?.minimizer?.find(minimizer => minimizer instanceof TerserPlugin);
expect(minimizer.options.minimizer.implementation.name).toEqual('swcMinify');
});

it('Preserve the rest optimization config other than minimizer', () => {
const config = transformer({ optimization: { moduleIds: 'named', minimizer: [] } });
expect(config).toEqual({ optimization: { moduleIds: 'named', minimizer: [] } });
});
});

describe('disableSourceMap', () => {
Expand Down

0 comments on commit bfaca66

Please sign in to comment.