feat(README.md): update package.json to better handle module resolution

- 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.
This commit is contained in:
mhchia
2023-04-15 19:07:37 +08:00
parent bda0f3e272
commit 9b80802ec5
2 changed files with 6 additions and 6 deletions

View File

@@ -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",

View File

@@ -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({
@@ -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,