[web3.js][experimental] Improve package exports (#28948)

* [web3.js][experimental] Repair build paths and add package.json `exports` field for CommonJS/ESM compatibility

* [web3.js][experimental] Add package.json entries for common JavaScript CDNs

* [web3.js][experimental] Exclude source files from npm bundle
This commit is contained in:
Steven Luscher 2022-11-23 16:47:56 -08:00 committed by GitHub
parent 267bbcadcf
commit e8da995e14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 18 deletions

View File

@ -2,15 +2,33 @@
"name": "@solana/web3.js-experimental",
"version": "0.0.0-development",
"description": "Solana Javascript API",
"browser": {
"./dist/index.node.cjs.js": "./dist/index.browser.cjs.js",
"./dist/index.node.esm.js": "./dist/index.browser.esm.js"
"exports": {
"browser": {
"import": "./dist/index.browser.js",
"require": "./dist/index.browser.cjs"
},
"node": {
"import": "./dist/index.node.js",
"require": "./dist/index.node.cjs"
},
"react-native": "./dist/index.native.js",
"types": "./dist/types/index.d.ts"
},
"react-native": "./dist/index.native.esm.js",
"main": "./dist/index.node.cjs.js",
"module": "./dist/index.node.esm.js",
"types": "./dist/index.d.ts",
"browser": {
"./dist/index.node.cjs": "./dist/index.browser.cjs",
"./dist/index.node.js": "./dist/index.browser.js"
},
"jsdelivr": "./dist/index.production.min.js",
"umd": "./dist/index.production.min.js",
"unpkg": "./dist/index.production.min.js",
"main": "./dist/index.node.cjs",
"module": "./dist/index.node.js",
"react-native": "./dist/index.native.js",
"types": "./dist/types/index.d.ts",
"type": "module",
"files": [
"./dist/"
],
"sideEffects": false,
"keywords": [
"blockchain",
@ -24,9 +42,9 @@
"compile:typedefs": "tsc -p ./tsconfig.declarations.json",
"dev": "pnpm run compile:js --watch",
"lint": "eslint 'src/**'",
"verifyTreeShakability:browser": "agadoo dist/index.browser.esm.js",
"verifyTreeShakability:native": "agadoo dist/index.node.esm.js",
"verifyTreeShakability:node": "agadoo dist/index.native.esm.js"
"verifyTreeShakability:browser": "agadoo dist/index.browser.js",
"verifyTreeShakability:native": "agadoo dist/index.node.js",
"verifyTreeShakability:node": "agadoo dist/index.native.js"
},
"author": "Solana Maintainers <maintainers@solana.com>",
"license": "MIT",

View File

@ -3,7 +3,7 @@
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "./dist"
"outDir": "./dist/types"
},
"extends": "./tsconfig.json",
"include": ["src/index.ts", "src/types"]

View File

@ -30,16 +30,14 @@ function getBaseConfig(platform: Platform, format: Format[], options: Options):
name: platform,
onSuccess: options.watch ? 'tsc -p ./tsconfig.declarations.json' : undefined,
outExtension({ format }) {
const parts: string[] = [];
if (format !== 'iife') {
parts.push(platform);
}
parts.push(format);
let extension;
if (format === 'iife') {
parts.push(isDebugBuild ? 'development' : 'production');
extension = `.${isDebugBuild ? 'development' : 'production.min'}.js`;
} else {
extension = `.${platform}.${format === 'cjs' ? 'cjs' : 'js'}`;
}
return {
js: `.${parts.join('.')}.js`,
js: extension,
};
},
platform: platform === 'node' ? 'node' : 'browser',