Skip to content

Commit

Permalink
chore: add swc helpers alias in monorepo (#23)
Browse files Browse the repository at this point in the history
* chore: add @swc/helpers alias in monorepo

* chore: fix remove unncessary flags
  • Loading branch information
hardfist authored Feb 7, 2024
1 parent 8999938 commit a8be8b1
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 64 deletions.
12 changes: 12 additions & 0 deletions libs/lib3/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "lib3",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
3 changes: 3 additions & 0 deletions libs/lib3/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export async function answer() {
return 42;
}
5 changes: 3 additions & 2 deletions rspack/builtin-swc-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
"@rspack/core": "latest",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-refresh": "0.14.0"
"react-refresh": "0.14.0",
"lib3": "workspace:*"
},
"devDependencies": {
"@rspack/core": "latest",
"@swc/helpers": "0.5.1"
}
}
}
107 changes: 57 additions & 50 deletions rspack/builtin-swc-loader/rspack.config.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,62 @@
const rspack = require("@rspack/core");
const path = require("path");
/** @type {import('@rspack/cli').Configuration} */
const config = {
entry: {
main: "./src/index.jsx"
},
resolve: {
extensions: ["...", ".jsx"]
},
module: {
rules: [
{
test: /\.jsx$/,
use: {
loader: "builtin:swc-loader",
options: {
// Enable source map
sourceMap: true,
jsc: {
parser: {
syntax: "ecmascript",
jsx: true
},
externalHelpers: true,
preserveAllComments: false,
transform: {
react: {
runtime: "automatic",
pragma: "React.createElement",
pragmaFrag: "React.Fragment",
throwIfNamespace: true,
useBuiltins: false
}
}
}
}
},
type: "javascript/auto"
},
{
test: /\.(png|svg|jpg)$/,
type: "asset/resource"
}
]
},
optimization: {
minimize: false // Disabling minification because it takes too long on CI
},
plugins: [
new rspack.HtmlRspackPlugin({
template: "./index.html"
})
]
entry: {
main: "./src/index.jsx",
},
resolve: {
extensions: ["...", ".jsx"],
alias: {
"@swc/helpers": path.dirname(
require.resolve("@swc/helpers/package.json")
),
},
},
module: {
rules: [
{
test: /\.(jsx|js)$/,
use: {
loader: "builtin:swc-loader",
options: {
// Enable source map
sourceMap: true,
target: "es5",
jsc: {
parser: {
syntax: "ecmascript",
jsx: true,
},
externalHelpers: true,
preserveAllComments: false,
transform: {
react: {
runtime: "automatic",
pragma: "React.createElement",
pragmaFrag: "React.Fragment",
throwIfNamespace: true,
useBuiltins: false,
},
},
},
},
},
type: "javascript/auto",
},
{
test: /\.(png|svg|jpg)$/,
type: "asset/resource",
},
],
},
optimization: {
minimize: false, // Disabling minification because it takes too long on CI
},
plugins: [
new rspack.HtmlRspackPlugin({
template: "./index.html",
}),
],
};
module.exports = config;
2 changes: 2 additions & 0 deletions rspack/builtin-swc-loader/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from "react";
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import {answer} from 'lib3';
console.log('answer:',answer());

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
Expand Down
19 changes: 7 additions & 12 deletions rspack/nest-alias/rspack.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
const {defineConfig } = require('@rspack/cli');
const path = require('path');
const { defineConfig } = require("@rspack/cli");
const path = require("path");
module.exports = defineConfig({
entry: {
main: './src/index.ts',
},
experiments: {
rspackFuture: {
newResolver:true
}
main: "./src/index.ts",
},
resolve: {
tsConfig: {
references: 'auto',
configFile:path.resolve(__dirname,'./tsconfig.json')
}
}
references: "auto",
configFile: path.resolve(__dirname, "./tsconfig.json"),
},
},
});

0 comments on commit a8be8b1

Please sign in to comment.