-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrollup.config.js
69 lines (62 loc) · 1.8 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
/** @format */
import path from 'path'
import resolve from '@rollup/plugin-node-resolve' // 依赖引用插件
import commonjs from '@rollup/plugin-commonjs' // commonjs模块转换插件
import tslint from 'rollup-plugin-tslint'
import ts from 'rollup-plugin-typescript2'
import {terser} from 'rollup-plugin-terser'
import typescript from 'typescript'
import babel from 'rollup-plugin-babel'
import builtins from 'rollup-plugin-node-builtins'
import globals from 'rollup-plugin-node-globals'
const getPath = _path => path.resolve(__dirname, _path)
import packageJSON from './package.json'
const isDev = process.env.NODE_ENV !== 'production'
console.log('isDev', isDev)
const extensions = ['.js', '.tsx']
// ts
const tsPlugin = tslint({
tsconfig: getPath('./tsconfig.json'), // 导入本地ts配置
include: ['tsx'],
})
// 基础配置
const commonConf = {
input: getPath('./src/web.tsx'),
plugins: [
globals(),
builtins(),
commonjs(),
resolve(extensions),
tsPlugin,
ts({
include: 'src/**/*.tsx',
exclude: 'node_modules/**',
typescript: typescript,
tsconfig: 'tsconfig.json',
}),
babel({
exclude: 'node_modules/**',
}),
!isDev && terser(),
],
}
// 需要导出的模块类型
const outputMap = [
{
file: packageJSON.main, // 通用模块
format: 'umd',
name: 'uploader',
},
{
file: packageJSON.module, // es6模块
format: 'es',
name: 'uploader',
},
{
file: packageJSON.cjs, // cjs
format: 'cjs',
name: 'uploader',
},
]
const buildConf = options => Object.assign({}, commonConf, options)
export default outputMap.map(output => buildConf({output: {name: packageJSON.name, ...output}}))