-
Notifications
You must be signed in to change notification settings - Fork 26
/
rollup.config.js
81 lines (76 loc) · 2.03 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
import path from 'path'
import babel from 'rollup-plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import external from 'rollup-plugin-peer-deps-external';
import scss from 'rollup-plugin-scss';
import resolve from '@rollup/plugin-node-resolve';
import image from '@rollup/plugin-image'
import markdown from '@jackfranklin/rollup-plugin-markdown'
import visualizer from 'rollup-plugin-visualizer';
import alias from '@rollup/plugin-alias';
import json from '@rollup/plugin-json';
import copy from 'rollup-plugin-copy';
import { uglify } from 'rollup-plugin-uglify';
import replace from '@rollup/plugin-replace';
import pkg from './package.json';
const mode = process.env.NODE_ENV || 'development'
const isProduction = mode==='production'
const resolveFile = function(filePath) {
return path.join(__dirname, filePath)
}
const config = {
input: './src/lib/index.js',
output: [
{
sourcemap: isProduction ? false : 'inline',
file: pkg.main,
format: 'cjs',
exports: 'named'
}
],
external: ['react', 'react-dom'],
plugins: [
alias({
entries: {
assets: resolveFile('src/assets'),
components: resolveFile('src/components'),
utils: resolveFile('src/utils'),
contexts: resolveFile('src/contexts'),
page: resolveFile('src/page'),
api: resolveFile('src/api')
}
}),
external(),
json(),
copy({
targets: [
{ src: resolveFile('src/lib/index.d.ts'), dest: resolveFile('dist') }
]
}),
scss({
outputStyle: isProduction ? 'compressed' : 'compact'
}),
babel({
exclude: 'node_modules/**'
}),
resolve({
preferBuiltins: true,
mainFields: ['browser']
}),
commonjs(),
image(),
markdown(),
replace({
preventAssignment: true,
values: {
'process.env.IS_MODULE': JSON.stringify(true),
'process.env.NODE_ENV': JSON.stringify(mode)
}
}),
visualizer()
]
};
if (isProduction) {
config.plugins.push(uglify())
}
export default config