Repository navigation
Expand file tree
/
Copy pathtsdown.config.mts
More file actions
116 lines (111 loc) · 2.88 KB
/
Copy pathtsdown.config.mts
File metadata and controls
116 lines (111 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import fs from 'node:fs/promises'
import path from 'node:path'
import type { UserConfig } from 'tsdown'
import { defineConfig } from 'tsdown'
async function writeCommonJSEntry() {
await fs.writeFile(
path.join('dist/cjs/', 'index.js'),
`'use strict'
if (process.env.NODE_ENV === 'production') {
module.exports = require('./reselect.production.min.cjs')
} else {
module.exports = require('./reselect.development.cjs')
}`
)
}
export default defineConfig((options): UserConfig[] => {
const commonOptions = {
entry: {
reselect: 'src/index.ts'
},
sourcemap: true,
// `pnpm clean` already removes `dist/`; letting each of the six builds
// clean would race them against each other.
clean: false,
hash: false,
report: false,
target: ['esnext'],
dts: false,
// esbuild dropped JSDoc from the bundles; Rolldown keeps it by default,
// which inflates every output file several times over. Legal and
// annotation comments stay so `@__PURE__` survives for consumers.
outputOptions: {
comments: { jsdoc: false }
},
...options
} satisfies UserConfig
return [
// Standard ESM, embedded `process.env.NODE_ENV` checks
{
...commonOptions,
name: 'Modern ESM',
format: ['esm'],
outExtensions: () => ({ js: '.mjs' })
},
// Support Webpack 4 by pointing `"module"` to a file with a `.js` extension
// and optional chaining compiled away
{
...commonOptions,
name: 'Legacy ESM, Webpack 4',
entry: {
'reselect.legacy-esm': 'src/index.ts'
},
format: ['esm'],
target: ['es2017'],
outExtensions: () => ({ js: '.js' })
},
// Meant to be served up via CDNs like `unpkg`.
{
...commonOptions,
name: 'Browser-ready ESM',
entry: {
'reselect.browser': 'src/index.ts'
},
platform: 'browser',
env: {
NODE_ENV: 'production'
},
format: ['esm'],
outExtensions: () => ({ js: '.mjs' }),
minify: true
},
{
...commonOptions,
name: 'CJS Development',
entry: {
'reselect.development': 'src/index.ts'
},
env: {
NODE_ENV: 'development'
},
format: ['cjs'],
outDir: './dist/cjs/',
outExtensions: () => ({ js: '.cjs' })
},
{
...commonOptions,
name: 'CJS production',
entry: {
'reselect.production.min': 'src/index.ts'
},
env: {
NODE_ENV: 'production'
},
format: ['cjs'],
outDir: './dist/cjs/',
outExtensions: () => ({ js: '.cjs' }),
minify: true,
onSuccess: async () => {
await writeCommonJSEntry()
}
},
{
...commonOptions,
name: 'Type definitions',
format: ['esm'],
sourcemap: false,
dts: { emitDtsOnly: true, sourcemap: false },
outExtensions: () => ({ dts: '.d.ts' })
}
]
})