This repository was archived by the owner on Jan 21, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrollup.config.js
More file actions
100 lines (92 loc) · 2.22 KB
/
rollup.config.js
File metadata and controls
100 lines (92 loc) · 2.22 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
import babel from 'rollup-plugin-babel'
import replace from 'rollup-plugin-replace'
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import { terser } from 'rollup-plugin-terser'
const ENV = process.env.NODE_ENV || 'development'
const ENV_ALIASES = {
production: 'prod',
development: 'dev',
test: 'prod',
}
const ENTRY_FILES = ['factory', 'index', 'createElement']
const plugins = format => {
return [
replace({
'process.env.NODE_ENV': JSON.stringify(ENV),
}),
babel({
exclude: 'node_modules/**',
babelrc: false,
presets: [
['@babel/preset-env', { targets: { esmodules: format === 'esm' } }],
],
}),
resolve({
browser: true,
}),
commonjs(),
ENV !== 'development' ? terser() : null,
].filter(Boolean)
}
const confCreators = ENTRY_FILES.map(entryName => [
entryName,
format => ({
input: `./src/${entryName}.js`,
output: {
format,
file: `lib/${format}/${entryName}.${ENV_ALIASES[ENV]}.js`,
compact: ENV === 'production',
},
plugins: plugins(format),
}),
])
const EXTERNAL = {
createElement: ['react'],
index: ['inline-style-prefixer', 'fnv1a'],
factory: ['inline-style-prefixer', 'fnv1a'],
}
const CJS_CONFIG = confCreators.map(([entryName, creator]) => ({
...creator('cjs'),
external: EXTERNAL[entryName],
}))
const ESM_CONFIG = confCreators.map(([entryName, creator]) => ({
...creator('esm'),
external: EXTERNAL[entryName],
}))
const GLOBALS = {
createElement: {
react: 'React',
},
}
const UMD_CONFIG = confCreators.map(([entryName, creator]) => {
const config = creator('umd')
config.output.name = `styleSheet${
entryName === 'index'
? ''
: entryName.charAt(0).toUpperCase() + entryName.slice(1)
}`
config.output.globals = GLOBALS[entryName]
return config
})
const BABEL_PLUGIN_CONFIG = {
input: './src/babel.js',
output: {
file: './lib/babel.js',
format: 'cjs',
exports: 'named',
},
plugins: [
resolve({
browser: false,
}),
commonjs(),
],
external: ['linaria/lib/babel/evaluate', 'babel-helper-evaluate-path'],
}
export default [
...CJS_CONFIG,
...ESM_CONFIG,
...UMD_CONFIG,
BABEL_PLUGIN_CONFIG,
]