-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
79 lines (73 loc) · 1.93 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
import babel from '@rollup/plugin-babel';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import url from '@rollup/plugin-url';
import image from '@rollup/plugin-image';
import replace from '@rollup/plugin-replace';
import filesize from 'rollup-plugin-filesize';
import css from 'rollup-plugin-css-only';
import svgr from '@svgr/rollup';
import del from 'rollup-plugin-delete';
// package.json 에 main , module 등 설정해논 경로가 있음
import pkg from './package.json';
const INPUT_FILE_PATH = 'src/index.js';
const PLUGINS = [
// 바벨로 es5 으로 변환.
babel({
babelHelpers: 'runtime',
exclude: 'node_modules/**'
}),
commonjs(),
resolve({
// browser: true,
resolveOnly: [
/^(?!react$)/,
/^(?!react-dom$)/,
/^(?!prop-types)/,
/^(?!qrcode.react)/
]
}),
css({ output: 'gosrockStyle.css' }),
replace({
values: {
"import 'reset.css';": ''
},
delimiters: ['', '']
}),
filesize(),
url(),
svgr({ icon: false }),
image(),
del({
targets: 'dist/*.svg',
verbose: true,
hook: 'writeBundle',
runOnce: false
})
];
// peer dependency 와 연관
const EXTERNAL = ['react', 'react-dom', 'prop-types', 'qrcode.react'];
const CJS_AND_ES_EXTERNALS = EXTERNAL.concat(/@babel\/runtime/);
const OUTPUT_DATA = [
{
file: pkg.module,
format: 'es'
},
{
file: pkg.main,
format: 'cjs'
}
];
const config = OUTPUT_DATA.map(({ file, format }) => ({
input: INPUT_FILE_PATH,
output: {
file,
format
},
// runtime 으로 바벨 플러그인 설정
// https://github.com/rollup/plugins/tree/master/packages/babel#babelhelpers
// 익스터널에 적용해야 임포트 시켰을때 해당 임포트 시킨사람의 로컬에서 dependency를 찾아 임포트함
external: ['cjs', 'es'].includes(format) ? CJS_AND_ES_EXTERNALS : EXTERNAL,
plugins: PLUGINS
}));
export default config;