-
Notifications
You must be signed in to change notification settings - Fork 128
/
rollup.config.base.js
79 lines (72 loc) · 1.8 KB
/
rollup.config.base.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
import path from 'path';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import terser from '@rollup/plugin-terser';
import size from 'rollup-plugin-sizes';
import esbuild from 'rollup-plugin-esbuild';
import nodePolyfills from 'rollup-plugin-polyfill-node';
import { dts } from 'rollup-plugin-dts';
const packageDir = path.resolve(__dirname);
const packageDirDist = `${packageDir}/dist`;
const name = path.basename(packageDir);
export const common = {
input: `${packageDir}/src/index.ts`,
output: {
name: `HEIMDALLR_${name.toLocaleUpperCase()}`,
footer: '/* follow me on Github! @LuciferHuang */',
sourcemap: process.env.NODE_ENV !== 'production'
},
plugins: [
esbuild({
include: /\.[jt]sx?$/,
exclude: /node_modules/,
target: 'es2015',
jsx: 'transform',
jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment',
tsconfig: 'tsconfig.json',
loaders: {
'.json': 'json',
'.js': 'jsx'
}
}),
resolve({
preferBuiltins: true
}), // 解析导入的第三方模块
commonjs(), // 将CommonJS模块转换为ESM
nodePolyfills(),
json(),
terser(),
size()
]
};
export const declaration = {
input: common.input,
output: [{ file: 'esm/index.d.ts', format: 'es' }],
plugins: [dts()]
};
export const umdPackage = {
...common,
output: {
file: `${packageDirDist}/${name}.umd.js`,
format: 'umd',
...common.output
}
};
export const esmPackage = {
...common,
output: {
dir: `${packageDir}/esm`,
format: 'esm'
}
};
export const iifePackage = {
...common,
output: {
file: `${packageDirDist}/${name}.iife.js`,
format: 'iife',
...common.output
},
context: 'window'
};