mirror of https://github.com/alibaba/ice.git
fix: codeSplitting is not works when using with splitChunks
This commit is contained in:
parent
44e4665f87
commit
4b293018ca
|
|
@ -0,0 +1,8 @@
|
|||
import { defineConfig } from '@ice/app';
|
||||
import defaultConfig from './ice.config.mjs';
|
||||
|
||||
export default defineConfig(() => ({
|
||||
...defaultConfig,
|
||||
codeSplitting: false,
|
||||
minify: false,
|
||||
}));
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import { defineConfig } from '@ice/app';
|
||||
import defaultConfig from './ice.config.mjs';
|
||||
|
||||
export default defineConfig(() => ({
|
||||
...defaultConfig,
|
||||
splitChunks: false,
|
||||
codeSplitting: false,
|
||||
minify: false,
|
||||
}));
|
||||
|
|
@ -463,31 +463,27 @@ const userConfig = [
|
|||
name: 'splitChunks',
|
||||
validation: 'boolean',
|
||||
defaultValue: true,
|
||||
setConfig: (config: Config, splitChunks: UserConfig['splitChunks'], context: UserConfigContext) => {
|
||||
const { originalUserConfig } = context;
|
||||
// Make sure config.splitChunks is not overwritten when codeSplitting is set.
|
||||
if (!('codeSplitting' in originalUserConfig)) {
|
||||
config.splitChunks = splitChunks;
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'codeSplitting',
|
||||
validation: 'boolean|string',
|
||||
defaultValue: true,
|
||||
setConfig: (config: Config, codeSplitting: UserConfig['codeSplitting'], context: UserConfigContext) => {
|
||||
const { originalUserConfig } = context;
|
||||
if ('splitChunks' in originalUserConfig) {
|
||||
logger.warn(
|
||||
'splitChunks is deprecated, please use codeSplitting instead.https://ice.work/docs/guide/basic/config#codesplitting',
|
||||
);
|
||||
} else {
|
||||
const { originalUserConfig, userConfig } = context;
|
||||
if ('codeSplitting' in originalUserConfig) {
|
||||
// When codeSplitting is set to false / router, do not config splitChunks.
|
||||
if (codeSplitting === false || codeSplitting === 'page') {
|
||||
config.splitChunks = false;
|
||||
} else {
|
||||
config.splitChunks = codeSplitting;
|
||||
}
|
||||
} else {
|
||||
config.splitChunks = userConfig.splitChunks;
|
||||
}
|
||||
if ('splitChunks' in originalUserConfig) {
|
||||
logger.warn(
|
||||
'splitChunks is deprecated, please use codeSplitting instead. https://ice.work/docs/guide/basic/config#codesplitting',
|
||||
);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -65,6 +65,30 @@ describe(`build ${example}`, () => {
|
|||
expect(files.length).toBe(11);
|
||||
});
|
||||
|
||||
test('disable codeSplitting', async () => {
|
||||
await buildFixture(example, {
|
||||
config: 'codeSplitting.config.mts',
|
||||
});
|
||||
const res = await setupBrowser({ example });
|
||||
page = res.page;
|
||||
browser = res.browser;
|
||||
|
||||
const files = fs.readdirSync(path.join(__dirname, `../../examples/${example}/build/js`), 'utf-8');
|
||||
expect(files.length).toBe(5);
|
||||
});
|
||||
|
||||
test('disable splitChunks and codeSplitting', async () => {
|
||||
await buildFixture(example, {
|
||||
config: 'splitChunksWithCodeSplitting.config.mts',
|
||||
});
|
||||
const res = await setupBrowser({ example });
|
||||
page = res.page;
|
||||
browser = res.browser;
|
||||
|
||||
const files = fs.readdirSync(path.join(__dirname, `../../examples/${example}/build/js`), 'utf-8');
|
||||
expect(files.length).toBe(5);
|
||||
});
|
||||
|
||||
test('render route config when downgrade to CSR.', async () => {
|
||||
await page.push('/downgrade.html');
|
||||
expect(await page.$$text('title')).toStrictEqual(['']);
|
||||
|
|
|
|||
Loading…
Reference in New Issue