Skip to content

Commit

Permalink
Fix: align the order and content of custom transformer with webpack (#…
Browse files Browse the repository at this point in the history
…6823)

* fix: align the order and content of custom transformer with webpack

* chore: changelog
  • Loading branch information
ClarkXia authored Mar 7, 2024
1 parent 79c32a7 commit c404b15
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/gentle-trainers-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@ice/shared-config': patch
'@ice/bundles': patch
---

fix: align the transform order and content with webpack mode
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
"packageManager": "[email protected]",
"pnpm": {
"patchedDependencies": {
"@rspack/[email protected]": "patches/@[email protected]"
"@rspack/[email protected]": "patches/@[email protected]",
"[email protected]": "patches/[email protected]"
}
}
}
4 changes: 3 additions & 1 deletion packages/shared-config/src/getCompilerPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ function getCompilerPlugins(rootDir: string, config: Config, compiler: Compiler,
}));
}
if (clientBundlers.includes(compiler)) {
return compilerPlugins
const transformPlugins = compilerPlugins
.map((plugin) => createUnplugin(() => getPluginTransform(plugin, transformOptions))[compiler]()) as Config['plugins'];
// Reverse the transformPlugins for rspack, because the unplugin order has been change in rspack mode.
return compiler === 'rspack' ? transformPlugins.reverse() : transformPlugins;
} else {
return compilerPlugins.map(plugin => getPluginTransform(plugin, transformOptions));
}
Expand Down
44 changes: 44 additions & 0 deletions patches/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
diff --git a/dist/index.js b/dist/index.js
index 631e1459fbcb948d5089ae5432350c91d9853b5c..00cd831ddaf72e181f6260a99ce40e3ee5220f59 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -1535,7 +1535,7 @@ function getRspackPlugin(factory) {
});
const externalModules = /* @__PURE__ */ new Set();
if (plugin.load) {
- compiler.options.module.rules.unshift({
+ compiler.options.module.rules.push({
enforce: plugin.enforce,
include(id) {
return shouldLoad(id, plugin, externalModules);
@@ -1549,7 +1549,7 @@ function getRspackPlugin(factory) {
});
}
if (plugin.transform) {
- compiler.options.module.rules.unshift({
+ compiler.options.module.rules.push({
enforce: plugin.enforce,
use(data) {
return transformUse(data, plugin, TRANSFORM_LOADER);
diff --git a/dist/index.mjs b/dist/index.mjs
index bca4a4f9ccf06032f8e8af17ec12307c9176b440..5be1848ae866cb181c486b59ecdbf26921b5e5c8 100644
--- a/dist/index.mjs
+++ b/dist/index.mjs
@@ -1501,7 +1501,7 @@ function getRspackPlugin(factory) {
});
const externalModules = /* @__PURE__ */ new Set();
if (plugin.load) {
- compiler.options.module.rules.unshift({
+ compiler.options.module.rules.push({
enforce: plugin.enforce,
include(id) {
return shouldLoad(id, plugin, externalModules);
@@ -1515,7 +1515,7 @@ function getRspackPlugin(factory) {
});
}
if (plugin.transform) {
- compiler.options.module.rules.unshift({
+ compiler.options.module.rules.push({
enforce: plugin.enforce,
use(data) {
return transformUse(data, plugin, TRANSFORM_LOADER);
10 changes: 7 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c404b15

Please sign in to comment.