-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.js
68 lines (59 loc) · 1.48 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
import path from 'path'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import ts from 'rollup-plugin-typescript2'
import { terser } from 'rollup-plugin-terser'
import replace from '@rollup/plugin-replace'
require('dotenv').config()
const name = 'ohbug-miniapp'
const packageFormats = ['esm', 'cjs']
const configs = {
esm: {
format: `es`,
},
cjs: {
format: `cjs`,
},
}
const tsPlugin = ts({
check: process.env.NODE_ENV === 'production',
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
})
const extensions = ['.js', '.ts']
const commonjsOptions = {
ignoreGlobal: true,
include: /node_modules/,
}
const pkg = require(path.resolve(`./package.json`))
function createConfig(isProduction = false) {
const input = path.resolve(__dirname, 'src/index.ts')
const output = packageFormats.map((format) => {
const target = {
file: path.resolve(
`dist/${name}.${format}${isProduction ? '.prod' : ''}.js`
),
format: configs[format].format,
}
return target
})
const plugins = [
replace({
__VERSION__: pkg.version,
}),
commonjs(commonjsOptions),
tsPlugin,
resolve({ extensions }),
]
if (isProduction) {
plugins.push(terser())
}
return {
input,
output,
plugins,
}
}
const NODE_ENV = process.env.NODE_ENV
const packageConfigs = [createConfig()]
if (NODE_ENV === 'production') packageConfigs.push(createConfig(true))
export default packageConfigs