-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrollup.config.js
71 lines (67 loc) · 2.01 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
// @ts-nocheck
import { babel } from '@rollup/plugin-babel';
import { terser } from 'rollup-plugin-terser';
import * as packageJson from './package.json';
import alias from '@rollup/plugin-alias';
import commonjs from '@rollup/plugin-commonjs';
import filesize from 'rollup-plugin-filesize';
import path from 'path';
import replace from '@rollup/plugin-replace';
import resolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
const processENV = process.argv[process.argv.length - 1]
.split('-')
.filter((o) => o);
// 获取优先的格式名(优先的格式名为默认gdp.js,非优先的为gdp.格式.js)
const formatPriority = processENV[0];
// 获取是否打包全量插件
const packageFull = processENV[1] === 'full';
// 控制台打印当前打包的环境
console.log(
`Packaging Format ${formatPriority === 'es' ? 'esm' : 'umd'
}; Package ${packageFull ? 'Full' : 'Base'}`
);
const configGenerat = (format) => ({
input: 'src/index.ts',
output: {
file: `dist/gdp${packageFull ? '-full' : ''}.${format === formatPriority ? '' : format + '.'}js`,
format,
name: 'gdp'
},
plugins: [
replace({
__SDK_VERSION__: packageJson.version || '0.0.1',
__GIO_PLUGIN_ENTRY__: `./plugins/plugins${packageFull ? '.full' : ''}.ts`
}),
alias({
entries: {
'@': path.resolve(__dirname, 'src')
}
}),
resolve(),
commonjs({ extensions: ['.js', '.ts'] }),
typescript({ compilerOptions: { target: 'es5' } }),
babel({
babelHelpers: 'bundled',
exclude: 'node_modules/**',
extensions: ['.ts', '.js', '.json']
}),
terser({
ecma: 'es5',
format: { comments: false },
compress: {
passes: 2,
unsafe: true,
unsafe_comps: true,
unsafe_proto: true,
unsafe_undefined: true
}
}),
filesize({
showMinifiedSize: false,
showGzippedSize: false
})
]
});
const config = ['es', 'umd'].map((o) => configGenerat(o));
export default config;