-
Notifications
You must be signed in to change notification settings - Fork 35
/
rollup.config.js
81 lines (73 loc) · 2.17 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
const babel = require("rollup-plugin-babel"),
{ terser } = require("rollup-plugin-terser"),
license = require("rollup-plugin-license"),
replace = require("rollup-plugin-replace");
const getBanner = isMin => {
if (isMin) {
return '/*! <%= pkg.name %> v<%= pkg.version %> | (c) <%= moment().format("YYYY") %> <%= pkg.author %> | <%= pkg.license %> License | <%= pkg.homepage %> */';
} else {
return [
" -------------------------------------------------------------------",
" <%= pkg.name %>",
" <%= pkg.description %>",
"",
" @author <%= pkg.author %>",
" @version v<%= pkg.version %>",
" @link <%= pkg.homepage %>",
" @license <%= pkg.license %> : https://github.com/Twikito/easy-toggle-state/blob/master/LICENSE",
" -------------------------------------------------------------------"
].join("\n");
}
};
const getFileName = (version = "es5", isMin = false) => {
const base = "easy-toggle-state";
const ext = isMin ? "min.js" : "js";
if (version === "es5") {
return [base, "es5", ext].filter(Boolean).join(".");
}
return [base, ext].filter(Boolean).join(".");
};
const getBabelConfig = (version = "es5") => {
if (version === "es5") {
return {
presets: [
['@babel/preset-env', {
'modules': false,
'targets': {
'browsers': [
'last 2 versions'
]
}
}]
]
};
}
return {};
};
const getPlugins = (version = "es5", isMin = false) => {
const babelConfig = getBabelConfig(version);
const list = [];
if (version === "es5") list.push(babel(babelConfig));
if (isMin) list.push(terser());
list.push(license({ banner: getBanner(isMin) }));
return list;
};
const getPreferConst = (version = "es5") => version === "es6";
const getConfig = () => {
const isMinify = process.env.OUT_STYLE === "min",
fileName = getFileName(process.env.NODE_ENV, isMinify),
preferConst = getPreferConst(process.env.NODE_ENV),
plugins = getPlugins(process.env.NODE_ENV, isMinify);
return { fileName, preferConst, plugins };
};
const { fileName, preferConst, plugins } = getConfig();
export default {
input: "src/index.js",
output: {
file: `dist/${fileName}`,
format: "iife",
name: "easyToggleState",
preferConst
},
plugins,
};