forked from LuciferHuang/heimdallr-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.base.config.js
78 lines (72 loc) · 1.67 KB
/
rollup.base.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
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';
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 */'
},
plugins: [
esbuild({
include: /\.[jt]sx?$/,
exclude: /node_modules/,
minify: process.env.NODE_ENV === 'production',
target: 'es2015',
jsx: 'transform',
jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment',
tsconfig: 'tsconfig.json',
loaders: {
'.json': 'json',
'.js': 'jsx'
}
}),
resolve({
preferBuiltins: true
}),
commonjs(),
nodePolyfills(),
json(),
size()
]
};
export const umdPackage = {
...common,
output: {
file: `${packageDirDist}/${name}.umd.js`,
format: 'umd',
...common.output
}
};
export const esmPackage = {
...common,
output: {
dir: packageDirDist,
format: 'esm',
plugins: [terser()],
...common.output
}
};
export const iifePackage = {
...common,
output: {
file: `${packageDirDist}/${name}.iife.js`,
format: 'iife',
...common.output
},
context: 'window',
plugins: [
...common.plugins,
// 压缩代码
terser()
]
};