-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
84 lines (82 loc) · 1.85 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
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { babel } from '@rollup/plugin-babel';
import { terser } from 'rollup-plugin-terser';
import glob from 'glob';
import json from '@rollup/plugin-json';
import pkg from './package.json';
const comments = `/**
* name: ${pkg.name}
* version ${pkg.version}
* description: ${pkg.description}
* author: ${pkg.author}
* website: https://ecitlm.github.io/JB-Utils/index.html
* Date: ${new Date().toLocaleDateString()}
**/
`;
/**
* 插件
*
* @type {Plugin[]}
*/
const plugins = [
babel({
exclude: 'node_modules/**',
babelHelpers: 'runtime'
}),
json(),
resolve(), // 查找和打包node_modules中的第三方模块
commonjs(), // 将 CommonJS 转换成 ES2015 模块供 Rollup 处理
terser({
compress: {
pure_funcs: ['console.log']
},
output: {
preamble: comments
}
})
];
/**
* 动态JS获取
* @param path
* @returns {[]}
*/
function getEntriesJs(path) {
let entryList = [];
glob.sync(path).forEach(entry => {
let fileName = entry.replace(/(.*\/)*([^.]+).*/gi, '$2');
entryList.push({
input: entry,
output: {
file: `dist/lib/${fileName}.js`,
format: 'umd',
name: fileName
},
plugins
});
});
return entryList;
}
const entryJS = getEntriesJs('src/methods/*.js');
export default [
{
input: './src/index.js',
output: [
{
file: pkg.browser,
format: 'umd', // umd是兼容amd/cjs/iife的通用打包格式,适合浏览器
name: 'webUtils' // 当format为iife和umd时必须提供,将作为全局变量挂在window(浏览器环境)下:window.webUtils
},
{
file: pkg.main,
format: 'cjs'
},
{
file: pkg.module,
format: 'esm'
}
],
plugins
},
...entryJS
];