Skip to content

Commit

Permalink
fix: skip hot reloading packages that are not locally imported
Browse files Browse the repository at this point in the history
  • Loading branch information
Cussone committed Nov 14, 2024
1 parent 4ef6c84 commit 67be021
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import p from "./package.json" assert { type: "json" }
import path from "path"
import { fileURLToPath } from "url"
import { createRequire } from "module"

const require = createRequire(import.meta.url)

const starknetkitNextVersion = Object.entries(p.dependencies)
.find((dep) => dep[0] === "starknetkit-next")[1]
Expand Down Expand Up @@ -48,20 +51,27 @@ const nextConfig = {

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const packageJson = require(path.join(__dirname, "./package.json"))

config.resolve.alias = {
...config.resolve.alias,
...localPackages.reduce(
(aliases, pkg) => ({
...aliases,
[pkg.name]: path.resolve(__dirname, pkg.path),
[`${pkg.name}/(.*)`]: path.resolve(__dirname, `${pkg.path}/$1`),
}),
{},
),
...localPackages.reduce((aliases, pkg) => {
if (packageJson.dependencies[pkg.name].startsWith("file:")) {
return {
...aliases,
[pkg.name]: path.resolve(__dirname, pkg.path),
[`${pkg.name}/(.*)`]: path.resolve(__dirname, `${pkg.path}/$1`),
}
}

return { ...aliases }
}, {}),
}

localPackages.forEach((pkg) => {
if (!packageJson.dependencies[pkg.name].startsWith("file:")) {
return
}
config.plugins.push(
new webpack.NormalModuleReplacementPlugin(
new RegExp(`^${pkg.name}(\\/.*)?$`),
Expand Down

0 comments on commit 67be021

Please sign in to comment.