Skip to content

Commit

Permalink
feat(README.md): update package.json to better handle module resolution
Browse files Browse the repository at this point in the history
- Replace "exports" field with "main", "module", and "browser" fields
- Ensure Node.js environment uses index.node.js
- Direct build tools supporting ES modules to use index.mjs
- Specify browser environment to replace index.node.js with index.mjs

This change improves module resolution across different environments and build tools, addressing potential issues with server-side and client-side execution in Next.js projects.
  • Loading branch information
mhchia committed Apr 15, 2023
1 parent bda0f3e commit 9b80802
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
"access": "public"
},
"main": "./dist/index.node.js",
"types": "./dist/types/index.d.ts",
"exports": {
"import": "./dist/index.mjs",
"require": "./dist/index.node.js"
"module": "./dist/index.mjs",
"browser": {
"./dist/index.node.js": "./dist/index.mjs"
},
"types": "./dist/types/index.d.ts",
"directories": {
"dist": "./dist",
"src": "./src",
Expand Down
4 changes: 2 additions & 2 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default [
// Node.js build
{
input,
output: { file: pkg.exports.require, format: 'cjs', banner },
output: { file: pkg.main, format: 'cjs', banner },
external: Object.keys(pkg.dependencies),
plugins: [
cleaner({
Expand All @@ -84,7 +84,7 @@ export default [
// Browser build
{
input,
output: { file: pkg.exports.import, format: 'es', banner },
output: { file: pkg.module, format: 'es', banner },
plugins: [
...browserPlugins,
visualizerPlugin,
Expand Down

0 comments on commit 9b80802

Please sign in to comment.