-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.build.js
More file actions
108 lines (97 loc) · 2.31 KB
/
rollup.build.js
File metadata and controls
108 lines (97 loc) · 2.31 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
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
const rollup = require('rollup');
const babel = require('rollup-plugin-babel');
const json = require('rollup-plugin-json');
const resolve = require('rollup-plugin-node-resolve');
const { uglify } = require('rollup-plugin-uglify');
const path = require('path');
const defaultPlugins = [
resolve({
browser: true
}),
babel({
exclude: 'node_modules/**'
// externalHelpers: true
}),
json({
// All JSON files will be parsed by default,
// but you can also specifically include/exclude files
exclude: ['node_modules/**'],
// include: ["src/**"],
// ignores indent and generates the smallest code
compact: true // Default: false
})
];
const inputOptions = {
input: './src/core/zel.js',
plugins: defaultPlugins
};
const outputOptions = {
file: path.resolve(__dirname, 'bundle/zel.js'),
format: 'iife',
name: 'ZEL',
};
const options = [
// standard output
{ input: inputOptions, output: outputOptions },
// ESM output (module)
{
input: {
...inputOptions,
plugins: [
...defaultPlugins,
resolve({
mainFields: ["module", "main"],
browser: true,
extensions: ['.js', '.json'],
jail: '/src/',
modulesOnly: true
}),
babel({
exclude: 'node_modules/**'
})
]
},
output: {
...outputOptions,
format: 'esm',
file: path.resolve(__dirname, 'bundle/zel.esm.js')
}
},
// CJS output
{
input: inputOptions,
output: {
...outputOptions,
format: 'cjs',
file: path.resolve(__dirname, 'bundle/zel.cjs.js')
}
},
// UMD output (main)
{
input: inputOptions,
output: {
...outputOptions,
format: 'umd',
file: path.resolve(__dirname, 'bundle/zel.umd.js')
}
},
// uglified output
{
input: { ...inputOptions, plugins: [...defaultPlugins, uglify({})] },
output: {
...outputOptions,
file: path.resolve(__dirname, 'bundle/zel.min.js')
}
}
];
// Regular bundle
async function build(_inputOptions, _outputOptions) {
// create a bundle
const bundle = await rollup.rollup(_inputOptions);
// or write the bundle to disk
await bundle.write(_outputOptions);
}
for (const key in options) {
const value = options[key];
build(value.input, value.output).then(console.log);
}