Skip to content

Commit

Permalink
Merge pull request #145 from OSpoon/feature/preact-fast-refresh
Browse files Browse the repository at this point in the history
feat(preact): replace react-refresh with @prefresh/webpack
  • Loading branch information
cezaraugusto authored Aug 11, 2024
2 parents 09a7e74 + dd7f477 commit 9277fe1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
1 change: 1 addition & 0 deletions programs/develop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"optionalDependencies": {
"@babel/core": "^7.24.9",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
"@prefresh/webpack": "^4.0.1",
"@svgr/webpack": "^8.1.0",
"@vue/compiler-sfc": "^3.4.34",
"babel-loader": "^9.1.3",
Expand Down
15 changes: 7 additions & 8 deletions programs/develop/webpack/plugin-js-frameworks/js-tools/preact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,17 @@ export async function maybeUsePreact(
if (!isUsingPreact(projectPath)) return undefined

try {
require.resolve('react-refresh')
// Fast-refresh for Preact!
// https://github.com/preactjs/prefresh
require.resolve('@prefresh/webpack')
} catch (e) {
const reactDependencies = [
'react-refresh',
'@pmmmwh/react-refresh-webpack-plugin',
'@svgr/webpack',
'react-refresh-typescript'
const preactDependencies = [
'@prefresh/webpack'
]
const manifest = require(path.join(projectPath, 'manifest.json'))
const manifestName = manifest.name || 'Extension.js'

await installOptionalDependencies(manifestName, 'Preact', reactDependencies)
await installOptionalDependencies(manifestName, 'Preact', preactDependencies)

// The compiler will exit after installing the dependencies
// as it can't read the new dependencies without a restart.
Expand All @@ -68,7 +67,7 @@ export async function maybeUsePreact(
}

const preactPlugins: WebpackPluginInstance[] = [
new (require('@pmmmwh/react-refresh-webpack-plugin'))()
new (require('@prefresh/webpack'))()
]

return {
Expand Down

0 comments on commit 9277fe1

Please sign in to comment.