From 8c666e19c5e5fdb930f02489c3de286bae54f8a7 Mon Sep 17 00:00:00 2001 From: liuzejia Date: Thu, 5 Sep 2024 16:11:34 +0800 Subject: [PATCH 1/5] =?UTF-8?q?refactor:=20webpack=20babel=20=E7=9A=84=20e?= =?UTF-8?q?xclude=20=E9=85=8D=E7=BD=AE=E9=80=BB=E8=BE=91=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../taro-webpack-runner/src/utils/chain.ts | 44 +++++++++---------- .../src/webpack/H5WebpackModule.ts | 5 ++- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/packages/taro-webpack-runner/src/utils/chain.ts b/packages/taro-webpack-runner/src/utils/chain.ts index 9a6aa56d0b40..c527f92fb459 100644 --- a/packages/taro-webpack-runner/src/utils/chain.ts +++ b/packages/taro-webpack-runner/src/utils/chain.ts @@ -428,30 +428,26 @@ export const parseModule = (appPath: string, { } } - if (compile.exclude && compile.exclude.length) { - scriptRule.exclude = [ - ...compile.exclude, - filename => /css-loader/.test(filename) || (/node_modules/.test(filename) && !(/taro/.test(filename))) - ] - } else if (compile.include && compile.include.length) { - scriptRule.include = [ - ...compile.include, - sourceDir, - filename => /taro/.test(filename) - ] - } else { - /** - * 要优先处理 css-loader 问题 - * - * https://github.com/webpack-contrib/mini-css-extract-plugin/issues/471#issuecomment-750266195 - * - * 若包含 @tarojs/components,则跳过 babel-loader 处理 - * 除了包含 taro 和 inversify 的第三方依赖均不经过 babel-loader 处理 - */ - scriptRule.exclude = [filename => - /css-loader/.test(filename) || - // || /@tarojs[\\/]components/.test(filename) Note: stencil 2.14 开始使用了 import.meta.url 需要额外处理 - (/node_modules/.test(filename) && !(/taro/.test(filename) || /inversify/.test(filename)))] + // Note: 和 webpack5 的 include 和 exclude 的逻辑保持一致: + // 什么都不配置时,默认只处理 sourceDir 和 taro 和 inversify 的第三方依赖 + + + scriptRule.include = [ + sourceDir, + filename => /(?<=node_modules[\\/]).*taro/.test(filename) || /inversify/.test(filename) + ] + /** + * Note: 要优先处理 css-loader 问题 所以这里不管如何配置include和exclude,都要进行排除,这是不同于 webpack5 的地方 + * + * https://github.com/webpack-contrib/mini-css-extract-plugin/issues/471#issuecomment-750266195 + * + */ + scriptRule.exclude = [filename => /css-loader/.test(filename)] + if (Array.isArray(compile.include)) { + scriptRule.include.unshift(...compile.include) + } + if(Array.isArray(compile.exclude)) { + scriptRule.exclude.unshift(...compile.exclude) } const rule: { diff --git a/packages/taro-webpack5-runner/src/webpack/H5WebpackModule.ts b/packages/taro-webpack5-runner/src/webpack/H5WebpackModule.ts index 80f9035a2202..a01d4c4b9ce9 100644 --- a/packages/taro-webpack5-runner/src/webpack/H5WebpackModule.ts +++ b/packages/taro-webpack5-runner/src/webpack/H5WebpackModule.ts @@ -268,9 +268,10 @@ export class H5WebpackModule { rule.include.unshift(...compile.include) } - rule.exclude = [filename => /@tarojs[\\/]components/.test(filename)] if (Array.isArray(compile.exclude)) { - rule.exclude.unshift(...compile.exclude) + rule.exclude = [...compile.exclude] + } else { + rule.exclude = [filename => /@tarojs[\\/]components/.test(filename)] } return rule From 1cb0c4dcdf4a0eaa52b5e308f02dbcb8bc9d939d Mon Sep 17 00:00:00 2001 From: liuzejia Date: Thu, 5 Sep 2024 16:18:55 +0800 Subject: [PATCH 2/5] fix: lint --- packages/taro-webpack-runner/src/utils/chain.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/taro-webpack-runner/src/utils/chain.ts b/packages/taro-webpack-runner/src/utils/chain.ts index c527f92fb459..1eb168ac46e9 100644 --- a/packages/taro-webpack-runner/src/utils/chain.ts +++ b/packages/taro-webpack-runner/src/utils/chain.ts @@ -446,7 +446,7 @@ export const parseModule = (appPath: string, { if (Array.isArray(compile.include)) { scriptRule.include.unshift(...compile.include) } - if(Array.isArray(compile.exclude)) { + if (Array.isArray(compile.exclude)) { scriptRule.exclude.unshift(...compile.exclude) } From 59f2db3f2ec37f712a4f36c36dbc6a6904efe629 Mon Sep 17 00:00:00 2001 From: liuzejia Date: Thu, 5 Sep 2024 17:22:38 +0800 Subject: [PATCH 3/5] =?UTF-8?q?docs:=20=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-webpack-runner/src/utils/chain.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/taro-webpack-runner/src/utils/chain.ts b/packages/taro-webpack-runner/src/utils/chain.ts index 1eb168ac46e9..01b911428659 100644 --- a/packages/taro-webpack-runner/src/utils/chain.ts +++ b/packages/taro-webpack-runner/src/utils/chain.ts @@ -428,10 +428,11 @@ export const parseModule = (appPath: string, { } } - // Note: 和 webpack5 的 include 和 exclude 的逻辑保持一致: - // 什么都不配置时,默认只处理 sourceDir 和 taro 和 inversify 的第三方依赖 - - + /** Note: 和 webpack5 的 include 和 exclude 的逻辑保持基本一致: + * 什么都不配置时,默认只处理 sourceDir 和 taro 和 inversify 的第三方依赖 + * 如果配置了 include,则把配置的 include 内容 unshift 到默认的 include + * 如果配置了 exclude,则把配置的 exclude 内容 unshift 到默认的 exclude (webpack5 会直用配置的 exclude 进行覆盖) + */ scriptRule.include = [ sourceDir, filename => /(?<=node_modules[\\/]).*taro/.test(filename) || /inversify/.test(filename) From 4fc39b1fbf6dc8595b1d2ccff18764b8b241a979 Mon Sep 17 00:00:00 2001 From: liuzejia Date: Thu, 5 Sep 2024 17:26:24 +0800 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20scripts=20=E6=AD=A3=E5=88=99?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=20mjs/mts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-helper/src/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/taro-helper/src/constants.ts b/packages/taro-helper/src/constants.ts index acdd7597e3d3..c54ce7daa2a5 100644 --- a/packages/taro-helper/src/constants.ts +++ b/packages/taro-helper/src/constants.ts @@ -89,7 +89,7 @@ export const VUE_EXT: string[] = ['.vue'] export const REG_JS = /\.js(\?.*)?$/ export const REG_SCRIPT = /\.(js|jsx)(\?.*)?$/ export const REG_TYPESCRIPT = /\.(tsx|ts)(\?.*)?$/ -export const REG_SCRIPTS = /\.[tj]sx?$/i +export const REG_SCRIPTS = /\.m?[tj]sx?$/i export const REG_VUE = /\.vue$/i export const REG_SASS = /\.(s[ac]ss)$/ export const REG_SASS_SASS = /\.sass$/ From 5719e606a2f6ed4f3620ad20b539f4d39a26825f Mon Sep 17 00:00:00 2001 From: liuzejia Date: Fri, 6 Sep 2024 11:39:53 +0800 Subject: [PATCH 5/5] =?UTF-8?q?feat:=20=E4=BF=9D=E7=95=99=E4=B9=8B?= =?UTF-8?q?=E5=89=8D=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-webpack-runner/src/utils/chain.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/taro-webpack-runner/src/utils/chain.ts b/packages/taro-webpack-runner/src/utils/chain.ts index 01b911428659..3a4578320005 100644 --- a/packages/taro-webpack-runner/src/utils/chain.ts +++ b/packages/taro-webpack-runner/src/utils/chain.ts @@ -435,7 +435,7 @@ export const parseModule = (appPath: string, { */ scriptRule.include = [ sourceDir, - filename => /(?<=node_modules[\\/]).*taro/.test(filename) || /inversify/.test(filename) + filename => /taro/.test(filename) || /inversify/.test(filename) ] /** * Note: 要优先处理 css-loader 问题 所以这里不管如何配置include和exclude,都要进行排除,这是不同于 webpack5 的地方