fix(webpack): allow optimization to be turned off via CLI (#14431)

This commit is contained in:
Jack Hsu 2023-01-17 11:55:14 -05:00 committed by GitHub
parent 2773f40202
commit da8b855c6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 4 deletions

View File

@ -1,8 +1,8 @@
import {
checkFilesDoNotExist,
checkFilesExist,
cleanupProject,
newProject,
readFile,
runCLI,
runCLIAsync,
tmpProjPath,
@ -10,6 +10,7 @@ import {
updateFile,
} from '@nrwl/e2e/utils';
import { execSync } from 'child_process';
import { read } from 'fs-extra';
describe('Node Applications + webpack', () => {
beforeEach(() => newProject());
@ -23,13 +24,29 @@ describe('Node Applications + webpack', () => {
checkFilesExist(`apps/${app}/webpack.config.js`);
updateFile(`apps/${app}/src/main.ts`, `console.log('Hello World!');`);
updateFile(
`apps/${app}/src/main.ts`,
`
function foo(x: string) {
return "foo " + x;
};
console.log(foo("bar"));
`
);
await runCLIAsync(`build ${app}`);
checkFilesExist(`dist/apps/${app}/main.js`);
// no optimization by default
const content = readFile(`dist/apps/${app}/main.js`);
expect(content).toContain('console.log(foo("bar"))');
const result = execSync(`node dist/apps/${app}/main.js`, {
cwd: tmpProjPath(),
}).toString();
expect(result).toMatch(/Hello World!/);
expect(result).toMatch(/foo bar/);
await runCLIAsync(`build ${app} --optimization`);
const optimizedContent = readFile(`dist/apps/${app}/main.js`);
expect(optimizedContent).toContain('console.log("foo "+"bar")');
}, 300_000);
});

View File

@ -185,7 +185,10 @@ export function withNx(opts?: { skipTypeChecking?: boolean }) {
optimization: {
...config.optimization,
sideEffects: true,
minimize: !!options.optimization,
minimize:
typeof options.optimization === 'object'
? !!options.optimization.scripts
: !!options.optimization,
minimizer: [
options.compiler !== 'swc'
? new TerserPlugin({