-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
57 lines (50 loc) · 1.41 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
import commonjs from 'rollup-plugin-commonjs'
import uglify from 'rollup-plugin-uglify'
import resolve from 'rollup-plugin-node-resolve'
import external from 'rollup-plugin-peer-deps-external'
import babel from 'rollup-plugin-babel'
import json from 'rollup-plugin-json'
import postcss from 'rollup-plugin-postcss'
const extensions = ['.js', '.jsx', '.ts', '.tsx']
function getConfig(name, dependencies = []) {
const config = {
input: `./src/${name}.ts`,
external: ['lodash', ...dependencies],
plugins: [
// Allows node_modules resolution
resolve({ extensions }),
// Allow CSS imports
postcss(),
// Allow bundling cjs modules. Rollup doesn't understand cjs
commonjs({
include: /node_modules/,
}),
json(),
// Compile TypeScript/JavaScript files
babel({ extensions, include: ['src/**/*'], exclude: 'node_modules/**' }),
external(),
],
output: [
{
file: `./dist/${name}.js`,
format: 'cjs',
exports: 'named',
},
{
file: `./dist/${name}.esm.js`,
format: 'es',
exports: 'named',
},
],
}
if (process.env.NODE_ENV === 'production') {
config.plugins.push(uglify())
}
return config
}
export default [
getConfig('index', ['react', 'react-dom']),
getConfig('hooks', ['react', 'react-dom']),
getConfig('ui', ['react', 'react-dom']),
getConfig('helpers'),
]