From f7a7eb6d1037628c68086f2c1e309f5483c49d7d Mon Sep 17 00:00:00 2001 From: zhipenglin Date: Fri, 11 Apr 2025 15:45:58 +0800 Subject: [PATCH] =?UTF-8?q?fix=E6=8E=89=E4=B8=80=E4=BA=9B=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E6=97=B6=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/craco-fix-plugin.js | 30 +++++++++++++++++++++++++++ lib/craco-libs-example-plugin.js | 16 ++------------ lib/craco-remote-components-plugin.js | 14 ++----------- package.json | 3 ++- 4 files changed, 36 insertions(+), 27 deletions(-) create mode 100644 lib/craco-fix-plugin.js diff --git a/lib/craco-fix-plugin.js b/lib/craco-fix-plugin.js new file mode 100644 index 0000000..bb0ed8e --- /dev/null +++ b/lib/craco-fix-plugin.js @@ -0,0 +1,30 @@ +const {when} = require("@craco/craco"); +const env = require("./env"); +module.exports = { + overrideWebpackConfig({webpackConfig, context}) { + if (context.env === 'production') { + when(env === 'production', () => { + // 查找 MiniCssExtractPlugin 实例 + const miniCssExtractPlugin = webpackConfig.plugins.find(plugin => plugin.constructor && plugin.constructor.name === 'MiniCssExtractPlugin'); + + if (miniCssExtractPlugin) { + // 修改配置 + miniCssExtractPlugin.options.ignoreOrder = true; + } + }); + } + webpackConfig.resolve.fallback = { + "path": false, + "util": false, + "url": false, + "http": false, + "https": false, + "stream": false, + "assert": false, + "querystring": false, + "zlib": false, + "fs": false + }; + return webpackConfig; + } +}; \ No newline at end of file diff --git a/lib/craco-libs-example-plugin.js b/lib/craco-libs-example-plugin.js index 968f2cf..22b0739 100644 --- a/lib/craco-libs-example-plugin.js +++ b/lib/craco-libs-example-plugin.js @@ -33,6 +33,8 @@ module.exports = { additionalPaths: [path.resolve(__dirname, './modulefederation.config.js')], middleware: pluginOptions?.middleware } + }, { + plugin: require('./craco-fix-plugin'), options: {} }); return cracoConfig; }, overrideWebpackConfig({webpackConfig, context}) { @@ -43,20 +45,6 @@ module.exports = { const LibExampleVersionPlugin = require('./lib-example-version-webpack-plugin'); webpackConfig.plugins.push(new LibExampleVersionPlugin()); } - - webpackConfig.resolve.fallback = { - "path": false, - "util": false, - "url": false, - "http": false, - "https": false, - "stream": false, - "assert": false, - "querystring": false, - "zlib": false, - "fs": false - }; - return webpackConfig; } }; diff --git a/lib/craco-remote-components-plugin.js b/lib/craco-remote-components-plugin.js index 514aa12..b94144e 100644 --- a/lib/craco-remote-components-plugin.js +++ b/lib/craco-remote-components-plugin.js @@ -18,6 +18,8 @@ module.exports = { additionalPaths: [path.resolve(__dirname, './modulefederation.config.js')], middleware: pluginOptions?.middleware } + }, { + plugin: require('./craco-fix-plugin'), options: {} }); return cracoConfig; }, overrideWebpackConfig({webpackConfig, context}) { @@ -26,18 +28,6 @@ module.exports = { }) const definePlugin = webpackConfig.plugins.find((plugin) => plugin.constructor.name === "DefinePlugin"); Object.assign(definePlugin.definitions["process.env"], {STATIC_BASE_URL: `"${env.staticBaseUrl}"`}); - webpackConfig.resolve.fallback = { - "path": false, - "util": false, - "url": false, - "http": false, - "https": false, - "stream": false, - "assert": false, - "querystring": false, - "zlib": false, - "fs": false - }; return webpackConfig; } }; diff --git a/package.json b/package.json index 24d330e..44d21e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kne/modules-dev", - "version": "2.1.5", + "version": "2.1.6", "description": "用于辅助在项目内启动一个规范化组件开发的环境", "publishConfig": { "source": "src/index.js", @@ -31,6 +31,7 @@ "author": "linzp", "license": "ISC", "dependencies": { + "@babel/plugin-proposal-private-property-in-object": "^7.21.11", "@kne/apply-template": "^0.1.1", "@kne/camel-case": "^0.1.1", "@kne/craco-module-federation": "^1.1.5",