Skip to content

Commit 6345695

Browse files
committed
Output a separate "legacy ESM" artifact for Webpack 4
1 parent b1dffb5 commit 6345695

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"Andrew Clark <[email protected]> (https://github.com/acdlite)"
2525
],
2626
"main": "dist/cjs/redux.cjs",
27-
"module": "dist/redux.mjs",
27+
"module": "dist/redux.legacy-esm.js",
2828
"types": "dist/redux.d.ts",
2929
"exports": {
3030
"./package.json": "./package.json",

tsup.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { defineConfig, Options } from 'tsup'
33
import * as babel from '@babel/core'
44
import { Plugin } from 'esbuild'
55
import { getBuildExtensions } from 'esbuild-extra'
6+
import fs from 'fs'
67

78
// Extract error strings, replace them with error codes, and write messages to a file
89
const mangleErrorsTransform: Plugin = {
@@ -42,7 +43,11 @@ export default defineConfig(options => {
4243
format: ['esm'],
4344
outExtension: () => ({ js: '.mjs' }),
4445
dts: true,
45-
clean: true
46+
clean: true,
47+
onSuccess() {
48+
// Support Webpack 4 by pointing `"module"` to a file with a `.js` extension
49+
fs.copyFileSync('dist/redux.mjs', 'dist/redux.legacy-esm.js')
50+
}
4651
},
4752
// Browser-ready ESM, production + minified
4853
{

0 commit comments

Comments
 (0)