forked from pandaoh/js-xxx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
89 lines (85 loc) · 2.31 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
/*
* @Author: HxB
* @Date: 2022-04-26 11:33:01
* @LastEditors: DoubleAm
* @LastEditTime: 2023-03-20 13:53:58
* @Description: rollup 配置文件
* @FilePath: \js-xxx\rollup.config.js
*/
import path from 'path';
import terser from '@rollup/plugin-terser';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from 'rollup-plugin-typescript2';
import alias from '@rollup/plugin-alias';
import eslint from '@rollup/plugin-eslint';
import clear from 'rollup-plugin-clear';
import pkg from './package.json';
const getPath = (_path) => path.resolve(__dirname, _path);
const extensions = ['.js', '.jsx', '.ts', '.tsx'];
/** @type {import('rollup').RollupOptions} */
const options = {
input: getPath('src/index.ts'),
output: [
{
file: getPath(pkg.iife),
format: 'iife', // iife 支持 自执行函数,可通过 `<script>` 标签加载。
name: '$xxx',
plugins: [terser()],
},
{
file: getPath(pkg.main),
format: 'cjs', // lib 兼容 CommonJS Node 默认的模块规范,可通过 Webpack 加载。
name: '$xxx',
plugins: [terser()],
},
{
file: getPath(pkg.module),
format: 'es', // es es6模块 ES module 规范,可用 Webpack、Rollup 加载。
name: '$xxx',
plugins: [terser()],
},
{
file: getPath(pkg.unpkg),
format: 'umd', // dist 通用模块 IIFE,AMD[`amd`: 浏览器端的模块规范-可通过 RequireJS 可加载],CJS。
name: '$xxx',
plugins: [terser()],
},
{
file: getPath(pkg['iife-source']),
name: '$xxx',
format: 'iife', // iife
},
{
file: getPath(pkg['main-source']),
name: '$xxx',
format: 'cjs', // lib
},
{
file: getPath(pkg['module-source']),
name: '$xxx',
format: 'es', // es
},
{
file: getPath(pkg['unpkg-source']),
name: '$xxx',
format: 'umd', // dist
},
],
plugins: [
resolve(extensions),
commonjs(),
eslint({
fix: true,
}),
clear({
targets: ['dist', 'es', 'lib', 'iife', 'docs', 'html'],
watch: true,
}),
typescript({ tsconfig: getPath('tsconfig.json'), extensions }),
alias({
entries: [{ find: '@', replacement: getPath('src') }],
}),
],
};
export default options;