fix(web): set envName to production when script optimization is enabled (#5522)

ISSUES CLOSED: #5512
This commit is contained in:
Noriyuki Shinpuku 2021-05-14 21:51:29 +09:00 committed by GitHub
parent 9258ef3816
commit cd3dd9431a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 6 deletions

View File

@ -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,
});
});
});
});

View File

@ -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,