-
Notifications
You must be signed in to change notification settings - Fork 45
/
bundle.js
138 lines (115 loc) · 3.45 KB
/
bundle.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const { join } = require('path');
const { copyFile } = require('fs').promises;
const rollup = require('rollup');
const typescript2 = require('rollup-plugin-typescript2');
const { terser } = require('rollup-plugin-terser');
const json = require('@rollup/plugin-json');
const ts = require('typescript');
const project = require('./project');
bundle();
async function bundle() {
if (process.argv.slice(2)[0] === 'bench') {
await bunldeCJS();
} else {
await bundleES6();
await bundleES5();
await copyFile('./dist/meriyah.esm.js', './dist/meriyah.esm.mjs');
await copyFile('./dist/meriyah.esm.min.js', './dist/meriyah.esm.min.mjs');
await copyFile('./dist/meriyah.cjs.js', './dist/meriyah.cjs');
await copyFile('./dist/meriyah.cjs.min.js', './dist/meriyah.min.cjs');
await copyFile('./dist/meriyah.umd.js', './dist/meriyah.umd.cjs');
await copyFile('./dist/meriyah.umd.min.js', './dist/meriyah.umd.min.cjs');
}
}
// bundle cjs(es6)
async function bunldeCJS() {
console.log(`creating cjs bundle`);
const bundle = await rollup.rollup({
input: project.entry.path,
plugins: [
typescript2({
tsconfig: project['tsconfig.json'].path,
typescript: ts,
clean: true
}),
json()
]
});
const fileName = join(project.dist.path, `meriyah.cjs.js`);
console.log(`writing ${fileName}`);
await bundle.write({
file: fileName,
name: 'meriyah',
format: 'cjs'
});
console.log(`done`);
}
// bundle es6()
async function bundleES6() {
for (const type of ['normal', 'minified']) {
console.log(`creating ${type} bundle`);
const bundle = await rollup.rollup({
input: project.entry.path,
plugins: [
typescript2({
tsconfig: project['tsconfig.json'].path,
typescript: ts,
clean: true
}),
json(),
...(type === 'minified' ? [terser()] : [])
]
});
const suffix = type === 'minified' ? '.min' : '';
//'amd' | 'cjs' | 'system' | 'es' | 'esm' | 'iife' | 'umd'
for (const format of ['esm', 'system', 'cjs']) {
const fileName = join(project.dist.path, `meriyah.${format}${suffix}.js`);
console.log(`writing ${fileName}`);
await bundle.write({
file: fileName,
name: 'meriyah',
format
});
}
for (const format of ['umd', 'amd', 'iife']) {
const fileName = join(project.dist.path, `meriyah.${format}${suffix}.js`);
console.log(`writing ${fileName}`);
await bundle.write({
file: fileName,
exports: 'named',
name: 'meriyah',
format
});
}
}
}
// bundle es5(umd)
async function bundleES5() {
for (const type of ['normal', 'minified']) {
console.log(`creating ${type} es5 bundle`);
const bundle = await rollup.rollup({
input: project.entry.path,
plugins: [
typescript2({
tsconfig: project['tsconfig.json'].path,
tsconfigOverride: { compilerOptions: { target: 'es5' } },
typescript: ts,
clean: true
}),
json(),
...(type === 'minified' ? [terser()] : [])
]
});
const suffix = type === 'minified' ? '.min' : '';
for (const format of ['umd']) {
const fileName = join(project.dist.path, `meriyah.${format}.es5${suffix}.js`);
console.log(`writing ${fileName}`);
await bundle.write({
file: fileName,
exports: 'named',
name: 'meriyah',
format
});
}
}
}