Skip to content

Commit

Permalink
Make CJS build compatible with React Native (#277).
Browse files Browse the repository at this point in the history
  • Loading branch information
molefrog committed Feb 6, 2023
1 parent bfad1ce commit f9f7ea7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"react": ">=16.8.0"
},
"dependencies": {
"@rollup/plugin-replace": "^5.0.2",
"use-sync-external-store": "^1.0.0"
},
"repository": "molefrog/wouter",
Expand Down
15 changes: 15 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import replace from "@rollup/plugin-replace";

// support for preact builds
const isPreact = String(process.env.DIR).indexOf("preact") !== -1;

Expand Down Expand Up @@ -25,13 +27,26 @@ export default [
"preact/hooks",
"use-sync-external-store/shim/index.js",
"use-sync-external-store/shim/index.native.js",
// tell Rollup not to apply any optimizations to unqualified `use-sync-external-store`
// import (see comment below)
"./use-sync-external-store",
],
output: {
dir: OUTPUT_DIR,
format: "cjs",
preserveModules: true,
exports: "named",
},
plugins: [
replace({
// replaces qualified import with an unqualified one
// so that React Native's bundler can pick up the right source file
// See https://github.com/molefrog/wouter/pull/277#issuecomment-1382930657
"./use-sync-external-store.js": "./use-sync-external-store",
preventAssignment: true,
delimiters: ["", ""],
}),
],
},
{
// TODO: migrate `static-location` to ESM object exports
Expand Down

0 comments on commit f9f7ea7

Please sign in to comment.