diff --git a/docs/config/README.md b/docs/config/README.md
index 38a1da387518..404da96201cb 100644
--- a/docs/config/README.md
+++ b/docs/config/README.md
@@ -1249,3 +1249,10 @@ export default {
包含以下子配置项:
- lazyCompilation,是否启用基于路由的按需编译
+
+## workerLoader 3.4.1+
+
+- Type: `object`
+- Default: `false`
+
+开启 worker-loader 功能。
diff --git a/docs/config/README.zh-CN.md b/docs/config/README.zh-CN.md
index 5c26cb5749b4..549aed16e904 100644
--- a/docs/config/README.zh-CN.md
+++ b/docs/config/README.zh-CN.md
@@ -1248,3 +1248,10 @@ export default {
包含以下子配置项:
- lazyCompilation,是否启用基于路由的按需编译
+
+## workerLoader 3.4.1+
+
+- Type: `object`
+- Default: `false`
+
+开启 worker-loader 功能。
diff --git a/packages/bundler-webpack/package.json b/packages/bundler-webpack/package.json
index f0ff463c750f..aa5a198993a4 100644
--- a/packages/bundler-webpack/package.json
+++ b/packages/bundler-webpack/package.json
@@ -34,7 +34,7 @@
},
"dependencies": {
"@umijs/bundler-utils": "3.4.0",
- "@umijs/deps": "0.2.34",
+ "@umijs/deps": "0.3.3",
"@umijs/types": "3.4.0",
"@umijs/utils": "3.4.0",
"jest-worker": "26.6.2",
diff --git a/packages/bundler-webpack/src/fixtures/worker-loader/config.ts b/packages/bundler-webpack/src/fixtures/worker-loader/config.ts
new file mode 100644
index 000000000000..43b1edb8ff4c
--- /dev/null
+++ b/packages/bundler-webpack/src/fixtures/worker-loader/config.ts
@@ -0,0 +1,3 @@
+export default {
+ workerLoader: {},
+}
diff --git a/packages/bundler-webpack/src/fixtures/worker-loader/expect.ts b/packages/bundler-webpack/src/fixtures/worker-loader/expect.ts
new file mode 100644
index 000000000000..425a5bcf18c3
--- /dev/null
+++ b/packages/bundler-webpack/src/fixtures/worker-loader/expect.ts
@@ -0,0 +1,7 @@
+import { IExpectOpts } from '../types';
+
+export default ({ indexJS, files }: IExpectOpts) => {
+ expect(files).toContain('index.js');
+ expect(files).toContain('worker.worker.js');
+ expect(indexJS).toContain(`return new Worker(__webpack_require__.p + "worker.worker.js");`);
+}
diff --git a/packages/bundler-webpack/src/fixtures/worker-loader/index.ts b/packages/bundler-webpack/src/fixtures/worker-loader/index.ts
new file mode 100644
index 000000000000..27dc227c3566
--- /dev/null
+++ b/packages/bundler-webpack/src/fixtures/worker-loader/index.ts
@@ -0,0 +1,4 @@
+import Worker from './worker';
+
+const worker = new Worker();
+worker.postMessage('aaaa');
diff --git a/packages/bundler-webpack/src/fixtures/worker-loader/worker.js b/packages/bundler-webpack/src/fixtures/worker-loader/worker.js
new file mode 100644
index 000000000000..b4d249d7a21c
--- /dev/null
+++ b/packages/bundler-webpack/src/fixtures/worker-loader/worker.js
@@ -0,0 +1,4 @@
+
+self.addEventListener('message', (e) => {
+ console.log('message received');
+});
diff --git a/packages/bundler-webpack/src/getConfig/getConfig.ts b/packages/bundler-webpack/src/getConfig/getConfig.ts
index 4b9d9f8bf8d9..32f748bf61d6 100644
--- a/packages/bundler-webpack/src/getConfig/getConfig.ts
+++ b/packages/bundler-webpack/src/getConfig/getConfig.ts
@@ -352,6 +352,16 @@ export default async function getConfig(
.use('raw-loader')
.loader(require.resolve('@umijs/deps/compiled/raw-loader'));
+ if (config.workerLoader) {
+ // prettier-ignore
+ webpackConfig.module
+ .rule('worker')
+ .test(/.*worker.(ts|js)/)
+ .use('worker-loader')
+ .loader(require.resolve('@umijs/deps/compiled/worker-loader'))
+ .options(config.workerLoader);
+ }
+
// css
css({
type,
diff --git a/packages/core/package.json b/packages/core/package.json
index b8710ecce6e9..6cc50ab0a2de 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -26,7 +26,7 @@
"dependencies": {
"@umijs/ast": "3.4.0",
"@umijs/babel-preset-umi": "3.4.0",
- "@umijs/deps": "0.2.34",
+ "@umijs/deps": "0.3.3",
"@umijs/utils": "3.4.0"
}
}
diff --git a/packages/preset-built-in/package.json b/packages/preset-built-in/package.json
index 577728668903..c089231bef44 100644
--- a/packages/preset-built-in/package.json
+++ b/packages/preset-built-in/package.json
@@ -28,7 +28,7 @@
"@types/react-router-config": "5.0.1",
"@umijs/babel-preset-umi": "3.4.0",
"@umijs/bundler-webpack": "3.4.0",
- "@umijs/deps": "0.2.34",
+ "@umijs/deps": "0.3.3",
"@umijs/renderer-mpa": "3.4.0",
"@umijs/renderer-react": "3.4.0",
"@umijs/runtime": "3.4.0",
diff --git a/packages/preset-built-in/src/index.ts b/packages/preset-built-in/src/index.ts
index 6c7940a6ff9d..0bb83a69e212 100644
--- a/packages/preset-built-in/src/index.ts
+++ b/packages/preset-built-in/src/index.ts
@@ -67,6 +67,7 @@ export default function () {
require.resolve('./plugins/features/umiInfo'),
require.resolve('./plugins/features/runtimeHistory'),
require.resolve('./plugins/features/webpack5'),
+ require.resolve('./plugins/features/workerLoader'),
// html
require.resolve('./plugins/features/html/favicon'),
diff --git a/packages/preset-built-in/src/plugins/features/workerLoader.ts b/packages/preset-built-in/src/plugins/features/workerLoader.ts
new file mode 100644
index 000000000000..456afc9c31e3
--- /dev/null
+++ b/packages/preset-built-in/src/plugins/features/workerLoader.ts
@@ -0,0 +1,12 @@
+import { IApi } from '@umijs/types';
+
+export default (api: IApi) => {
+ api.describe({
+ key: 'workerLoader',
+ config: {
+ schema(joi) {
+ return joi.object();
+ },
+ },
+ });
+};
diff --git a/packages/server/package.json b/packages/server/package.json
index 98017594997e..f36051fba41d 100644
--- a/packages/server/package.json
+++ b/packages/server/package.json
@@ -24,7 +24,7 @@
"access": "public"
},
"dependencies": {
- "@umijs/deps": "0.2.34",
+ "@umijs/deps": "0.3.3",
"@umijs/utils": "3.4.0"
}
}
diff --git a/packages/types/package.json b/packages/types/package.json
index 1e82f87f7c8d..8ead92abf220 100644
--- a/packages/types/package.json
+++ b/packages/types/package.json
@@ -27,7 +27,7 @@
"dependencies": {
"@umijs/babel-preset-umi": "3.4.0",
"@umijs/core": "3.4.0",
- "@umijs/deps": "0.2.34",
+ "@umijs/deps": "0.3.3",
"@umijs/server": "3.4.0",
"@umijs/utils": "3.4.0",
"webpack-chain": "6.5.1"
diff --git a/packages/umi/package.json b/packages/umi/package.json
index 441550ce965a..9f4cf60e5d94 100644
--- a/packages/umi/package.json
+++ b/packages/umi/package.json
@@ -30,7 +30,7 @@
"dependencies": {
"@umijs/bundler-webpack": "3.4.0",
"@umijs/core": "3.4.0",
- "@umijs/deps": "0.2.34",
+ "@umijs/deps": "0.3.3",
"@umijs/preset-built-in": "3.4.0",
"@umijs/runtime": "3.4.0",
"@umijs/types": "3.4.0",
diff --git a/packages/utils/package.json b/packages/utils/package.json
index f14be3f5b522..abb26a060223 100644
--- a/packages/utils/package.json
+++ b/packages/utils/package.json
@@ -24,6 +24,6 @@
"access": "public"
},
"dependencies": {
- "@umijs/deps": "0.2.34"
+ "@umijs/deps": "0.3.3"
}
}
diff --git a/yarn.lock b/yarn.lock
index f25c8ee112c2..ec271110dc39 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2945,10 +2945,10 @@
dependencies:
"@types/yargs-parser" "*"
-"@umijs/deps@0.2.34":
- version "0.2.34"
- resolved "https://registry.yarnpkg.com/@umijs/deps/-/deps-0.2.34.tgz#3d748c5818da53f013d16dbb686c1b00e4409a4b"
- integrity sha512-6PUTf2IeMh1V1k0aoFOT4Z7gs3vYPOxkDuKsjglT+UrQxa8Wfm613U7LecnkC6nv3wZk23oolGmE6fjMgtYfSw==
+"@umijs/deps@0.3.3":
+ version "0.3.3"
+ resolved "https://registry.yarnpkg.com/@umijs/deps/-/deps-0.3.3.tgz#b712f7b66c5d2339e7833fc2547b7b50b8390ade"
+ integrity sha512-MO13OHd77nXObz1B5xaYOc/ZxdVyaaV6ZRIVVxsWKsB941zEJC9lImvga7ZMd7d3Fy6+M7HRi9LsCo8PHUhp5Q==
dependencies:
chokidar "3.5.1"
clipboardy "2.3.0"