-
Notifications
You must be signed in to change notification settings - Fork 17
/
rollup.config.js
85 lines (77 loc) · 1.57 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
import resolve from '@rollup/plugin-node-resolve'
import babel from '@rollup/plugin-babel'
import replace from '@rollup/plugin-replace'
import { eslint } from 'rollup-plugin-eslint'
import { terser } from 'rollup-plugin-terser'
import { version } from './package.json'
import sourcemaps from 'rollup-plugin-sourcemaps'
/**
* Returns the input file path
* @param {('SERVICE_WORKER' | 'WEB')} mode
*/
const getInput = (mode) => {
if (mode === 'SERVICE_WORKER') {
return 'sw_webpush.js'
}
return 'src/main.js'
}
/**
* returns the output object of the build config
* @param {('SERVICE_WORKER' | 'WEB')} mode
*/
const getOutput = (mode) => {
if (mode === 'SERVICE_WORKER') {
return [
{
name: 'sw_webpush',
file: 'sw_webpush.min.js',
format: 'umd',
plugins: [terser()]
}
]
}
return [
{
name: 'clevertap',
file: 'clevertap.js',
format: 'umd',
sourcemap: true
},
{
name: 'clevertap',
file: 'clevertap.min.js',
format: 'umd',
plugins: [terser()]
}
]
}
/**
* returns the plugins array
*/
const getPlugins = () => {
return [
resolve(),
sourcemaps(),
eslint({
fix: true,
throwOnError: true
}),
replace({
preventAssignment: true,
delimiters: ['', ''],
$$PACKAGE_VERSION$$: version
}),
babel({
babelHelpers: 'bundled'
})
]
}
const config = () => {
const mode = process.env.MODE
return {
input: getInput(mode),
output: getOutput(mode),
plugins: getPlugins()
}
}
export default config()