Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pnpm-lock.yaml

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

4 changes: 4 additions & 0 deletions rspack/library-esm/rspack.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export default defineConfig({
library: {
type: "modern-module",
},
chunkLoading: 'import',
workerChunkLoading: 'import',
},
module: {
parser: {
Expand All @@ -21,6 +23,8 @@ export default defineConfig({
},
},
optimization: {
concatenateModules: true,
avoidEntryIife: true,
minimize: false, // no need to minify for library
},
experiments: {
Expand Down
15 changes: 15 additions & 0 deletions rspack/react-refresh-esm/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>

<body>
<div id="root"></div>
</body>

</html>
21 changes: 21 additions & 0 deletions rspack/react-refresh-esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "example-rspack-react-refresh-esm",
"version": "1.0.0",
"private": true,
"license": "MIT",
"main": "index.js",
"scripts": {
"build": "cross-env NODE_ENV=production rspack build",
"dev": "rspack serve "
},
"dependencies": {
"react": "^19.1.0",
"react-dom": "^19.1.0"
},
"devDependencies": {
"@rspack/cli": "1.4.10",
"@rspack/core": "1.4.10",
"@rspack/plugin-react-refresh": "^1.4.3",
"react-refresh": "0.17.0"
}
}
55 changes: 55 additions & 0 deletions rspack/react-refresh-esm/rspack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const { rspack } = require('@rspack/core');
const ReactRefreshPlugin = require('@rspack/plugin-react-refresh');

const isProduction = process.env.NODE_ENV === 'production';

/** @type {import('@rspack/cli').Configuration} */
const config = {
entry: { main: './src/index.tsx' },
devtool: 'source-map',
output: {
module: true,
chunkFormat: 'array-push',
chunkLoading: 'jsonp',
workerChunkLoading: 'import',
},
resolve: {
extensions: ['...', '.ts', '.tsx', '.jsx'],
},
experiments: {
css: true,
outputModule: true,
},
module: {
rules: [
{
test: /\.tsx$/,
use: {
loader: 'builtin:swc-loader',
options: {
sourceMap: true,
jsc: {
parser: {
syntax: 'typescript',
tsx: true,
},
transform: {
react: {
runtime: 'automatic',
development: !isProduction,
refresh: !isProduction,
},
},
},
},
},
},
],
},
plugins: [
new rspack.HtmlRspackPlugin({ template: './index.html', scriptLoading: "module" }),
!isProduction && new ReactRefreshPlugin(),
].filter(Boolean),
};

module.exports = config;
25 changes: 25 additions & 0 deletions rspack/react-refresh-esm/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { lazy, Suspense } from 'react';
import { ArrowFunction } from './ArrowFunction';
import ClassDefault from './ClassDefault';
import { ClassNamed } from './ClassNamed';
import FunctionDefault from './FunctionDefault';
import { FunctionNamed } from './FunctionNamed';

const LazyComponent = lazy(() => import('./LazyComponent'));

function App() {
return (
<div>
<ClassDefault />
<ClassNamed />
<FunctionDefault />
<FunctionNamed />
<ArrowFunction />
<Suspense fallback={<h1>Loading</h1>}>
<LazyComponent />
</Suspense>
</div>
);
}

export default App;
1 change: 1 addition & 0 deletions rspack/react-refresh-esm/src/ArrowFunction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const ArrowFunction = () => <h1>Arrow Function</h1>;
9 changes: 9 additions & 0 deletions rspack/react-refresh-esm/src/ClassDefault.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Component } from 'react';

class ClassDefault extends Component {
render() {
return <h1>Default Export Class</h1>;
}
}

export default ClassDefault;
7 changes: 7 additions & 0 deletions rspack/react-refresh-esm/src/ClassNamed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Component } from 'react';

export class ClassNamed extends Component {
render() {
return <h1>Named Export Class</h1>;
}
}
5 changes: 5 additions & 0 deletions rspack/react-refresh-esm/src/FunctionDefault.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function FunctionDefault() {
return <h1>Default Export Function</h1>;
}

export default FunctionDefault;
13 changes: 13 additions & 0 deletions rspack/react-refresh-esm/src/FunctionNamed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useEffect, useState } from 'react';

export function FunctionNamed() {
const [data, setData] = useState(0);

useEffect(() => {
setInterval(() => {
setData((i) => i + 1);
}, 100);
}, []);

return <h1>Named Export Function {data}</h1>;
}
5 changes: 5 additions & 0 deletions rspack/react-refresh-esm/src/LazyComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function LazyComponent() {
return <h1>Lazy Component</h1>;
}

export default LazyComponent;
6 changes: 6 additions & 0 deletions rspack/react-refresh-esm/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createRoot } from 'react-dom/client';
import App from './App';

const container = document.getElementById('root');
const root = createRoot(container!);
root.render(<App />);