-
Notifications
You must be signed in to change notification settings - Fork 55
/
rollup.config.js
87 lines (82 loc) · 2.27 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
import serve from 'rollup-plugin-serve'
import livereload from 'rollup-plugin-livereload'
import { terser } from 'rollup-plugin-terser'
import banner from 'rollup-plugin-banner'
import { getBabelOutputPlugin } from '@rollup/plugin-babel'
import typescript from 'rollup-plugin-typescript2'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import { inlineParser } from './scripts/plugins'
const FORMAT = process.env.FORMAT
const IS_TEST_ENV = process.env.NODE_ENV === 'test'
const DIST_FILE_NAME = 'index'
const TEST_DIR = '__test__'
const DIST_DIR = 'dist'
const UMD_NAME = 'SVGA'
const babelOutputPlugin = getBabelOutputPlugin({
allowAllFormats: true,
comments: false,
presets: [
[
'@babel/preset-env',
{
targets: {
browsers: [
'Android >= 4.4',
'iOS >= 9.0'
]
}
}
]
]
})
const config = [
{
onwarn () {},
input: IS_TEST_ENV ? 'src/test.ts' : 'src/index.ts',
output: {
file: IS_TEST_ENV ? `${TEST_DIR}/${DIST_FILE_NAME}.js` : `${DIST_DIR}/${DIST_FILE_NAME}${FORMAT === 'umd' ? '' : `.${FORMAT}`}.min.js`,
format: FORMAT,
name: UMD_NAME,
sourcemap: false
},
plugins: [
resolve({ jsnext: true, preferBuiltins: true, browser: true }),
commonjs(),
typescript({
tsconfig: IS_TEST_ENV ? 'tsconfig.test.json' : 'tsconfig.json'
}),
babelOutputPlugin,
IS_TEST_ENV && serve(TEST_DIR),
IS_TEST_ENV && livereload({
delay: 810,
watch: TEST_DIR,
verbose: false
}),
!IS_TEST_ENV && terser(),
!IS_TEST_ENV && banner('SVGA.Lite v<%= pkg.version %>'),
IS_TEST_ENV && inlineParser
]
}
]
if (IS_TEST_ENV || FORMAT === 'umd') {
config.unshift({
onwarn () {},
input: 'src/parser/index.ts',
output: {
file: IS_TEST_ENV ? `${TEST_DIR}/parser.js` : `${DIST_DIR}/parser.js`,
format: 'iife'
},
plugins: [
resolve({ jsnext: true, preferBuiltins: true, browser: true }),
commonjs(),
typescript({
tsconfig: IS_TEST_ENV ? 'tsconfig.test.json' : 'tsconfig.json'
}),
babelOutputPlugin,
!IS_TEST_ENV && terser(),
IS_TEST_ENV && inlineParser
]
})
}
export default config