Skip to content

Commit da8b855

Browse files
authored
fix(webpack): allow optimization to be turned off via CLI (#14431)
1 parent 2773f40 commit da8b855

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

e2e/node/src/node-webpack.test.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import {
2-
checkFilesDoNotExist,
32
checkFilesExist,
43
cleanupProject,
54
newProject,
5+
readFile,
66
runCLI,
77
runCLIAsync,
88
tmpProjPath,
99
uniq,
1010
updateFile,
1111
} from '@nrwl/e2e/utils';
1212
import { execSync } from 'child_process';
13+
import { read } from 'fs-extra';
1314

1415
describe('Node Applications + webpack', () => {
1516
beforeEach(() => newProject());
@@ -23,13 +24,29 @@ describe('Node Applications + webpack', () => {
2324

2425
checkFilesExist(`apps/${app}/webpack.config.js`);
2526

26-
updateFile(`apps/${app}/src/main.ts`, `console.log('Hello World!');`);
27+
updateFile(
28+
`apps/${app}/src/main.ts`,
29+
`
30+
function foo(x: string) {
31+
return "foo " + x;
32+
};
33+
console.log(foo("bar"));
34+
`
35+
);
2736
await runCLIAsync(`build ${app}`);
2837

2938
checkFilesExist(`dist/apps/${app}/main.js`);
39+
// no optimization by default
40+
const content = readFile(`dist/apps/${app}/main.js`);
41+
expect(content).toContain('console.log(foo("bar"))');
42+
3043
const result = execSync(`node dist/apps/${app}/main.js`, {
3144
cwd: tmpProjPath(),
3245
}).toString();
33-
expect(result).toMatch(/Hello World!/);
46+
expect(result).toMatch(/foo bar/);
47+
48+
await runCLIAsync(`build ${app} --optimization`);
49+
const optimizedContent = readFile(`dist/apps/${app}/main.js`);
50+
expect(optimizedContent).toContain('console.log("foo "+"bar")');
3451
}, 300_000);
3552
});

packages/webpack/src/utils/with-nx.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,10 @@ export function withNx(opts?: { skipTypeChecking?: boolean }) {
185185
optimization: {
186186
...config.optimization,
187187
sideEffects: true,
188-
minimize: !!options.optimization,
188+
minimize:
189+
typeof options.optimization === 'object'
190+
? !!options.optimization.scripts
191+
: !!options.optimization,
189192
minimizer: [
190193
options.compiler !== 'swc'
191194
? new TerserPlugin({

0 commit comments

Comments
 (0)