From a69f8abdf912a48b0e3f923bf1d1c73c5487e05b Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Wed, 8 Mar 2023 12:32:29 -0500 Subject: [PATCH] fix(node): add default build configuration (#15542) --- e2e/node/src/node-esbuild.test.ts | 1 - .../generators/application/application.spec.ts | 12 +++++++----- .../src/generators/application/application.ts | 17 +++++++++++++---- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/e2e/node/src/node-esbuild.test.ts b/e2e/node/src/node-esbuild.test.ts index 0509ee365b9c6..16d68a9fce20e 100644 --- a/e2e/node/src/node-esbuild.test.ts +++ b/e2e/node/src/node-esbuild.test.ts @@ -27,7 +27,6 @@ describe('Node Applications + esbuild', () => { await runCLIAsync(`build ${app}`); checkFilesExist(`dist/apps/${app}/main.js`); - checkFilesExist(`dist/apps/${app}/main.js.map`); const result = execSync(`node dist/apps/${app}/main.js`, { cwd: tmpProjPath(), }).toString(); diff --git a/packages/node/src/generators/application/application.spec.ts b/packages/node/src/generators/application/application.spec.ts index 6a58d3ade1efd..8097a8fe71dcb 100644 --- a/packages/node/src/generators/application/application.spec.ts +++ b/packages/node/src/generators/application/application.spec.ts @@ -49,6 +49,7 @@ describe('app', () => { build: { executor: '@nrwl/webpack:webpack', outputs: ['{options.outputPath}'], + defaultConfiguration: 'production', options: { target: 'node', compiler: 'tsc', @@ -60,19 +61,20 @@ describe('app', () => { assets: ['my-node-app/src/assets'], }, configurations: { - production: { - optimization: true, - extractLicenses: true, - inspect: false, - }, + development: {}, + production: {}, }, }, serve: { executor: '@nrwl/js:node', + defaultConfiguration: 'development', options: { buildTarget: 'my-node-app:build', }, configurations: { + development: { + buildTarget: 'my-node-app:build:development', + }, production: { buildTarget: 'my-node-app:build:production', }, diff --git a/packages/node/src/generators/application/application.ts b/packages/node/src/generators/application/application.ts index f98655d65e608..3e048556dac58 100644 --- a/packages/node/src/generators/application/application.ts +++ b/packages/node/src/generators/application/application.ts @@ -58,6 +58,7 @@ function getWebpackBuildConfig( return { executor: `@nrwl/webpack:webpack`, outputs: ['{options.outputPath}'], + defaultConfiguration: 'production', options: { target: 'node', compiler: 'tsc', @@ -78,11 +79,9 @@ function getWebpackBuildConfig( ), }, configurations: { + development: {}, production: { ...(options.docker && { generateLockfile: true }), - optimization: true, - extractLicenses: true, - inspect: false, }, }, }; @@ -95,6 +94,7 @@ function getEsBuildConfig( return { executor: '@nrwl/esbuild:esbuild', outputs: ['{options.outputPath}'], + defaultConfiguration: 'production', options: { platform: 'node', outputPath: joinPathFragments( @@ -117,9 +117,14 @@ function getEsBuildConfig( }, }, configurations: { + development: {}, production: { ...(options.docker && { generateLockfile: true }), - esbuildOptions: { sourcemap: false }, + esbuildOptions: { + sourcemap: false, + // Generate CJS files as .js so imports can be './foo' rather than './foo.cjs'. + outExtension: { '.js': '.js' }, + }, }, }, }; @@ -128,10 +133,14 @@ function getEsBuildConfig( function getServeConfig(options: NormalizedSchema): TargetConfiguration { return { executor: '@nrwl/js:node', + defaultConfiguration: 'development', options: { buildTarget: `${options.name}:build`, }, configurations: { + development: { + buildTarget: `${options.name}:build:development`, + }, production: { buildTarget: `${options.name}:build:production`, },