-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
269e349
commit 2e44695
Showing
10 changed files
with
227 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "example-preact-refresh", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"private": true, | ||
"scripts": { | ||
"dev": "rspack serve", | ||
"build": "rspack build" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@swc/helpers": "0.5.1", | ||
"preact": "10.19.3" | ||
}, | ||
"devDependencies": { | ||
"@rspack/cli": "^0.7.3", | ||
"@rspack/core": "^0.7.3", | ||
"@rspack/plugin-preact-refresh": "^0.7.3", | ||
"@prefresh/babel-plugin": "0.5.1", | ||
"@prefresh/webpack": "4.0.0" | ||
}, | ||
"resolve": { | ||
"alias": { | ||
"react": "preact/compat", | ||
"react-dom/test-utils": "preact/test-utils", | ||
"react-dom": "preact/compat", | ||
"react/jsx-runtime": "preact/jsx-runtime" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const rspack = require('@rspack/core'); | ||
const dev = process.env.NODE_ENV === 'development'; | ||
const PreactRefreshPlugin = require('@rspack/plugin-preact-refresh'); | ||
/** @type {import('@rspack/cli').Configuration} */ | ||
const config = { | ||
entry: { | ||
main: './src/index.jsx', | ||
}, | ||
resolve: { | ||
extensions: ['...', '.ts', '.tsx', '.jsx'], | ||
alias: { | ||
react: 'preact/compat', | ||
'react-dom/test-utils': 'preact/test-utils', | ||
'react-dom': 'preact/compat', | ||
'react/jsx-runtime': 'preact/jsx-runtime', | ||
}, | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.jsx$/, | ||
use: { | ||
loader: 'builtin:swc-loader', | ||
options: { | ||
sourceMap: true, | ||
rspackExperiments: { | ||
preact: {}, // enable preact swc plugin | ||
}, | ||
jsc: { | ||
parser: { | ||
syntax: 'ecmascript', | ||
jsx: true, | ||
}, | ||
externalHelpers: true, | ||
preserveAllComments: false, | ||
transform: { | ||
react: { | ||
runtime: 'automatic', | ||
pragma: 'h', | ||
pragmaFrag: 'Fragment', | ||
throwIfNamespace: true, | ||
useBuiltins: false, | ||
refresh: true, // enable react hooks hmr compatiblity | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
type: 'javascript/auto', | ||
}, | ||
{ | ||
test: /\.(png|svg|jpg)$/, | ||
type: 'asset/resource', | ||
}, | ||
], | ||
}, | ||
plugins: [ | ||
new rspack.HtmlRspackPlugin({ | ||
template: './index.html', | ||
scriptLoading: 'blocking', | ||
}), | ||
dev && new rspack.HotModuleReplacementPlugin(), | ||
dev && new PreactRefreshPlugin(), | ||
].filter(Boolean), | ||
}; | ||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
.App { | ||
text-align: center; | ||
} | ||
|
||
.App-logo { | ||
height: 40vmin; | ||
pointer-events: none; | ||
} | ||
|
||
@media (prefers-reduced-motion: no-preference) { | ||
.App-logo { | ||
animation: App-logo-spin infinite 20s linear; | ||
} | ||
} | ||
|
||
.App-header { | ||
background-color: #282c34; | ||
min-height: 100vh; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
font-size: calc(10px + 2vmin); | ||
color: white; | ||
} | ||
|
||
.App-link { | ||
color: #61dafb; | ||
} | ||
|
||
@keyframes App-logo-spin { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import { useState, useEffect } from 'react'; | ||
import logo from './logo.svg'; | ||
import './App.css'; | ||
|
||
function App() { | ||
const [count, setCount] = useState(1); | ||
useEffect(() => { | ||
const timer = setInterval(() => { | ||
setCount((x) => x + 1); | ||
}, 1000); | ||
return () => { | ||
clearInterval(timer); | ||
}; | ||
}, []); | ||
return ( | ||
<div className="App"> | ||
<header className="App-header"> | ||
<img src={logo} className="App-logo" alt="logo" /> | ||
<p> | ||
Edit <code>src/App.jsx</code> and save to reload. | ||
</p> | ||
<div>count: {count}</div> | ||
<a | ||
className="App-link" | ||
href="https://preactjs.com/" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
Learn Preact | ||
</a> | ||
</header> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
body { | ||
margin: 0; | ||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', | ||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', | ||
sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
} | ||
|
||
code { | ||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', | ||
monospace; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import './index.css'; | ||
import App from './App'; | ||
|
||
const root = ReactDOM.createRoot(document.getElementById('root')); | ||
root.render(<App />); | ||
|
||
if (module.hot) { | ||
module.hot.accept(); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.