Skip to content

Commit

Permalink
feat: upgrade rspack to 0.5 canary (#1171)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk authored Jan 8, 2024
1 parent 7f1c16e commit 5237f65
Show file tree
Hide file tree
Showing 16 changed files with 178 additions and 198 deletions.
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
},
"dependencies": {
"@rsbuild/shared": "workspace:*",
"@rspack/core": "0.4.5",
"@rspack/core": "0.4.5-canary-be59383-20240105051840",
"@swc/helpers": "0.5.3",
"core-js": "~3.32.2",
"html-webpack-plugin": "npm:[email protected]",
"postcss": "8.4.31"
Expand Down
10 changes: 7 additions & 3 deletions packages/core/src/provider/plugins/hmr.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import type { RsbuildPlugin } from '../../types';

import { setConfig, isUsingHMR } from '@rsbuild/shared';
import { isUsingHMR } from '@rsbuild/shared';

export const pluginHMR = (): RsbuildPlugin => ({
name: 'rsbuild:hmr',

setup(api) {
api.modifyRspackConfig((rspackConfig, utils) => {
api.modifyBundlerChain((chain, utils) => {
const config = api.getNormalizedConfig();

const usingHMR = isUsingHMR(config, utils);

setConfig(rspackConfig, 'devServer.hot', usingHMR);
if (usingHMR) {
chain
.plugin(utils.CHAIN_ID.PLUGIN.HMR)
.use(utils.bundler.HotModuleReplacementPlugin);
}
});
},
});
7 changes: 7 additions & 0 deletions packages/core/src/provider/plugins/swc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ export const pluginSwc = (): RsbuildPlugin => ({

applyDecorator(swcConfig, config.output.enableLatestDecorators);

if (swcConfig.jsc?.externalHelpers) {
chain.resolve.alias.set(
'@swc/helpers',
path.dirname(require.resolve('@swc/helpers/package.json')),
);
}

// apply polyfill
if (isWebTarget(target)) {
const polyfillMode = config.output.polyfill;
Expand Down
7 changes: 4 additions & 3 deletions packages/core/tests/__snapshots__/builder.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ exports[`should use rspack as default bundler > apply rspack correctly 1`] = `
},
},
"context": "<ROOT>",
"devServer": {
"hot": true,
},
"devtool": "cheap-module-source-map",
"entry": {
"index": [
Expand Down Expand Up @@ -649,9 +646,13 @@ exports[`should use rspack as default bundler > apply rspack correctly 1`] = `
RemoveCssSourcemapPlugin {
"name": "RemoveCssSourcemapPlugin",
},
HotModuleReplacementPlugin {
"name": "HotModuleReplacementPlugin",
},
],
"resolve": {
"alias": {
"@swc/helpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
"core-js": "<ROOT>/node_modules/<PNPM_INNER>/core-js",
},
"extensions": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
},
},
"context": "<ROOT>",
"devServer": {
"hot": true,
},
"devtool": "cheap-module-source-map",
"entry": {
"index": [
Expand Down Expand Up @@ -649,9 +646,13 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
RemoveCssSourcemapPlugin {
"name": "RemoveCssSourcemapPlugin",
},
HotModuleReplacementPlugin {
"name": "HotModuleReplacementPlugin",
},
],
"resolve": {
"alias": {
"@swc/helpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
"core-js": "<ROOT>/node_modules/<PNPM_INNER>/core-js",
},
"extensions": [
Expand Down Expand Up @@ -682,9 +683,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod
},
},
"context": "<ROOT>",
"devServer": {
"hot": false,
},
"devtool": false,
"entry": {
"index": [
Expand Down Expand Up @@ -1243,7 +1241,9 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod
"_options": {
"compress": "{"passes":1,"pure_funcs":[],"drop_console":false}",
"exclude": undefined,
"extractComments": "true",
"extractComments": {
"condition": "@preserve|@lic|@cc_on|^/**!",
},
"format": "{"comments":false,"asciiOnly":true}",
"include": undefined,
"mangle": "{"keep_classnames":false,"keep_fnames":false}",
Expand Down Expand Up @@ -1370,6 +1370,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod
],
"resolve": {
"alias": {
"@swc/helpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
"core-js": "<ROOT>/node_modules/<PNPM_INNER>/core-js",
},
"extensions": [
Expand Down Expand Up @@ -1400,9 +1401,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe
},
},
"context": "<ROOT>",
"devServer": {
"hot": false,
},
"devtool": "cheap-module-source-map",
"entry": {
"index": [
Expand Down Expand Up @@ -1786,6 +1784,9 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe
},
],
"resolve": {
"alias": {
"@swc/helpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
},
"conditionNames": [
"require",
"node",
Expand Down Expand Up @@ -1815,9 +1816,6 @@ exports[`tools.rspack > should match snapshot 1`] = `
},
},
"context": "<ROOT>",
"devServer": {
"hot": true,
},
"devtool": "cheap-module-source-map",
"entry": {
"index": [
Expand Down Expand Up @@ -2463,9 +2461,13 @@ exports[`tools.rspack > should match snapshot 1`] = `
RemoveCssSourcemapPlugin {
"name": "RemoveCssSourcemapPlugin",
},
HotModuleReplacementPlugin {
"name": "HotModuleReplacementPlugin",
},
],
"resolve": {
"alias": {
"@swc/helpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
"core-js": "<ROOT>/node_modules/<PNPM_INNER>/core-js",
},
"extensions": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ exports[`plugin-swc > should add antd pluginImport 1`] = `
},
"resolve": {
"alias": {
"@swc/helpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
"core-js": "<ROOT>/node_modules/<PNPM_INNER>/core-js",
},
},
Expand Down Expand Up @@ -205,6 +206,7 @@ exports[`plugin-swc > should add browserslist 1`] = `
},
"resolve": {
"alias": {
"@swc/helpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
"core-js": "<ROOT>/node_modules/<PNPM_INNER>/core-js",
},
},
Expand Down Expand Up @@ -309,6 +311,7 @@ exports[`plugin-swc > should add browserslist 2`] = `
},
"resolve": {
"alias": {
"@swc/helpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
"core-js": "<ROOT>/node_modules/<PNPM_INNER>/core-js",
},
},
Expand Down Expand Up @@ -433,6 +436,7 @@ exports[`plugin-swc > should add pluginImport 1`] = `
},
"resolve": {
"alias": {
"@swc/helpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
"core-js": "<ROOT>/node_modules/<PNPM_INNER>/core-js",
},
},
Expand Down Expand Up @@ -542,6 +546,7 @@ exports[`plugin-swc > should disable all pluginImport 1`] = `
},
"resolve": {
"alias": {
"@swc/helpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
"core-js": "<ROOT>/node_modules/<PNPM_INNER>/core-js",
},
},
Expand Down Expand Up @@ -637,6 +642,11 @@ exports[`plugin-swc > should disable preset_env in target other than web 1`] = `
},
],
},
"resolve": {
"alias": {
"@swc/helpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
},
},
},
]
`;
Expand Down Expand Up @@ -738,6 +748,11 @@ exports[`plugin-swc > should disable preset_env mode 1`] = `
},
],
},
"resolve": {
"alias": {
"@swc/helpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
},
},
},
]
`;
Expand Down Expand Up @@ -844,6 +859,7 @@ exports[`plugin-swc > should enable entry mode preset_env 1`] = `
},
"resolve": {
"alias": {
"@swc/helpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
"core-js": "<ROOT>/node_modules/<PNPM_INNER>/core-js",
},
},
Expand Down Expand Up @@ -954,6 +970,7 @@ exports[`plugin-swc > should enable usage mode preset_env 1`] = `
},
"resolve": {
"alias": {
"@swc/helpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
"core-js": "<ROOT>/node_modules/<PNPM_INNER>/core-js",
},
},
Expand Down Expand Up @@ -1063,6 +1080,7 @@ exports[`plugin-swc > should has correct core-js 1`] = `
},
"resolve": {
"alias": {
"@swc/helpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
"core-js": "<ROOT>/node_modules/<PNPM_INNER>/core-js",
},
},
Expand Down Expand Up @@ -1159,6 +1177,11 @@ exports[`plugin-swc > should has correct core-js 2`] = `
},
],
},
"resolve": {
"alias": {
"@swc/helpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
},
},
},
]
`;
Expand Down Expand Up @@ -1266,6 +1289,7 @@ exports[`plugin-swc > should'n override browserslist when target platform is not
},
"resolve": {
"alias": {
"@swc/helpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
"core-js": "<ROOT>/node_modules/<PNPM_INNER>/core-js",
},
},
Expand Down
16 changes: 12 additions & 4 deletions packages/core/tests/rspack-provider/plugins/minimize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ describe('plugin-minimize', () => {
"_options": {
"compress": "{"passes":1,"pure_funcs":[],"drop_console":false}",
"exclude": undefined,
"extractComments": "true",
"extractComments": {
"condition": "@preserve|@lic|@cc_on|^/**!",
},
"format": "{"comments":false,"asciiOnly":true}",
"include": undefined,
"mangle": "{"keep_classnames":false,"keep_fnames":false}",
Expand Down Expand Up @@ -97,7 +99,9 @@ describe('plugin-minimize', () => {
"_options": {
"compress": "{"passes":1,"pure_funcs":[],"drop_console":true}",
"exclude": undefined,
"extractComments": "true",
"extractComments": {
"condition": "@preserve|@lic|@cc_on|^/**!",
},
"format": "{"comments":false,"asciiOnly":true}",
"include": undefined,
"mangle": "{"keep_classnames":false,"keep_fnames":false}",
Expand Down Expand Up @@ -140,7 +144,9 @@ describe('plugin-minimize', () => {
"_options": {
"compress": "{"passes":1,"pure_funcs":["console.log","console.warn"],"drop_console":false}",
"exclude": undefined,
"extractComments": "true",
"extractComments": {
"condition": "@preserve|@lic|@cc_on|^/**!",
},
"format": "{"comments":false,"asciiOnly":true}",
"include": undefined,
"mangle": "{"keep_classnames":false,"keep_fnames":false}",
Expand Down Expand Up @@ -183,7 +189,9 @@ describe('plugin-minimize', () => {
"_options": {
"compress": "{"passes":1,"pure_funcs":[],"drop_console":false}",
"exclude": undefined,
"extractComments": "true",
"extractComments": {
"condition": "@preserve|@lic|@cc_on|^/**!",
},
"format": "{"comments":false,"asciiOnly":false}",
"include": undefined,
"mangle": "{"keep_classnames":false,"keep_fnames":false}",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"dependencies": {
"@rsbuild/shared": "workspace:*",
"@rspack/plugin-react-refresh": "0.4.5",
"@rspack/plugin-react-refresh": "0.4.5-canary-be59383-20240105051840",
"react-refresh": "^0.14.0"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 5237f65

Please sign in to comment.