-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
153 lines (138 loc) · 3.88 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import {babel} from "@rollup/plugin-babel"
import filesize from "rollup-plugin-filesize"
import {nodeResolve} from "@rollup/plugin-node-resolve"
import progress from "rollup-plugin-progress"
import {terser} from "rollup-plugin-terser"
const bannerProd = `/**
* DatePlus v4.0.0-beta2 | A simple program to assist with date manipulation
* @copyright Copyright (C) 2020 - 2021 Luke Zhang
* @license MIT
*/
`
const bannerDev = `/**
* DatePlus
* A simple program to assist with date manipulation
* @copyright Copyright (C) 2020 - 2021 Luke Zhang
* @author Luke Zhang luke-zhang-04.github.io
* @license MIT
* @version 4.0.0-beta2
*/
`
/**
* Creates plugin setup with parameters
*
* @param {string} target - Browserslist target env
* @param {boolean} prod - If bundle is production
* @returns {import("rollup").Plugin[]} Rollup plugin configs
*/
const makePlugins = (target = "es6", prod = true) => [
nodeResolve(),
babel({
babelrc: false,
babelHelpers: "bundled",
presets: [
[
"@babel/preset-env",
{
browserslistEnv: target,
},
],
],
minified: prod,
comments: !prod,
shouldPrintComment: (val) =>
!prod &&
/@/u.test(val) &&
!/eslint|istanbul/u.test(val) &&
!/@author Luke Zhang/u.test(val), // Remove license headers in favour of one banner
}),
...(prod
? [
terser({
mangle: {
properties: {
regex: /^_/u, // Mangle private properties
},
},
}),
]
: []),
// To make bundling look cool
filesize(),
progress(),
]
const es5 = (() => {
/**
* @type {import("rollup").RollupOptions[]}
*/
const configs = []
/**
* @type {[format: import("rollup").ModuleFormat, extension?: string][]}
*/
const formats = [["iife", "js"], ["cjs"]]
for (const [format, extension] of formats) {
configs.push({
input: "lib",
output: {
file: `dist/es5/dateplus.min.${extension ?? format}`,
format,
banner: bannerProd,
name: "DatePlus",
sourcemap: true,
},
plugins: makePlugins("es5", true),
})
configs.push({
input: "lib",
output: {
file: `dist/es5/dateplus.${extension ?? format}`,
format,
banner: bannerDev,
name: "DatePlus",
sourcemap: true,
},
plugins: makePlugins("es5", false),
})
}
return configs
})()
const es6 = (() => {
/**
* @type {import("rollup").RollupOptions[]}
*/
const configs = []
/**
* @type {[format: import("rollup").ModuleFormat, extension?: string][]}
*/
const formats = [["esm", "js"], ["iife", "js"], ["cjs"]]
for (const [format, extension] of formats) {
configs.push({
input: "lib",
output: {
file: `dist/${format}/dateplus.min.${extension ?? format}`,
format,
banner: bannerProd,
name: "DatePlus",
sourcemap: true,
},
plugins: makePlugins("es6", true),
})
configs.push({
input: "lib",
output: {
file: `dist/${format}/dateplus.${extension ?? format}`,
format,
banner: bannerDev,
name: "DatePlus",
sourcemap: true,
},
plugins: makePlugins("es6", false),
})
}
return configs
})()
/**
* @type {import("rollup").RollupOptions[]}
*/
const rollupConfig = [...es5, ...es6]
export default rollupConfig