-
Notifications
You must be signed in to change notification settings - Fork 8
/
rollup.config.js
91 lines (80 loc) · 1.98 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
// @ts-check
import json from 'rollup-plugin-json'
import babel from 'rollup-plugin-babel'
import replace from 'rollup-plugin-replace'
import { eslint } from 'rollup-plugin-eslint'
import { terser } from 'rollup-plugin-terser'
import { DEFAULT_EXTENSIONS } from '@babel/core'
const pkg = require('./package.json')
const banner =
`/**
* ${pkg.name} v${pkg.version}
* (c) ${new Date().getFullYear()} ${pkg.author}
* @license ${pkg.license}
*/
`
const extensions = [...DEFAULT_EXTENSIONS, 'ts', 'tsx']
const configMap = {
cjs: {
file: pkg.main,
format: 'cjs',
exports: 'named',
},
esm: {
file: pkg.module,
format: 'esm',
},
umdDev: {
file: pkg.main,
format: 'umd',
env: 'development',
},
umdProd: {
file: `dist/tua-storage.umd.min.js`,
format: 'umd',
env: 'production',
},
esmBrowserDev: {
env: 'development',
file: 'dist/tua-storage.esm.browser.js',
format: 'esm',
},
esmBrowserProd: {
env: 'production',
file: 'dist/tua-storage.esm.browser.min.js',
format: 'esm',
},
}
const genConfig = (opts) => {
const isProd = /min\.js$/.test(opts.file)
const config = {
input: 'src/index.js',
plugins: [eslint({ include: '**/*.js' }), json()],
output: {
file: opts.file,
name: 'TuaStorage',
banner,
format: opts.format,
},
}
if (opts.env) {
config.plugins.push(replace({
'process.env.NODE_ENV': JSON.stringify(opts.env),
}))
}
if (opts.transpile !== false) {
config.plugins.push(babel({ extensions }))
}
if (isProd) {
config.plugins.push(terser({
output: {
/* eslint-disable */
ascii_only: true,
},
}))
}
return config
}
export default Object.keys(configMap)
.map(key => configMap[key])
.map(genConfig)