diff --git a/package.json b/package.json index c876c581..6de26c99 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "@umijs/core": "^4.0.17", "@umijs/utils": "^4.0.17", "@vercel/ncc": "0.33.3", + "babel-plugin-dynamic-import-node": "2.3.3", "babel-plugin-module-resolver": "4.1.0", "babel-plugin-react-require": "3.1.3", "babel-plugin-transform-define": "2.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b896c7fe..10dc7114 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -19,6 +19,7 @@ importers: '@umijs/utils': ^4.0.17 '@vercel/ncc': 0.33.3 '@zerollup/ts-transform-paths': 1.7.18 + babel-plugin-dynamic-import-node: 2.3.3 babel-plugin-module-resolver: 4.1.0 babel-plugin-react-require: 3.1.3 babel-plugin-transform-define: 2.0.1 @@ -48,6 +49,7 @@ importers: '@umijs/core': 4.0.17 '@umijs/utils': 4.0.17 '@vercel/ncc': 0.33.3 + babel-plugin-dynamic-import-node: 2.3.3 babel-plugin-module-resolver: 4.1.0 babel-plugin-react-require: 3.1.3 babel-plugin-transform-define: 2.0.1 @@ -2215,8 +2217,7 @@ packages: /babel-plugin-dynamic-import-node/2.3.3: resolution: {integrity: sha512-jZVI+s9Zg3IqA/kdi0i6UDCybUI3aSBLnglhYbSSjKlV7yF1F/5LWv8MakQmvYpnbJDS6fcBL2KzHSxNCMtWSQ==} dependencies: - object.assign: 4.1.2 - dev: true + object.assign: 4.1.4 /babel-plugin-istanbul/6.1.1: resolution: {integrity: sha512-Y1IQok9821cC9onCx5otgFfRm7Lm+I+wwxOx738M/WLPZ9Q42m4IG5W0FNX8WLL2gYMZo3JkuXIH2DOpWM+qwA==} @@ -5591,16 +5592,6 @@ packages: resolution: {integrity: sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==} engines: {node: '>= 0.4'} - /object.assign/4.1.2: - resolution: {integrity: sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ==} - engines: {node: '>= 0.4'} - dependencies: - call-bind: 1.0.2 - define-properties: 1.1.4 - has-symbols: 1.0.3 - object-keys: 1.1.1 - dev: true - /object.assign/4.1.4: resolution: {integrity: sha512-1mxKf0e58bvyjSCtKYY4sRe9itRk3PJpquJOjeIkz885CczcI4IvJJDLPS72oowuSh+pBxUFROpX+TU++hxhZQ==} engines: {node: '>= 0.4'} @@ -5609,7 +5600,6 @@ packages: define-properties: 1.1.4 has-symbols: 1.0.3 object-keys: 1.1.1 - dev: false /object.entries/1.1.5: resolution: {integrity: sha512-TyxmjUoZggd4OrrU1W66FMDG6CuqJxsFvymeyXI51+vQLN67zYfZseptRge703kKQdo4uccgAKebXFcRCzk4+g==} diff --git a/src/builder/bundle/index.ts b/src/builder/bundle/index.ts index aaad4a88..7dfa9477 100644 --- a/src/builder/bundle/index.ts +++ b/src/builder/bundle/index.ts @@ -70,6 +70,7 @@ export default async (opts: { pluginDynamicImportNode: false, }, ], + beforeBabelPlugins: [require.resolve('babel-plugin-dynamic-import-node')], extraBabelPresets: config.extraBabelPresets, extraBabelPlugins: config.extraBabelPlugins, diff --git a/tests/fixtures/build/bundle-dynamic-import/.fatherrc.ts b/tests/fixtures/build/bundle-dynamic-import/.fatherrc.ts new file mode 100644 index 00000000..3ee63fdc --- /dev/null +++ b/tests/fixtures/build/bundle-dynamic-import/.fatherrc.ts @@ -0,0 +1,3 @@ +export default { + umd: {}, +}; diff --git a/tests/fixtures/build/bundle-dynamic-import/expect.ts b/tests/fixtures/build/bundle-dynamic-import/expect.ts new file mode 100644 index 00000000..69e27067 --- /dev/null +++ b/tests/fixtures/build/bundle-dynamic-import/expect.ts @@ -0,0 +1,4 @@ +export default (files: Record) => { + // expect single dist file (no async chunks) + expect(Object.keys(files)).toHaveLength(1); +}; diff --git a/tests/fixtures/build/bundle-dynamic-import/package.json b/tests/fixtures/build/bundle-dynamic-import/package.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/tests/fixtures/build/bundle-dynamic-import/package.json @@ -0,0 +1 @@ +{} diff --git a/tests/fixtures/build/bundle-dynamic-import/src/dynamic.ts b/tests/fixtures/build/bundle-dynamic-import/src/dynamic.ts new file mode 100644 index 00000000..2d1ec238 --- /dev/null +++ b/tests/fixtures/build/bundle-dynamic-import/src/dynamic.ts @@ -0,0 +1 @@ +export default () => {}; diff --git a/tests/fixtures/build/bundle-dynamic-import/src/index.ts b/tests/fixtures/build/bundle-dynamic-import/src/index.ts new file mode 100644 index 00000000..251dbb98 --- /dev/null +++ b/tests/fixtures/build/bundle-dynamic-import/src/index.ts @@ -0,0 +1,3 @@ +export default async () => { + (await import('./dynamic')).default(); +};