-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrollup.config.mjs
82 lines (77 loc) · 1.64 KB
/
rollup.config.mjs
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
import * as path from 'path'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import typescript from 'rollup-plugin-typescript2'
import json from '@rollup/plugin-json'
import packageJson from './package.json' assert { type: 'json' }
const plugins = [
json(),
resolve({
preferBuiltins: false,
mainFields: ['module', 'main', 'jsnext:main', 'browser'],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
}),
typescript({
useTsconfigDeclarationDir: true,
}),
commonjs(),
]
/**
* Configuration for the ESM build
*/
const buildEsm = {
external: ['msw'],
input: [
// Split modules so they can be tree-shaken
'src/index.ts',
],
output: {
entryFileNames: '[name].js',
chunkFileNames: '[name]-deps.js',
dir: path.dirname(packageJson.module),
format: 'esm',
},
plugins,
}
/**
* Configuration for the UMD build
*/
const buildUdm = {
external: ['msw'],
input: 'src/index.ts',
output: {
file: packageJson.main,
name: 'MswWebarchiveExtension',
format: 'umd',
esModule: false,
globals: {
msw: 'msw',
},
},
plugins,
}
const buildNode = {
input: 'src/node/index.ts',
external: ['msw'],
output: {
file: 'node/index.js',
format: 'cjs',
},
plugins: [
json(),
resolve({
browser: false,
preferBuiltins: true,
extensions: ['.js', '.jsx', '.ts', '.tsx'],
}),
typescript({
useTsconfigDeclarationDir: true,
tsconfigOverride: {
outDir: './node',
declarationDir: './dist/types/node',
},
}),
commonjs(),
],
}
export default [buildEsm, buildUdm, buildNode]