Skip to content

Commit 6a2bd5f

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

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

.github/workflows/test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
src:
1717
- 'src/**'
1818
- 'test/**'
19+
- '.github/**/*.yaml'
20+
- 'tsup.config.ts'
1921
2022
build:
2123
needs: changes

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)