From 6a2bd5f43f6429f8273c7d7104a45ac0f585843d Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Sun, 2 Apr 2023 22:53:53 -0400 Subject: [PATCH] Output a separate "legacy ESM" artifact for Webpack 4 --- .github/workflows/test.yaml | 2 ++ package.json | 2 +- tsup.config.ts | 7 ++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 691ee2f46a..26609ec159 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -16,6 +16,8 @@ jobs: src: - 'src/**' - 'test/**' + - '.github/**/*.yaml' + - 'tsup.config.ts' build: needs: changes diff --git a/package.json b/package.json index 2e0969f025..5c563aa8c3 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "Andrew Clark (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", diff --git a/tsup.config.ts b/tsup.config.ts index c159e95953..739de93ab9 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -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 = { @@ -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 {