-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrollup.config.js
121 lines (117 loc) · 3.25 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
// import rollup from "rollup";
import resolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
import json from "rollup-plugin-json";
import babel from "rollup-plugin-babel";
import { eslint } from "rollup-plugin-eslint";
import { terser } from "rollup-plugin-terser";
const pkg = require("./package.json");
const banner = (function() {
const row = [
`Leaflet.CustomLayer.js v${pkg.version}`,
"",
"Copyright (c) 2019-present Derek Li",
"Released under the MIT License - https://choosealicense.com/licenses/mit/",
"",
"https://github.com/iDerekLi/Leaflet.CustomLayer"
];
return ["/*!", ...row.map(r => `* ${r}`), "*/"].join("\n ");
})();
function getBaseConfig() {
const baseConfig = {
input: "src/Leaflet.CustomLayer.js",
plugins: [
json(),
resolve({
jsnext: false, // 该属性是指定将Node包转换为ES2015模块
// main 和 browser 属性将使插件决定将那些文件应用到bundle中
main: true, // Default: true
browser: true // Default: false
}),
commonjs(),
eslint({
include: "src/**",
exclude: "node_modules/**",
throwOnWarning: true
}),
babel({
exclude: "node_modules/**"
})
],
external: ["leaflet"],
watch: {
include: "src/**",
exclude: "node_modules/**"
}
};
return baseConfig;
}
function TerserPlugin(minimizer) {
return terser({
ie8: true,
keep_fnames: !minimizer, // 是否保持原变量名
compress: {
warnings: false,
drop_console: false, // 删除所有的 `console` 语句,可以兼容ie浏览器
reduce_vars: false // 内嵌定义了但是只用到一次的变量
},
output: {
beautify: !minimizer, // 是否不进行压缩
comments: minimizer ? /Leaflet.CustomLayer.js|Derek Li/ : true // 是否保留注释
}
});
}
export default ((name, options) => {
const config = [];
for (let type in options) {
config.push(
typeof options[type] === "function" && options[type](name, type)
);
}
return config;
})("Leaflet.CustomLayer", {
[""](name, type) {
const config = Object.assign(getBaseConfig(), {
output: {
format: "umd",
name: "Leaflet.CustomLayer",
file: `dist/${name}.js`,
banner,
indent: true,
legacy: true, // Needed to create files loadable by IE8
sourcemap: true
}
});
config.plugins.push(TerserPlugin(false));
return config;
},
["min"](name, type) {
const config = Object.assign(getBaseConfig(), {
output: {
format: "umd",
name: "Leaflet.CustomLayer",
file: `dist/${name}.${type}.js`,
banner,
indent: true,
legacy: true, // Needed to create files loadable by IE8
sourcemap: true
}
});
config.plugins.push(TerserPlugin(true));
return config;
},
["es"](name, type) {
const config = Object.assign(getBaseConfig(), {
output: {
format: "es",
file: `dist/${name}.esm.js`,
banner,
indent: true,
legacy: true, // Needed to create files loadable by IE8
sourcemap: true
}
});
config.plugins.push(TerserPlugin(false));
return config;
}
});