From 35ebf877448e975aaab0e49ef316c7557b00a7c0 Mon Sep 17 00:00:00 2001 From: iapyang Date: Mon, 22 Aug 2022 14:34:38 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=8E=BB=E9=99=A4worker=E4=B8=ADcss?= =?UTF-8?q?=20less=E7=9A=84=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/webpack-fui-worker-plugin/empty.js | 0 .../webpack-fui-worker-plugin/worker-loader.js | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 plugins/webpack-fui-worker-plugin/empty.js diff --git a/plugins/webpack-fui-worker-plugin/empty.js b/plugins/webpack-fui-worker-plugin/empty.js new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/webpack-fui-worker-plugin/worker-loader.js b/plugins/webpack-fui-worker-plugin/worker-loader.js index ea5d86459..3dcb8de6c 100644 --- a/plugins/webpack-fui-worker-plugin/worker-loader.js +++ b/plugins/webpack-fui-worker-plugin/worker-loader.js @@ -68,9 +68,20 @@ function loader() { }).apply(childCompiler); // 去除源码中的less css引用 - new webpack.IgnorePlugin({ - resourceRegExp: /\.(css|less)$/, - }).apply(childCompiler); + const regExp = /\.(css|less)$/; + + new webpack.NormalModuleReplacementPlugin( + regExp, + result => { + if (regExp.test(result.request)) { + result.request = resolve(__dirname, './empty.js'); + } + + if (regExp.test(result.resource)) { + result.resource = resolve(__dirname, './empty.js'); + } + }, + ).apply(childCompiler); const subCache = `subcache ${__dirname} ${workerEntry}`; childCompiler.hooks.compilation.tap(WorkerLoaderName, compilation => {