forked from clouDr-f2e/monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
121 lines (118 loc) · 3.25 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import json from '@rollup/plugin-json'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import typescript from 'rollup-plugin-typescript2'
import { terser } from 'rollup-plugin-terser'
import clear from 'rollup-plugin-clear'
import cleanup from 'rollup-plugin-cleanup'
import size from 'rollup-plugin-sizes'
import { visualizer } from 'rollup-plugin-visualizer'
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path')
if (!process.env.TARGET) {
throw new Error('TARGET package must be specified')
}
// 是否生成声明文件
const isDeclaration = process.env.TYPES !== 'false'
// eslint-disable-next-line @typescript-eslint/no-var-requires
const masterVersion = require('./package.json').version
const packagesDir = path.resolve(__dirname, 'packages')
const packageDir = path.resolve(packagesDir, process.env.TARGET)
const packageDirDist = process.env.LOCALDIR === 'undefined' ? `${packageDir}/dist` : process.env.LOCALDIR
const name = path.basename(packageDir)
// const pathResolve = (p) => path.resolve(packageDir, p)
const M = '@mitojs'
const paths = {
'@mitojs/utils': [`${packagesDir}/utils/src`],
'@mitojs/core': [`${packagesDir}/core/src`],
'@mitojs/types': [`${packagesDir}/types/src`],
'@mitojs/shared': [`${packagesDir}/shared/src`],
'@mitojs/browser': [`${packagesDir}/browser/src`],
'@mitojs/react': [`${packagesDir}/react/src`],
'@mitojs/vue': [`${packagesDir}/vue/src`],
'@mitojs/wx-mini': [`${packagesDir}/wx-mini/src`]
}
const common = {
input: `${packageDir}/src/index.ts`,
output: {
banner: `/* ${M}/${name} version ' + ${masterVersion} */`,
footer: '/* follow me on Github! @cjinhuo */'
},
external: [...Object.keys(paths)],
plugins: [
resolve(),
size(),
visualizer({
title: `${M} analyzer`,
filename: 'analyzer.html'
}),
commonjs({
exclude: 'node_modules'
}),
json(),
cleanup({
comments: 'none'
}),
typescript({
tsconfig: 'tsconfig.build.json',
useTsconfigDeclarationDir: true,
tsconfigOverride: {
compilerOptions: {
declaration: isDeclaration,
declarationMap: isDeclaration,
declarationDir: `${packageDirDist}/packages/`, // 类型声明文件的输出目录
module: 'ES2015',
paths
}
},
include: ['*.ts+(|x)', '**/*.ts+(|x)', '../**/*.ts+(|x)']
})
]
}
const esmPackage = {
...common,
output: {
file: `${packageDirDist}/${name}.esm.js`,
format: 'es',
name: 'MITO',
sourcemap: true,
...common.output
},
plugins: [
...common.plugins,
clear({
targets: [packageDirDist]
})
]
}
const cjsPackage = {
...common,
external: [],
output: {
file: `${packageDirDist}/${name}.js`,
format: 'cjs',
name: 'MITO',
sourcemap: true,
minifyInternalExports: true,
...common.output
},
plugins: [...common.plugins]
}
const iifePackage = {
...common,
external: [],
output: {
file: `${packageDirDist}/${name}.min.js`,
format: 'iife',
name: 'MITO',
...common.output
},
plugins: [...common.plugins, terser()]
}
const total = {
esmPackage,
iifePackage,
cjsPackage
}
let result = total
export default [...Object.values(result)]