diff --git a/packages/web/src/utils/config.spec.ts b/packages/web/src/utils/config.spec.ts index 8be66631cf..44ef83e748 100644 --- a/packages/web/src/utils/config.spec.ts +++ b/packages/web/src/utils/config.spec.ts @@ -442,16 +442,18 @@ describe('getBaseWebpackPartial', () => { }); }); - it('should support envName overrides', () => { + it('should set envName to production when script optimization is enabled', () => { + const esm = true; + const isScriptOptimizeOn = true; + const emitDecoratorMetadata = true; const result = getBaseWebpackPartial( { ...input, progress: true, }, - true, - true, - true, - 'production' + esm, + isScriptOptimizeOn, + emitDecoratorMetadata ); const rule = result.module.rules.find( @@ -464,5 +466,31 @@ describe('getBaseWebpackPartial', () => { babelrc: true, }); }); + + it('should override envName when script optimization is disabled', () => { + const esm = true; + const isScriptOptimizeOn = false; + const emitDecoratorMetadata = true; + const result = getBaseWebpackPartial( + { + ...input, + progress: true, + }, + esm, + isScriptOptimizeOn, + emitDecoratorMetadata, + 'staging' + ); + + const rule = result.module.rules.find( + (r) => typeof r.loader === 'string' && r.loader.match(/babel-loader/) + ); + expect(rule.options).toMatchObject({ + rootMode: 'upward', + cwd: '/root/root/src', + envName: 'staging', + babelrc: true, + }); + }); }); }); diff --git a/packages/web/src/utils/config.ts b/packages/web/src/utils/config.ts index 4998c0b412..64cdb2b27b 100644 --- a/packages/web/src/utils/config.ts +++ b/packages/web/src/utils/config.ts @@ -57,7 +57,7 @@ export function getBaseWebpackPartial( cwd: join(options.root, options.sourceRoot), emitDecoratorMetadata, isModern: esm, - envName: configuration, + envName: isScriptOptimizeOn ? 'production' : configuration, babelrc: true, cacheDirectory: true, cacheCompression: false,