From 7afe4f958393363fda2f43bd0c8ff34b7ae2003f Mon Sep 17 00:00:00 2001 From: QCQCQC <1220204124@zust.edu.cn> Date: Sun, 8 Dec 2024 13:21:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81module.rules?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/mp/webpack.config.js | 5 +++++ lib/createConfig.d.ts | 6 ++++++ src/createConfig.ts | 8 +++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/config/mp/webpack.config.js b/config/mp/webpack.config.js index d76ab6a..342ba93 100644 --- a/config/mp/webpack.config.js +++ b/config/mp/webpack.config.js @@ -293,6 +293,11 @@ module.exports = function (webpackEnv) { type: 'javascript/auto', use: [oakFileLoader('wxml')], }, + ...(projectConfiguration && + projectConfiguration.module && + projectConfiguration.module.rules + ? projectConfiguration.module.rules : [] + ), ], }, plugins: [ diff --git a/lib/createConfig.d.ts b/lib/createConfig.d.ts index 44c3e89..d058f31 100644 --- a/lib/createConfig.d.ts +++ b/lib/createConfig.d.ts @@ -9,6 +9,9 @@ type ExternalsType = Required['externals']; type ExternalsObjectType = Exclude>; type PluginType = Required['plugins']; type PluginInstanceType = PluginType extends Array ? Exclude : never; +type ModuleType = Required['module']; +type RuleType = Required['rules']; +type RuleObjectType = RuleType extends Array ? Exclude : never; /** * 编译环境配置 */ @@ -23,6 +26,9 @@ export type CompilerConfiguration = { cacheGroups: CacheGroups; }; externals?: ExternalsObjectType; + module: { + rules: RuleObjectType[]; + }; plugins?: PluginInstanceType[]; }; }; diff --git a/src/createConfig.ts b/src/createConfig.ts index f6737c8..de8fe05 100644 --- a/src/createConfig.ts +++ b/src/createConfig.ts @@ -10,7 +10,10 @@ type CacheGroups = Exclude["cacheGroups"]; type ExternalsType = Required['externals']; type ExternalsObjectType = Exclude>; type PluginType = Required['plugins']; -type PluginInstanceType = PluginType extends Array ? Exclude : never +type PluginInstanceType = PluginType extends Array ? Exclude : never +type ModuleType = Required < WebpackConfiguration > ['module']; +type RuleType = Required['rules']; +type RuleObjectType = RuleType extends Array ? Exclude : never /** * 编译环境配置 @@ -26,6 +29,9 @@ export type CompilerConfiguration = { cacheGroups: CacheGroups; }, externals?: ExternalsObjectType; + module: { + rules: RuleObjectType[]; + } plugins?: PluginInstanceType[]; }, };