Skip to content
Myr

tsup.config.ts

This file

Path

tsup.config.ts

93 lines · 1.9 KiB · TypeScript

Last changed by

fix: Move index.js.flow from dist/ -> dist/cjs/ to match index.js (#1038)Björgvin Ragnarssonbefore adoptiona3b5603

History of this file

Take it

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

lines 1–32why, one step back
1import {defineConfig, Options} from "tsup"
2import fs from "fs"34export default defineConfig(options => {5 const commonOptions: Partial<Options> = {6 entry: {7 immer: "src/immer.ts"8 },9 sourcemap: true,10 ...options11 }1213 const productionOptions = {14 minify: true,15 esbuildOptions(options, _context) {16 options.mangleProps = /_$/17 },18 define: {19 "process.env.NODE_ENV": JSON.stringify("production")20 }21 }2223 return [24 // ESM, standard bundler dev, embedded `process` references25 {26 ...commonOptions,27 format: ["esm"],28 dts: true,29 clean: true,30 sourcemap: true,31 onSuccess() {32 // Support Flow types

fix: Move index.js.flow from dist/ -> dist/cjs/ to match index.js (#1038)Björgvin Ragnarssonbefore adoptiona3b5603

line 33why, one step back
33 fs.copyFileSync("src/types/index.js.flow", "dist/cjs/index.js.flow")

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

lines 34–84why, one step back
34 }
35 },36 // ESM, Webpack 4 support. Target ES2018 syntax to compile away optional chaining and spreads37 {38 ...commonOptions,39 entry: {40 "immer.legacy-esm": "src/immer.ts"41 },42 // ESBuild outputs `'.mjs'` by default for the 'esm' format. Force '.js'43 outExtension: () => ({js: ".js"}),44 target: "es2017",45 format: ["esm"],46 sourcemap: true47 },48 // ESM for use in browsers. Minified, with `process` compiled away49 {50 ...commonOptions,51 ...productionOptions,52 entry: {53 "immer.production": "src/immer.ts"54 },55 format: ["esm"],56 outExtension: () => ({js: ".mjs"})57 },58 // CJS development59 {60 ...commonOptions,61 entry: {62 "immer.cjs.development": "src/immer.ts"63 },64 format: "cjs",6566 outDir: "./dist/cjs/"67 },68 // CJS production69 {70 ...commonOptions,71 ...productionOptions,72 entry: {73 "immer.cjs.production": "src/immer.ts"74 },75 format: "cjs",76 outDir: "./dist/cjs/",77 onSuccess: () => {78 // Write the CJS index file79 fs.writeFileSync(80 "dist/cjs/index.js",81 `82'use strict'8384if (process.env.NODE_ENV === 'production') {

fix: production bundle was loaded incorrectly, fixes #1037Michel Weststratebefore adoption707e72b

line 85why, one step back
85 module.exports = require('./immer.cjs.production.js')

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

lines 86–93why, one step back
86} else {
87 module.exports = require('./immer.cjs.development.js')88}`89 )90 }91 }92 ]93})