-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
83 lines (74 loc) · 1.91 KB
/
rollup.config.js
File metadata and controls
83 lines (74 loc) · 1.91 KB
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
import fs from 'fs'
import path from 'path'
import typescript from '@rollup/plugin-typescript'
import replace from '@rollup/plugin-replace'
import terser from '@rollup/plugin-terser'
import babel from '@rollup/plugin-babel'
import pkg from './package.json'
const NODE_ENV = process.env.NODE_ENV
const APP_FILENAME = 'index'
const APP_SRC_DIRNAME = 'src'
const APP_BUILD_DIRNAME = 'dist'
const APP_BUILD_FILENAME = 'object-parser'
const APP_BUILD_UMD_NAME = 'objectParser'
const input = path.join(APP_SRC_DIRNAME, `${APP_FILENAME}.ts`)
const output = path.join(APP_BUILD_DIRNAME, `${APP_BUILD_FILENAME}`)
const splitedVersion = pkg.version.split('.')
if (fs.existsSync(APP_BUILD_DIRNAME)) {
fs.rmSync(APP_BUILD_DIRNAME, { recursive: true, force: true })
}
const rollupConfig = {
input,
output: [
{
file: `${output}.js`,
format: 'umd',
exports: 'named',
name: APP_BUILD_UMD_NAME,
},
],
plugins: [
typescript(),
replace({
preventAssignment: true,
'process.env.VERSION_MAJOR': splitedVersion[0],
'process.env.VERSION_MINOR': splitedVersion[1],
'process.env.VERSION_PATCH': splitedVersion[2],
}),
],
}
if (NODE_ENV === 'production') {
const removeComments = terser({
compress: false,
mangle: false,
format: {
beautify: true,
comments: false,
},
})
rollupConfig.output[0].plugins = [removeComments]
rollupConfig.output.push(
...[
{
file: `${output}.esm.js`,
format: 'esm',
exports: 'named',
plugins: [removeComments],
},
{
file: `${output}.min.js`,
format: 'umd',
exports: 'named',
name: APP_BUILD_UMD_NAME,
plugins: [terser({ compress: { unsafe_arrows: true, passes: 2 } })],
},
]
)
rollupConfig.plugins.push(
babel({
babelHelpers: 'bundled',
exclude: 'node_modules/**',
})
)
}
export default rollupConfig