-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
rollup.config.js
124 lines (116 loc) · 2.66 KB
/
rollup.config.js
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
import typescript from 'rollup-plugin-typescript2';
import babel from '@rollup/plugin-babel';
import { terser } from 'rollup-plugin-terser';
import rollupReplace from 'rollup-plugin-replace';
import fileSize from 'rollup-plugin-filesize';
import glob from 'fast-glob';
import path from 'path';
import fs from 'fs';
const createTsPlugin = ({ declaration = true, target } = {}) =>
typescript({
clean: true,
tsconfigOverride: {
compilerOptions: {
declaration,
...(target && { target })
}
}
});
const createBabelPlugin = () =>
babel({
babelrc: false,
configFile: false,
skipPreflightCheck: true,
babelHelpers: 'inline',
extensions: ['.ts', '.tsx', '.js'],
plugins: ['babel-plugin-annotate-pure-calls']
});
const createNpmConfig = ({ input, output }) => ({
input,
output,
preserveModules: true,
plugins: [
createTsPlugin(),
createBabelPlugin(),
/** @ts-ignore [symbolObservable] creates problems who are on older versions of TS, remove this plugin when we drop support for TS@<4.3 */
{
writeBundle(outputOptions, bundle) {
const [, dtsAsset] = Object.entries(bundle).find(
([fileName]) => fileName === 'interpreter.d.ts'
);
const dtsPath = path.join(
__dirname,
outputOptions.dir,
'interpreter.d.ts'
);
fs.writeFileSync(
dtsPath,
dtsAsset.source.replace(
'[symbolObservable]():',
'[Symbol.observable]():'
)
);
}
}
]
});
const createUmdConfig = ({ input, output, target = undefined }) => ({
input,
output,
plugins: [
rollupReplace({
'process.env.NODE_ENV': JSON.stringify('production')
}),
createTsPlugin({ declaration: false, target }),
createBabelPlugin(),
terser({
toplevel: true
}),
fileSize()
]
});
const npmInputs = glob.sync('src/!(scxml|invoke|model.types|typegenTypes).ts');
export default [
createNpmConfig({
input: npmInputs,
output: [
{
dir: 'lib',
format: 'cjs'
}
]
}),
createNpmConfig({
input: npmInputs,
output: [
{
dir: 'es',
format: 'esm'
}
]
}),
createUmdConfig({
input: 'src/index.ts',
output: {
file: 'dist/xstate.js',
format: 'umd',
name: 'XState'
}
}),
createUmdConfig({
input: 'src/interpreter.ts',
output: {
file: 'dist/xstate.interpreter.js',
format: 'umd',
name: 'XStateInterpreter'
}
}),
createUmdConfig({
input: 'src/index.ts',
output: {
file: 'dist/xstate.web.js',
format: 'esm'
},
target: 'ES2015'
})
];