-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
90 lines (85 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
82
83
84
85
86
87
88
89
90
import path from 'node:path';
import chalk from 'chalk';
import json from '@rollup/plugin-json';
import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import { babel } from '@rollup/plugin-babel';
import { name, version, author } from './package.json';
import fs from 'node:fs';
const resolve = (p) => path.resolve(__dirname, p);
function getLicense() {
const license = fs.readFileSync(path.resolve(__dirname, './LICENSE'), { encoding: 'utf-8' });
const content = `${name} \n@version ${version}\n@author ${author}\n\n${license}`;
return `/*!\n * ${content.replace(/\*\//g, '* /').split('\n').join('\n * ')}\n */`;
}
const outputConfigs = {
esm: {
file: resolve(`dist/${name}.esm.js`),
format: 'es',
},
cjs: {
file: resolve(`dist/${name}.cjs.js`),
format: 'cjs',
},
umd: {
file: resolve(`dist/${name}.js`),
format: 'umd',
},
mumd: {
file: resolve(`dist/${name}.min.js`),
format: 'umd',
},
};
console.log(chalk.bgCyan(`🚩 Building ${version} ... `));
const packageConfigs = Object.keys(outputConfigs).reduce(
(prev, format) => {
const output = {
...outputConfigs[format],
externalLiveBindings: false,
interop: 'esModule',
globals: {
echarts: 'echarts',
},
validate: true,
banner: getLicense(),
};
const plugins = [
json(),
nodeResolve(),
commonjs(),
babel({
babelHelpers: 'bundled',
}),
];
if (output.format === 'umd') {
output.name = 'echarts.bingmap';
output.sourcemap = true;
}
if (format === 'mumd') {
plugins.push(
terser({
module: /^esm/.test(format),
compress: {
ecma: 2015,
pure_getters: true,
pure_funcs: ['console.log'],
},
safari10: true,
ie8: false,
}),
);
}
return prev.concat({
input: resolve('index.js'),
external: ['echarts'],
plugins: [...plugins],
output,
treeshake: {
moduleSideEffects: false,
},
});
},
[],
);
export default packageConfigs;