Skip to content

Commit

Permalink
feat: add builtin:swc-loader test case
Browse files Browse the repository at this point in the history
  • Loading branch information
h-a-n-a committed Oct 24, 2023
1 parent 07caeb7 commit 79ee706
Show file tree
Hide file tree
Showing 4 changed files with 329 additions and 2 deletions.
4 changes: 3 additions & 1 deletion bin/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ const rootDir = resolve(fileURLToPath(import.meta.url), "../..");
"10000_development-mode",
"10000_development-mode_hmr",
"10000_production-mode",
"10000_production-mode_builtin-swc-loader",
"threejs_development-mode_10x",
"threejs_development-mode_10x_hmr",
"threejs_production-mode_10x"
"threejs_production-mode_10x",
"threejs_production-mode_builtin-swc-loader"
];
for (const item of benchmarks) {
const result = await run(item);
Expand Down
59 changes: 59 additions & 0 deletions lib/addons/builtin-swc-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Addon } from "./common.js";

export default class extends Addon {
async afterSetup(ctx) {
ctx.config =
ctx.config +
`
const ReactRefreshPlugin = require("@rspack/plugin-react-refresh");
const prod = process.env.NODE_ENV === "production";
module.exports.experiments ||= {};
module.exports.experiments.rspackFuture ||= {};
module.exports.experiments.rspackFuture.disableTransformByDefault = true;
(module.exports.plugins ||= []).push(new ReactRefreshPlugin());
module.exports.module ||= {};
(module.exports.module.rules ||= []).push({
test: /\.(j|t)s$/,
exclude: [/[\\/]node_modules[\\/]/],
loader: "builtin:swc-loader",
options: {
sourceMap: true,
jsc: {
parser: {
syntax: "typescript"
},
externalHelpers: true
},
env: {
targets: "Chrome >= 48"
}
}
},
{
test: /\.(j|t)sx$/,
loader: "builtin:swc-loader",
exclude: [/[\\/]node_modules[\\/]/],
options: {
sourceMap: true,
jsc: {
parser: {
syntax: "typescript",
tsx: true
},
transform: {
react: {
runtime: "automatic",
development: !prod,
refresh: !prod
}
},
externalHelpers: true
},
env: {
targets: "Chrome >= 48"
}
}
});
`;
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"type": "module",
"dependencies": {
"@icon-park/react": "^1.4.2",
"@rspack/plugin-react-refresh": "^0.3.8",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"react-refresh": "^0.14.0"
}
}
264 changes: 264 additions & 0 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 79ee706

Please sign in to comment.