-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
195 lines (180 loc) · 3.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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import fs from 'fs'
import path from 'path'
import { camelCase } from 'lodash'
import babel from '@rollup/plugin-babel'
import resolve from '@rollup/plugin-node-resolve'
import typescript2 from '@rollup/plugin-typescript'
import commonjs from '@rollup/plugin-commonjs'
import eslint from '@rollup/plugin-eslint'
import replace from '@rollup/plugin-replace'
import { terser } from 'rollup-plugin-terser'
const pkg = require('./package.json');
const base = path.resolve(__dirname, '.');
const src = path.resolve(base, 'src');
const dist = path.resolve(base, 'dist');
const date = new Date();
const bannerComment = `/*!
* Buession ${pkg.alias} ${pkg.version}
*
* @link ${pkg.homepage}
* @source ${pkg.repository.url}
* @copyright @ 2020-${date.getFullYear()} ${pkg.copyright}
* @license ${pkg.license}
* @Build Time ${date.toUTCString()}
*/
`
const filename = pkg.alias;
const externals = ['window'];
const plugins = [
eslint('./.eslintrc.js'),
resolve({
browser: true,
external: externals
}),
commonjs(),
typescript2({
tsconfig: './tsconfig.json'
}),
replace({
preventAssignment: true,
values: {
__NAME__: pkg.alias,
__VERSION__: pkg.version
}
}),
babel({
configFile: './babel.config.js',
babelHelpers: 'runtime',
exclude: 'node_modules/**'
})
];
// The base rollup configuration
const baseConfig = {
input: path.resolve(src, 'index.ts'),
external: externals,
plugins: plugins
};
const minifyConfig = {
...baseConfig,
plugins: [...plugins, terser()]
};
const outputConfig = {
name: camelCase(pkg.alias),
exports: 'named',
banner: bannerComment,
sourcemap: true
};
// Ensure dist directory exists
if (!fs.existsSync(dist)) {
fs.mkdirSync(dist);
}
export default [
// AMD Browser Build
{
...baseConfig,
output: {
...outputConfig,
format: 'amd',
file: path.resolve(dist, `${filename}.amd.js`)
}
},
// Minify AMD Browser Build
{
...minifyConfig,
output: {
...outputConfig,
format: 'amd',
file: path.resolve(dist, `${filename}.amd.min.js`)
}
},
// UMD Browser Build
{
...baseConfig,
output: {
...outputConfig,
format: 'umd',
file: path.resolve(dist, `${filename}.umd.js`)
}
},
// Minify UMD Browser Build
{
...minifyConfig,
output: {
...outputConfig,
format: 'umd',
file: path.resolve(dist, `${filename}.umd.min.js`)
}
},
// UMD Browser Build
{
...baseConfig,
output: {
...outputConfig,
format: 'umd',
file: path.resolve(dist, `${filename}.js`)
}
},
// Minify UMD Browser Build
{
...minifyConfig,
output: {
...outputConfig,
format: 'umd',
file: path.resolve(dist, `${filename}.min.js`)
}
},
// ESM Module Bundle Build
{
...baseConfig,
output: {
...outputConfig,
format: 'esm',
file: path.resolve(dist, `${filename}.esm.js`)
}
},
// Minify ESM Module Bundle Build
{
...minifyConfig,
output: {
...outputConfig,
format: 'esm',
file: path.resolve(dist, `${filename}.esm.min.js`)
}
},
// IIFE Browser Build
{
...baseConfig,
output: {
...outputConfig,
format: 'iife',
file: path.resolve(dist, `${filename}.iife.js`)
}
},
// Minify IIFE Browser Build
{
...minifyConfig,
output: {
...outputConfig,
format: 'iife',
file: path.resolve(dist, `${filename}.iife.min.js`)
}
},
// COMMONJS Module Build
{
...baseConfig,
output: {
...outputConfig,
format: 'cjs',
file: path.resolve(dist, `${filename}.cjs.js`)
}
},
// Minify COMMONJS Module Bundle Build
{
...minifyConfig,
output: {
...outputConfig,
format: 'cjs',
file: path.resolve(dist, `${filename}.cjs.min.js`)
}
}
]