Skip to content
Myr

tsup.config.ts

This file

Path

tsup.config.ts

91 lines · 1.9 KiB · TypeScript

Last changed by

chore: fixed raise condition in directory creation (?)Michel Weststratebefore adoptioncb322f5

History of this file

Take it

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

lines 1–29why, 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,

chore: fixed raise condition in directory creation (?)Michel Weststratebefore adoptioncb322f5

line 30why, one step back
30 sourcemap: true

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

lines 31–80why, one step back
31 },
32 // ESM, Webpack 4 support. Target ES2018 syntax to compile away optional chaining and spreads33 {34 ...commonOptions,35 entry: {36 "immer.legacy-esm": "src/immer.ts"37 },38 // ESBuild outputs `'.mjs'` by default for the 'esm' format. Force '.js'39 outExtension: () => ({js: ".js"}),40 target: "es2017",41 format: ["esm"],42 sourcemap: true43 },44 // ESM for use in browsers. Minified, with `process` compiled away45 {46 ...commonOptions,47 ...productionOptions,48 entry: {49 "immer.production": "src/immer.ts"50 },51 format: ["esm"],52 outExtension: () => ({js: ".mjs"})53 },54 // CJS development55 {56 ...commonOptions,57 entry: {58 "immer.cjs.development": "src/immer.ts"59 },60 format: "cjs",6162 outDir: "./dist/cjs/"63 },64 // CJS production65 {66 ...commonOptions,67 ...productionOptions,68 entry: {69 "immer.cjs.production": "src/immer.ts"70 },71 format: "cjs",72 outDir: "./dist/cjs/",73 onSuccess: () => {74 // Write the CJS index file75 fs.writeFileSync(76 "dist/cjs/index.js",77 `78'use strict'7980if (process.env.NODE_ENV === 'production') {

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

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

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

lines 82–85why, one step back
82} else {
83 module.exports = require('./immer.cjs.development.js')84}`85 )

chore: fixed raise condition in directory creation (?)Michel Weststratebefore adoptioncb322f5

lines 86–87why, one step back
86 // Support Flow types
87 fs.copyFileSync("src/types/index.js.flow", "dist/cjs/index.js.flow")

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

lines 88–91why, one step back
88 }
89 }90 ]91})