-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
94 lines (84 loc) · 2.01 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
import * as path from 'path'
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import babel from 'rollup-plugin-babel'
import cleaner from 'rollup-plugin-cleaner'
import multiEntry from 'rollup-plugin-multi-entry'
import replace from 'rollup-plugin-replace'
import pkg from './package.json'
const dist = 'dist'
const defaultPlatform = 'node'
export default () => {
const plugins = [
babel({
exclude: 'node_modules/**',
extensions: ['.js', '.ts']
}),
resolve({
extensions: ['.mjs', '.js', '.ts', 'json'],
preferBuiltins: true
})
]
const input = 'src/index.ts'
if (process.env.PURPOSE === 'test') {
const platform = process.env.PLATFORM || defaultPlatform
const pluginsForTest = [
multiEntry(),
replace({
PLATFORM: JSON.stringify(platform)
})
]
.concat(plugins)
.concat([
commonjs({
namedExports: {
'should-util': ['hasOwnProperty']
}
}),
])
const output = {}
if(platform === 'node') {
output.file = pkg.testBundleInNode.output
output.format = pkg.testBundleInNode.format
}
else {
output.file = pkg.testBundleInBrowser.output
output.format = pkg.testBundleInBrowser.format
output.name = pkg.testBundleInBrowser.name
}
return [
{
input: `**/__test__/**/*.${platform}.ts`,
output,
external: ['events'],
plugins: pluginsForTest
}
]
}
else {
const pluginsForDist = plugins.concat([commonjs()])
const pluginsWitchCleanUp = [
cleaner({
targets: [dist]
})
].concat(pluginsForDist)
return [
{
input,
output: {
file: path.resolve(pkg.module),
format: 'esm'
},
plugins: pluginsWitchCleanUp
},
{
input,
output: {
file: path.resolve(pkg.main),
format: 'cjs'
},
plugins: pluginsForDist
}
]
}
}