generated from MShineRay/template-jslib-rollup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
123 lines (122 loc) · 3.39 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
/**
* @reference https://www.rollupjs.com/guide/introduction/
*/
import commonjs from '@rollup/plugin-commonjs'// 用来将 CommonJS 转换成 ES2015 模块的
import json from '@rollup/plugin-json'
import resolve from '@rollup/plugin-node-resolve'// 告诉 Rollup 如何查找外部模块
import babel from '@rollup/plugin-babel'
import {uglify} from 'rollup-plugin-uglify'
import {packageName, version, author} from './package.json'
const name = packageName
const banner = `/*!
* ${name} v${version}
* (c) ${new Date().getFullYear()} ${author}
* @license MIT
*/`
export default {
input: 'src/index.js',
output: [
{
banner,
file: `dist/${name}.amd.js`,
format: 'amd', // 浏览器
},
{
file: `dist/${name}.cjs.js`,
format: 'cjs', // compile to a CommonJS module ('cjs') node环境
name
},
{
file: `dist/${name}.esm.js`,
format: 'esm', // 浏览器
name
},
{
file: `dist/${name}.iife.js`,
format: 'iife', // 浏览器
name
},
{
file: `dist/${name}.umd.js`,
format: 'umd', // UMD format requires a bundle name 浏览器和 Node.js
name
},
// min
{
file: `dist/${name}.amd.min.js`,
format: 'amd', // 浏览器
name,
plugins: [uglify()]
},
{
file: `dist/${name}.cjs.min.js`,
format: 'cjs', // compile to a CommonJS module ('cjs') node环境
name,
plugins: [uglify()]
},
{
file: `dist/${name}.esm.min.js`,
format: 'esm', // 浏览器
name,
plugins: [uglify()]
},
{
file: `dist/${name}.iife.min.js`,
format: 'iife', // 浏览器
name,
plugins: [uglify({
output:{
comments: function (node, comment){
//以!开头部分的注视进行保留
return /^!/.test(comment.value)
}
}
})]
},
{
file: `dist/${name}.umd.min.js`,
format: 'umd', // UMD format requires a bundle name 浏览器和 Node.js
name,
plugins: [uglify({
output:{
preamble: '/** \r\r 版本所有 \r\n 填写日期 \r\n 填写作者信息 */'
}
})]
}
],
plugins: [
commonjs(),
json(),
resolve({
// 将自定义选项传递给解析插件
customResolveOptions: {
moduleDirectory: 'node_modules'
}
}),
babel({
// 为避免编译三方脚本,通过设置exclude属性忽略node_modules目录。
// babelHelpers:'bundled',
exclude: ['node_modules/**', 'dist/**', 'test/**'], // 只编译我们的源代码
include: ['src/**']
}),
// default
// ["lodash"],
// Set plugin options using an array of [pluginName, optionsObject].
// ["lodash", { "id": "lodash-compat", "cwd": "some/path" }]
// The options.id can be an array of ids.
['lodash', {id: ['async', 'lodash-bound']}],
// uglify() //只生产压缩的库
],
// 指出应将哪些模块视为外部模块:
// 你可以微调哪些导入是想要打包的,哪些是外部的引用(externals)。
// 对于这个例子,我们认为 lodash 是外部的引用(externals),而不是 the-answer 。
external: ['lodash'],
watch: {
// 限制文件监控至某些文件:
include: 'src/**',
// 防止文件被监控:
exclude: 'node_modules/**'
},
// treeshake: true,
presets: [['@babel/env', {targets: {node: 6}}]]
}