-
Notifications
You must be signed in to change notification settings - Fork 146
/
rollup.config.mjs
111 lines (107 loc) · 3.1 KB
/
rollup.config.mjs
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
import fse from "fs-extra";
import resolve from "@rollup/plugin-node-resolve";
import babel from "@rollup/plugin-babel";
import commonjs from "@rollup/plugin-commonjs";
import format from 'date-format'
import terser from '@rollup/plugin-terser';
import { defineConfig } from 'rollup'
const packages = fse.readJSONSync("./package.json");
function createBanner() {
const today = format.asString('yyyy-MM-dd', new Date()); // today, formatted as yyyy-MM-dd
const version = packages.version; // module version
return String(fse.readFileSync('./src/header.js'))
.replace('@@date', today)
.replace('@@version', version);
}
fse.emptyDirSync("./dist/");
fse.copyFileSync('./src/header.js', './dist/workerpool.min.js.LICENSE.txt')
const commonPlugin = [
resolve({
extensions: [".js", ".ts", ".html"],
moduleDirectories: [],
preferBuiltins: false,
browser: true
}),
commonjs({
strictRequires: 'auto',
ignore: ['os', 'worker_threads', 'child_process']
}),
babel({
extensions: [".js", ".ts"],
babelHelpers: "bundled",
presets: ['@babel/env']
}),
];
const commonOutput = {
banner: createBanner(),
format: "umd",
sourcemap: true
}
/** generate embeddedWorker.js */
const buildEmbeddedWorker = (bundledWorkerCode) => {
const embedded = '/**\n' +
' * embeddedWorker.js contains an embedded version of worker.js.\n' +
' * This file is automatically generated,\n' +
' * changes made in this file will be overwritten.\n' +
' */\n' +
'module.exports = ' + JSON.stringify(bundledWorkerCode) + ';\n';
fse.writeFileSync('./src/generated/embeddedWorker.js', embedded);
}
export default defineConfig([
{
input: "./src/worker.js",
output: {
file: "./dist/worker.js",
name: "worker",
...commonOutput
},
plugins: commonPlugin
},
{
input: "./src/worker.js",
output: {
file: "./dist/worker.min.js",
name: "worker",
...commonOutput,
banner: ""
},
plugins: [
...commonPlugin,
terser({
maxWorkers: 4
}),
{
name: "outputEmbeddedWorker",
generateBundle(_, output) {
buildEmbeddedWorker(output['worker.min.js'].code)
}
}
],
},
{
input: "./src/index.js",
output: {
file: "./dist/workerpool.js",
name: "workerpool",
exports: "named",
...commonOutput
},
plugins: commonPlugin
},
{
input: "./src/index.js",
output: {
file: "./dist/workerpool.min.js",
name: "workerpool",
exports: "named",
...commonOutput,
banner: "/*! For license information please see workerpool.min.js.LICENSE.txt */",
},
plugins: [
...commonPlugin,
terser({
maxWorkers: 4
})
],
},
]);