-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
93 lines (86 loc) · 2.36 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
/* eslint-disable @typescript-eslint/no-var-requires,global-require */
import resolve from '@rollup/plugin-node-resolve'
import multiInput from 'rollup-plugin-multi-input'
import del from 'rollup-plugin-delete'
import typescript from '@rollup/plugin-typescript'
import alias from '@rollup/plugin-alias'
import replace from '@rollup/plugin-replace'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import path from 'path'
import pkg from './package.json'
const dev = !!process.env.ROLLUP_WATCH
const onwarnRollup = (warning, onwarn) => {
// prevent warn: (!) `this` has been rewritten to `undefined`
// if ( warning.code === 'THIS_IS_UNDEFINED' ) {
// return false
// }
// if ( warning.code === 'EVAL' ) {
// return false
// }
// if ( warning.code === 'SOURCEMAP_ERROR' ) {
// return false
// }
// if ( warning.plugin === 'typescript' && /Rollup 'sourcemap' option must be set to generate source maps/.test(warning.message)) {
// return false
// }
console.warn('onwarnRollup',
[
`${warning.code}: ${warning.message}`,
warning.loc && `${warning.loc.file}:${warning.loc.line}:${warning.loc.column}`,
warning.plugin && `plugin: ${warning.plugin}`,
warning.pluginCode && `pluginCode: ${warning.pluginCode}`,
warning.hook && `hook: ${warning.hook}`,
warning.frame,
]
.map(o => o?.toString()?.trim())
.filter(o => o)
.join('\r\n') + '\r\n',
)
return false
}
const aliasOptions = {
entries: [
{
find : 'src',
replacement: path.resolve(__dirname, 'src'),
},
],
}
const nodeConfig = {
cache: true,
input: [
'src/**/*.ts',
],
output: {
dir : 'dist',
format : 'cjs',
exports : 'named',
entryFileNames: '[name].cjs',
chunkFileNames: '[name].cjs',
sourcemap : dev,
},
plugins: [
del({ targets: 'dist/*' }),
multiInput(),
alias(aliasOptions),
json(),
replace({
preventAssignment: true,
}),
resolve(),
commonjs({
transformMixedEsModules: true,
}),
typescript({
sourceMap: dev,
}),
],
onwarn : onwarnRollup,
external: Object.keys(pkg.dependencies)
.concat(Object.keys(pkg.devDependencies))
.concat(require('module').builtinModules || Object.keys(process.binding('natives'))),
}
export default [
nodeConfig,
]