fix(node): default webpack build to not perform default optimizations for Node (#16625)
This commit is contained in:
parent
95c0fad6bf
commit
b3d07a8293
@ -64,7 +64,7 @@ describe('Node Applications + webpack', () => {
|
||||
const expressApp = uniq('expressapp');
|
||||
const fastifyApp = uniq('fastifyapp');
|
||||
const koaApp = uniq('koaapp');
|
||||
const nestApp = uniq('koaapp');
|
||||
const nestApp = uniq('nest');
|
||||
|
||||
runCLI(`generate @nx/node:lib ${testLib1}`);
|
||||
runCLI(`generate @nx/node:lib ${testLib2} --importPath=@acme/test2`);
|
||||
@ -98,7 +98,22 @@ describe('Node Applications + webpack', () => {
|
||||
expect(() => runCLI(`lint ${nestApp}-e2e`)).not.toThrow();
|
||||
|
||||
// Only Fastify generates with unit tests since it supports them without additional libraries.
|
||||
expect(() => runCLI(`lint ${fastifyApp}`)).not.toThrow();
|
||||
expect(() => runCLI(`test ${fastifyApp}`)).not.toThrow();
|
||||
|
||||
// https://github.com/nrwl/nx/issues/16601
|
||||
const nestMainContent = readFile(`apps/${nestApp}/src/main.ts`);
|
||||
updateFile(
|
||||
`apps/${nestApp}/src/main.ts`,
|
||||
`
|
||||
${nestMainContent}
|
||||
// Make sure this is not replaced during build time
|
||||
console.log('env: ' + process.env['NODE_ENV']);
|
||||
`
|
||||
);
|
||||
runCLI(`build ${nestApp}`);
|
||||
expect(readFile(`dist/apps/${nestApp}/main.js`)).toContain(
|
||||
`'env: ' + process.env['NODE_ENV']`
|
||||
);
|
||||
|
||||
addLibImport(expressApp, testLib1);
|
||||
addLibImport(expressApp, testLib2, '@acme/test2');
|
||||
|
||||
@ -139,6 +139,11 @@ export function withNx(pluginOptions?: WithNxOptions): NxWebpackPlugin {
|
||||
: undefined,
|
||||
target: options.target,
|
||||
node: false as const,
|
||||
mode:
|
||||
// When the target is Node avoid any optimizations, such as replacing `process.env.NODE_ENV` with build time value.
|
||||
options.target === ('node' as const)
|
||||
? 'none'
|
||||
: // Otherwise, make sure it matches `process.env.NODE_ENV`.
|
||||
// When mode is development or production, webpack will automatically
|
||||
// configure DefinePlugin to replace `process.env.NODE_ENV` with the
|
||||
// build-time value. Thus, we need to make sure it's the same value to
|
||||
@ -146,7 +151,6 @@ export function withNx(pluginOptions?: WithNxOptions): NxWebpackPlugin {
|
||||
//
|
||||
// When the NODE_ENV is something else (e.g. test), then set it to none
|
||||
// to prevent extra behavior from webpack.
|
||||
mode:
|
||||
process.env.NODE_ENV === 'development' ||
|
||||
process.env.NODE_ENV === 'production'
|
||||
? (process.env.NODE_ENV as 'development' | 'production')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user