Repository navigation
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
125 lines (117 loc) · 3.26 KB
/
Copy pathtsdown.config.ts
File metadata and controls
125 lines (117 loc) · 3.26 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
117
118
119
120
121
122
123
124
125
import fs from 'node:fs'
import * as path from 'node:path'
import { defineConfig, type UserConfig } from 'tsdown'
import * as glob from 'glob'
import {
getWorkerChecksum,
copyWorkerPlugin,
} from './config/plugins/rolldown/copy-worker-plugin.ts'
const packageJson = JSON.parse(
fs.readFileSync(new URL('./package.json', import.meta.url), 'utf8'),
) as { dependencies: Record<string, string> }
const ecosystemDependencies = /^@mswjs\/(.+)$/
const SERVICE_WORKER_CHECKSUM = await getWorkerChecksum()
const commonConfig = {
target: 'esnext',
fixedExtension: false,
hash: false,
report: false,
clean: false,
} satisfies UserConfig
/**
* Every module under "src/utils" is a public entry
* (exposed via the "./utils/*" export in package.json).
*/
const utilsEntries = Object.fromEntries(
glob
.sync('./src/utils/*.ts', { ignore: '**/*.test.ts', posix: true })
.map((modulePath) => {
return [`utils/${path.basename(modulePath, '.ts')}`, modulePath]
}),
)
const esmConfig: UserConfig = {
...commonConfig,
name: 'esm',
platform: 'neutral',
entry: {
'core/index': './src/core/index.ts',
'core/experimental/index': './src/core/experimental/index.ts',
'http/index': './src/http/index.ts',
'graphql/index': './src/graphql/index.ts',
'ws/index': './src/ws/index.ts',
'sse/index': './src/sse/index.ts',
...utilsEntries,
'node/index': './src/node/index.ts',
'browser/index': './src/browser/index.ts',
},
deps: {
neverBundle: ['util', 'events', /^node:/, ecosystemDependencies],
onlyBundle: false,
},
format: ['esm'],
outDir: './lib',
unbundle: false,
outputOptions: {
entryFileNames: '[name].js',
chunkFileNames: '_chunks/[name].js',
codeSplitting: true,
},
sourcemap: true,
dts: true,
tsconfig: path.resolve(import.meta.dirname, 'src/tsconfig.core.build.json'),
define: {
SERVICE_WORKER_CHECKSUM: JSON.stringify(SERVICE_WORKER_CHECKSUM),
},
plugins: [copyWorkerPlugin(SERVICE_WORKER_CHECKSUM)],
}
const viteConfig: UserConfig = {
...commonConfig,
name: 'vite',
platform: 'node',
entry: ['./src/vite/index.ts', './src/vite/runtime.ts'],
deps: {
neverBundle: ['vite', 'msw/experimental'],
onlyBundle: false,
},
format: ['esm'],
outDir: './lib/vite',
unbundle: false,
sourcemap: true,
dts: true,
tsconfig: path.resolve(import.meta.dirname, 'src/vite/tsconfig.build.json'),
}
const iifeConfig: UserConfig = {
...commonConfig,
name: 'iife',
platform: 'browser',
globalName: 'MockServiceWorker',
entry: ['./src/iife/index.ts'],
deps: {
alwaysBundle: [
...Object.keys(packageJson.dependencies),
ecosystemDependencies,
// The IIFE bundle re-exports "msw/graphql", so the
// "graphql" peer dependency must be bundled with it.
'graphql',
],
onlyBundle: false,
},
outDir: './lib/iife',
format: ['iife'],
unbundle: false,
outputOptions: {
entryFileNames: 'index.js',
chunkFileNames: '[name].js',
codeSplitting: false,
},
sourcemap: true,
dts: false,
tsconfig: path.resolve(
import.meta.dirname,
'src/browser/tsconfig.browser.build.json',
),
define: {
SERVICE_WORKER_CHECKSUM: JSON.stringify(SERVICE_WORKER_CHECKSUM),
},
}
export default defineConfig([esmConfig, viteConfig, iifeConfig])