Skip to content

Commit

Permalink
chore: set fullySpecified when defining rule (#1488)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Feb 1, 2024
1 parent b6807c4 commit 2c955dc
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 8 deletions.
4 changes: 4 additions & 0 deletions packages/compat/plugin-swc/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export const pluginSwc = (options: PluginSwcOptions = {}): RsbuildPlugin => ({
.mimetype({
or: ['text/javascript', 'application/javascript'],
})
// compatible with legacy packages with type="module"
// https://github.com/webpack/webpack/issues/11467
.resolve.set('fullySpecified', false)
.end()
.use(CHAIN_ID.USE.SWC)
.loader(path.resolve(__dirname, './loader'))
.options(removeUselessOptions(mainConfig) satisfies TransformConfig);
Expand Down
24 changes: 24 additions & 0 deletions packages/compat/plugin-swc/tests/__snapshots__/plugin.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ exports[`plugin-swc > should apply source.include and source.exclude correctly 1
"application/javascript",
],
},
"resolve": {
"fullySpecified": false,
},
"use": [
{
"loader": "<ROOT>/packages/compat/plugin-swc/src/loader",
Expand Down Expand Up @@ -206,6 +209,9 @@ exports[`plugin-swc > should disable react refresh when dev.hmr is false 1`] = `
"application/javascript",
],
},
"resolve": {
"fullySpecified": false,
},
"use": [
{
"loader": "<ROOT>/packages/compat/plugin-swc/src/loader",
Expand Down Expand Up @@ -330,6 +336,9 @@ exports[`plugin-swc > should disable react refresh when target is not web 1`] =
"application/javascript",
],
},
"resolve": {
"fullySpecified": false,
},
"use": [
{
"loader": "<ROOT>/packages/compat/plugin-swc/src/loader",
Expand Down Expand Up @@ -454,6 +463,9 @@ exports[`plugin-swc > should disable react refresh when target is not web 2`] =
"application/javascript",
],
},
"resolve": {
"fullySpecified": false,
},
"use": [
{
"loader": "<ROOT>/packages/compat/plugin-swc/src/loader",
Expand Down Expand Up @@ -581,6 +593,9 @@ exports[`plugin-swc > should disable react refresh when target is not web 3`] =
"application/javascript",
],
},
"resolve": {
"fullySpecified": false,
},
"use": [
{
"loader": "<ROOT>/packages/compat/plugin-swc/src/loader",
Expand Down Expand Up @@ -708,6 +723,9 @@ exports[`plugin-swc > should disable react refresh when target is not web 4`] =
"application/javascript",
],
},
"resolve": {
"fullySpecified": false,
},
"use": [
{
"loader": "<ROOT>/packages/compat/plugin-swc/src/loader",
Expand Down Expand Up @@ -928,6 +946,9 @@ exports[`plugin-swc > should set multiple swc-loader 1`] = `
"application/javascript",
],
},
"resolve": {
"fullySpecified": false,
},
"use": [
{
"loader": "<ROOT>/packages/compat/plugin-swc/src/loader",
Expand Down Expand Up @@ -1075,6 +1096,9 @@ exports[`plugin-swc > should set swc-loader 1`] = `
"application/javascript",
],
},
"resolve": {
"fullySpecified": false,
},
"use": [
{
"loader": "<ROOT>/packages/compat/plugin-swc/src/loader",
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/provider/plugins/swc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ export const pluginSwc = (): RsbuildPlugin => ({
.mimetype({
or: ['text/javascript', 'application/javascript'],
})
// compatible with legacy packages with type="module"
// https://github.com/webpack/webpack/issues/11467
.resolve.set('fullySpecified', false)
.end()
.use(CHAIN_ID.USE.SWC)
.loader(builtinSwcLoaderName)
// Using cloned options to keep options separate from each other
Expand Down
36 changes: 36 additions & 0 deletions packages/core/tests/__snapshots__/swc.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ exports[`plugin-swc > should add antd pluginImport 1`] = `
"application/javascript",
],
},
"resolve": {
"fullySpecified": false,
},
"use": [
{
"loader": "builtin:swc-loader",
Expand Down Expand Up @@ -171,6 +174,9 @@ exports[`plugin-swc > should add browserslist 1`] = `
"application/javascript",
],
},
"resolve": {
"fullySpecified": false,
},
"use": [
{
"loader": "builtin:swc-loader",
Expand Down Expand Up @@ -276,6 +282,9 @@ exports[`plugin-swc > should add browserslist 2`] = `
"application/javascript",
],
},
"resolve": {
"fullySpecified": false,
},
"use": [
{
"loader": "builtin:swc-loader",
Expand Down Expand Up @@ -391,6 +400,9 @@ exports[`plugin-swc > should add pluginImport 1`] = `
"application/javascript",
],
},
"resolve": {
"fullySpecified": false,
},
"use": [
{
"loader": "builtin:swc-loader",
Expand Down Expand Up @@ -508,6 +520,9 @@ exports[`plugin-swc > should disable all pluginImport 1`] = `
"application/javascript",
],
},
"resolve": {
"fullySpecified": false,
},
"use": [
{
"loader": "builtin:swc-loader",
Expand Down Expand Up @@ -612,6 +627,9 @@ exports[`plugin-swc > should disable preset_env in target other than web 1`] = `
"application/javascript",
],
},
"resolve": {
"fullySpecified": false,
},
"use": [
{
"loader": "builtin:swc-loader",
Expand Down Expand Up @@ -714,6 +732,9 @@ exports[`plugin-swc > should disable preset_env mode 1`] = `
"application/javascript",
],
},
"resolve": {
"fullySpecified": false,
},
"use": [
{
"loader": "builtin:swc-loader",
Expand Down Expand Up @@ -822,6 +843,9 @@ exports[`plugin-swc > should enable entry mode preset_env 1`] = `
"application/javascript",
],
},
"resolve": {
"fullySpecified": false,
},
"use": [
{
"loader": "builtin:swc-loader",
Expand Down Expand Up @@ -932,6 +956,9 @@ exports[`plugin-swc > should enable usage mode preset_env 1`] = `
"application/javascript",
],
},
"resolve": {
"fullySpecified": false,
},
"use": [
{
"loader": "builtin:swc-loader",
Expand Down Expand Up @@ -1043,6 +1070,9 @@ exports[`plugin-swc > should has correct core-js 1`] = `
"application/javascript",
],
},
"resolve": {
"fullySpecified": false,
},
"use": [
{
"loader": "builtin:swc-loader",
Expand Down Expand Up @@ -1147,6 +1177,9 @@ exports[`plugin-swc > should has correct core-js 2`] = `
"application/javascript",
],
},
"resolve": {
"fullySpecified": false,
},
"use": [
{
"loader": "builtin:swc-loader",
Expand Down Expand Up @@ -1251,6 +1284,9 @@ exports[`plugin-swc > should'n override browserslist when target platform is not
"application/javascript",
],
},
"resolve": {
"fullySpecified": false,
},
"use": [
{
"loader": "builtin:swc-loader",
Expand Down
8 changes: 0 additions & 8 deletions packages/shared/src/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,6 @@ export function applyResolvePlugin(api: RsbuildPluginAPI) {
applyFullySpecified({ chain, config, CHAIN_ID });
},
});

api.modifyBundlerChain((chain, { CHAIN_ID }) => {
if (chain.module.rules.get(CHAIN_ID.RULE.JS_DATA_URI)) {
chain.module
.rule(CHAIN_ID.RULE.JS_DATA_URI)
.resolve.set('fullySpecified', false);
}
});
}

// compatible with legacy packages with type="module"
Expand Down

0 comments on commit 2c955dc

Please sign in to comment.