-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4511 from reduxjs/feature/build-esm-fixes
- Loading branch information
Showing
10 changed files
with
736 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
{ | ||
"sandboxes": [ | ||
"vanilla", | ||
"vanilla-ts" | ||
], | ||
"node": "14" | ||
"sandboxes": ["vanilla", "vanilla-ts"], | ||
"node": "16" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,27 +23,23 @@ | |
"Dan Abramov <[email protected]> (https://github.com/gaearon)", | ||
"Andrew Clark <[email protected]> (https://github.com/acdlite)" | ||
], | ||
"type": "module", | ||
"module": "dist/es/index.js", | ||
"main": "dist/cjs/index.cjs", | ||
"types": "types/index.d.ts", | ||
"main": "dist/cjs/redux.cjs", | ||
"module": "dist/redux.mjs", | ||
"types": "dist/redux.d.ts", | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": { | ||
"types": "./types/index.d.ts", | ||
"import": "./dist/es/index.js", | ||
"default": "./dist/cjs/index.cjs" | ||
"types": "./dist/redux.d.ts", | ||
"import": "./dist/redux.mjs", | ||
"default": "./dist/cjs/redux.cjs" | ||
} | ||
}, | ||
"files": [ | ||
"dist", | ||
"lib", | ||
"es", | ||
"src", | ||
"types" | ||
"src" | ||
], | ||
"scripts": { | ||
"clean": "rimraf lib dist es coverage types", | ||
"clean": "rimraf dist", | ||
"format": "prettier --write \"{src,test}/**/*.{js,ts}\" \"**/*.md\"", | ||
"format:check": "prettier --list-different \"{src,test}/**/*.{js,ts}\" \"**/*.md\"", | ||
"lint": "eslint --ext js,ts src test", | ||
|
@@ -52,7 +48,7 @@ | |
"test:types": "tsc -p test/typescript && echo \"Typetests passed\"", | ||
"test:watch": "vitest", | ||
"test:cov": "vitest --coverage", | ||
"build": "rollup -c", | ||
"build": "tsup", | ||
"prepublishOnly": "yarn clean && yarn check-types && yarn format:check && yarn lint && yarn test", | ||
"prepack": "yarn build", | ||
"examples:lint": "eslint --ext js,ts examples", | ||
|
@@ -79,6 +75,7 @@ | |
"@typescript-eslint/eslint-plugin": "^5.36.2", | ||
"@typescript-eslint/parser": "^5.36.2", | ||
"cross-env": "^7.0.3", | ||
"esbuild-extra": "^0.1.3", | ||
"eslint": "^8.23.0", | ||
"eslint-config-react-app": "^7.0.1", | ||
"eslint-import-resolver-typescript": "^3.5.1", | ||
|
@@ -94,6 +91,7 @@ | |
"rollup": "^3.12.0", | ||
"rollup-plugin-typescript2": "^0.34.1", | ||
"rxjs": "^7.5.6", | ||
"tsup": "^6.7.0", | ||
"typescript": "^4.8.3", | ||
"vitest": "^0.27.2" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { defineConfig, Options } from 'tsup' | ||
|
||
import * as babel from '@babel/core' | ||
import { Plugin } from 'esbuild' | ||
import { getBuildExtensions } from 'esbuild-extra' | ||
|
||
// Extract error strings, replace them with error codes, and write messages to a file | ||
const mangleErrorsTransform: Plugin = { | ||
name: 'mangle-errors-plugin', | ||
setup(build) { | ||
const { onTransform } = getBuildExtensions(build, 'mangle-errors-plugin') | ||
|
||
onTransform({ loaders: ['ts', 'tsx'] }, async args => { | ||
const res = babel.transformSync(args.code, { | ||
parserOpts: { | ||
plugins: ['typescript'] | ||
}, | ||
plugins: [['./scripts/mangleErrors.cjs', { minify: false }]] | ||
})! | ||
return { | ||
code: res.code!, | ||
map: res.map! | ||
} | ||
}) | ||
} | ||
} | ||
|
||
export default defineConfig(options => { | ||
const commonOptions: Partial<Options> = { | ||
entry: { | ||
redux: 'src/index.ts' | ||
}, | ||
esbuildPlugins: [mangleErrorsTransform], | ||
sourcemap: true, | ||
...options | ||
} | ||
|
||
return [ | ||
// Standard ESM, embedded `process.env.NODE_ENV` checks | ||
{ | ||
...commonOptions, | ||
format: ['esm'], | ||
outExtension: () => ({ js: '.mjs' }), | ||
dts: true, | ||
clean: true | ||
}, | ||
// Browser-ready ESM, production + minified | ||
{ | ||
...commonOptions, | ||
entry: { | ||
'redux.browser': 'src/index.ts' | ||
}, | ||
define: { | ||
'process.env.NODE_ENV': JSON.stringify('production') | ||
}, | ||
format: ['esm'], | ||
outExtension: () => ({ js: '.mjs' }), | ||
minify: true | ||
}, | ||
{ | ||
...commonOptions, | ||
format: 'cjs', | ||
outDir: './dist/cjs/', | ||
outExtension: () => ({ js: '.cjs' }) | ||
} | ||
] | ||
}) |
Oops, something went wrong.