Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support config.dynamicImportSyntax for syntax only #6014

Merged
merged 1 commit into from
Jan 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,21 @@ export default () => {

构建之后使用低网络模拟就能看到效果。

## dynamicImportSyntax

* Type: `object`
* Default: `false`

如果你不需要路由按需加载,只需要支持 `import()` 语法的 code splitting,可使用此配置。

比如:

```js
export default {
dynamicImportSyntax: {},
}
```

## exportStatic

* Type: `object`
Expand Down
15 changes: 15 additions & 0 deletions docs/config/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,21 @@ export default () => {

构建之后使用低网络模拟就能看到效果。

## dynamicImportSyntax

* Type: `object`
* Default: `false`

如果你不需要路由按需加载,只需要支持 `import()` 语法的 code splitting,可使用此配置。

比如:

```js
export default {
dynamicImportSyntax: {},
}
```

## exportStatic

* Type: `object`
Expand Down
6 changes: 4 additions & 2 deletions packages/bundler-utils/src/getBabelOpts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ function getBasicBabelLoaderOpts({ cwd }: { cwd: string }) {
}

export function getBabelPresetOpts(opts: IOpts) {
const { config } = opts;
return {
// @ts-ignore
nodeEnv: opts.env,
dynamicImportNode: !opts.config.dynamicImport,
dynamicImportNode: !config.dynamicImport && !config.dynamicImportSyntax,
autoCSSModules: true,
svgr: true,
env: {
Expand Down Expand Up @@ -74,7 +75,8 @@ export function getBabelDepsOpts({
require.resolve('@umijs/babel-preset-umi/dependency'),
{
nodeEnv: env,
dynamicImportNode: !config.dynamicImport,
dynamicImportNode:
!config.dynamicImport && !config.dynamicImportSyntax,
},
],
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { IApi } from '@umijs/types';

export default (api: IApi) => {
api.describe({
key: 'dynamicImportSyntax',
config: {
schema(joi) {
return joi
.object()
.description('Code splitting for import statement syntax');
},
},
});
};
1 change: 1 addition & 0 deletions packages/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ export interface BaseIConfig extends IConfigCore {
dynamicImport?: {
loading?: string;
};
dynamicImportSyntax?: {};
exportStatic?: {
htmlSuffix?: boolean;
dynamicRoot?: boolean;
Expand Down