-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrollup.config.js
86 lines (80 loc) · 2.01 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
import path from 'path'
import babelPlugin from '@rollup/plugin-babel'
import esbuild from 'rollup-plugin-esbuild'
import resolve from '@rollup/plugin-node-resolve'
import { defineConfig } from 'rollup'
import { terser } from 'rollup-plugin-terser'
import pkg from './package.json'
import commonjs from '@rollup/plugin-commonjs'
const extensions = ['.js', '.ts']
const { root } = path.parse(process.cwd())
const terserPlugin = [
terser({
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
warnings: false,
},
format: {
comments: RegExp(`${pkg.name}`),
},
}),
]
function external(id) {
return !id.startsWith('.') && !id.startsWith(root)
}
function createCommonJSConfig(input, output) {
return defineConfig({
input,
output: { file: output, format: 'cjs', exports: 'named' },
external,
plugins: [
resolve({ extensions }),
babelPlugin({ babelHelpers: 'runtime', extensions, comments: false }),
...terserPlugin,
],
})
}
function createESMConfig(input, output) {
return defineConfig({
input,
output: { file: output, format: 'esm' },
external,
plugins: [
resolve({ extensions }),
esbuild({
minify: false,
target: 'node12',
tsconfig: path.resolve('./tsconfig.json'),
}),
...terserPlugin,
],
})
}
function createUMDJSConfig(input, output) {
return defineConfig({
input,
output: { file: output, format: 'umd', name: 'BQueue' },
plugins: [
resolve({ extensions }),
babelPlugin({
extensions,
babelHelpers: 'runtime',
comments: false,
plugins: ['@babel/plugin-transform-runtime', '@babel/plugin-transform-typescript'],
}),
commonjs({
extensions,
}),
...terserPlugin,
],
})
}
export default function () {
return [
createCommonJSConfig('src/index.ts', 'lib/index.js'),
createESMConfig('src/index.ts', 'es/index.js'),
createUMDJSConfig('src/index.ts', 'dist/best-queue.js'),
]
}