forked from jeffijoe/awilix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
114 lines (109 loc) · 2.76 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
112
113
114
import typescript from 'rollup-plugin-typescript2'
import replace from 'rollup-plugin-replace'
import commonjs from 'rollup-plugin-commonjs'
import resolve from 'rollup-plugin-node-resolve'
import copy from 'rollup-plugin-copy'
const comment = '/* removed in browser build */'
const ignoredWarnings = ['UNUSED_EXTERNAL_IMPORT']
const tsOpts = {
cacheRoot: './node_modules/.rpt2',
typescript: require('typescript'),
tsconfig: 'tsconfig.build.json',
tsconfigOverride: {
compilerOptions: {
// Don't emit declarations, that's done by the regular build.
declaration: false,
module: 'ESNext',
},
},
}
export default [
// Build 1: ES6 modules for Node.
{
input: 'src/awilix.ts',
external: [
'glob',
'path',
'url',
'util',
'camel-case',
'./load-module-native.js',
],
treeshake: { moduleSideEffects: 'no-external' },
onwarn,
output: [
{
file: 'lib/awilix.module.js',
format: 'es',
},
],
plugins: [
// Copy the native module loader
copy({
targets: [{ src: 'src/load-module-native.js', dest: 'lib' }],
}),
typescript(tsOpts),
],
},
// Build 2: ES modules for browser builds.
{
input: 'src/awilix.ts',
external: ['glob', 'path', 'util'],
treeshake: { moduleSideEffects: 'no-external' },
onwarn,
output: [
{
name: 'Awilix',
file: 'lib/awilix.browser.js',
format: 'es',
},
{
name: 'Awilix',
file: 'lib/awilix.umd.js',
format: 'umd',
},
],
plugins: [
// Removes stuff that won't work in the browser
// which also means node-only stuff like `path`, `util` and `glob`
// will be shaken off.
replace({
'loadModules,':
'loadModules: () => { throw new Error("loadModules is not supported in the browser.") },',
'[util.inspect.custom]: inspect,': comment,
'[util.inspect.custom]: inspectCradle,': comment,
'case util.inspect.custom:': '',
"import { camelCase } from 'camel-case'":
'const camelCase = null as any',
"export * from './list-modules'": comment,
"import * as util from 'util'": '',
delimiters: ['', ''],
}),
typescript(
Object.assign({}, tsOpts, {
tsconfigOverride: {
compilerOptions: {
target: 'es5',
declaration: false,
noUnusedLocals: false,
module: 'ESNext',
},
},
})
),
resolve({
preferBuiltins: true,
}),
commonjs(),
],
},
]
/**
* Ignores certain warnings.
*/
function onwarn(warning, next) {
if (ignoredWarnings.includes(warning.code)) {
return
}
next(warning)
}