Skip to content

Commit

Permalink
fix(webpack): allow optimization to be turned off via CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo authored and Jack Hsu committed Jan 17, 2023
1 parent e0bd338 commit 8c341ad
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
23 changes: 20 additions & 3 deletions e2e/node/src/node-webpack.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import {
checkFilesDoNotExist,
checkFilesExist,
cleanupProject,
newProject,
readFile,
runCLI,
runCLIAsync,
tmpProjPath,
uniq,
updateFile,
} from '@nrwl/e2e/utils';
import { execSync } from 'child_process';
import { read } from 'fs-extra';

describe('Node Applications + webpack', () => {
beforeEach(() => newProject());
Expand All @@ -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);
});
5 changes: 4 additions & 1 deletion packages/webpack/src/utils/with-nx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 8c341ad

Please sign in to comment.