This repository has been archived by the owner on Nov 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
111 lines (99 loc) · 2.43 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
import { join, dirname, extname, basename } from 'path'
import nodeResolver from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import replace from '@rollup/plugin-replace'
import json from '@rollup/plugin-json'
import clear from 'rollup-plugin-clear'
import progress from 'rollup-plugin-progress'
import typescript from 'rollup-plugin-typescript2'
import externals from 'rollup-plugin-node-externals'
import { terser } from 'rollup-plugin-terser'
import filesize from 'rollup-plugin-filesize'
import visualizer from 'rollup-plugin-visualizer'
import toUpper from 'lodash/toUpper'
import snakeCase from 'lodash/snakeCase'
import pkg from './package.json'
const isProd = process.env.NODE_ENV === 'production'
const analyse = process.env.npm_config_analyse
const banner = `/**
* ${pkg.name} v${pkg.version}
*
* (c) ${new Date().getFullYear()} ${pkg.author.name}
*
* @author ${pkg.author.name}
* @license ${pkg.license}
*/`
const config = {
input: './src/index.ts',
output: [
{
banner,
file: pkg.main,
format: 'cjs',
sourcemap: true,
exports: 'named'
}
],
external(resolveId) {
return /^lodash/.test(resolveId)
},
plugins: [
clear({
targets: ['dist', 'tsconfig.tsbuildinfo']
}),
progress({
clearLine: false
}),
replace({
__VERSION__: pkg.version,
NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development')
}),
externals({
exclude: [/^lodash?/]
}),
nodeResolver(),
commonjs(),
typescript(),
json()
],
watch: {
include: 'src/**',
exclude: 'node_modules/**'
}
}
if (analyse) {
config.plugins.push(
visualizer({
title: `${pkg.name} - ${pkg.author.name}`,
filename: join(__dirname, 'dist/bundle-analyzer-report.html')
})
)
} else {
const pkgName = pkg.name
const umdOutputConfig = {
banner,
format: 'umd',
name: toUpper(snakeCase(basename(pkgName))),
sourcemap: true,
exports: 'named'
}
const outputFile = pkg.browser
const ext = extname(outputFile)
config.output.push({
file: join(dirname(outputFile), `${basename(outputFile, ext)}.min${ext}`),
plugins: [terser(), isProd && filesize()],
...umdOutputConfig
})
config.output.push({
file: outputFile,
...umdOutputConfig
})
config.output.push({
banner,
file: pkg.module,
format: 'esm',
sourcemap: true,
exports: 'named'
})
}
export default config