Skip to content

Commit

Permalink
Output a separate "legacy ESM" artifact for Webpack 4
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Apr 3, 2023
1 parent b1dffb5 commit 6345695
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Andrew Clark <acdlite@me.com> (https://github.com/acdlite)"
],
"main": "dist/cjs/redux.cjs",
"module": "dist/redux.mjs",
"module": "dist/redux.legacy-esm.js",
"types": "dist/redux.d.ts",
"exports": {
"./package.json": "./package.json",
Expand Down
7 changes: 6 additions & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineConfig, Options } from 'tsup'
import * as babel from '@babel/core'
import { Plugin } from 'esbuild'
import { getBuildExtensions } from 'esbuild-extra'
import fs from 'fs'

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

0 comments on commit 6345695

Please sign in to comment.