-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrollup.config.js
86 lines (80 loc) · 1.99 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
import copy from "rollup-plugin-copy";
import json from "@rollup/plugin-json";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import inject from "@rollup/plugin-inject";
import * as path from "path";
const filesToCopy = [
path.resolve("src", "index.html"),
path.resolve("src", "favicon.ico"),
path.resolve("src", "style.css"),
path.resolve("src", "assets"),
path.resolve("src", "card"),
];
const EMPTY_MODULE_ID = "$empty$";
const EMPTY_MODULE = `export default {}`;
const BROWSERIFY_ALIASES = {
assert: "assert",
events: "events",
fs: "memfs",
module: EMPTY_MODULE_ID,
path: "path-browserify",
process: "process",
util: "util",
};
const nodeResolve = resolve({
preferBuiltins: false,
mainFields: ["module", "jsnext:main", "browser"],
});
const plugins = [
commonjs(),
{
name: "browserify",
resolveId(source, importer) {
if (source in BROWSERIFY_ALIASES) {
if (BROWSERIFY_ALIASES[source] === EMPTY_MODULE_ID)
return EMPTY_MODULE_ID;
return nodeResolve.resolveId(BROWSERIFY_ALIASES[source], undefined);
}
if (source === EMPTY_MODULE_ID) return EMPTY_MODULE_ID;
},
load(id) {
if (id === EMPTY_MODULE_ID) return EMPTY_MODULE;
},
},
inject({
process: "process",
}),
nodeResolve,
json(),
{
name: "watch-external",
buildStart() {
filesToCopy.forEach((file) => this.addWatchFile(file));
},
},
copy({
targets: [...filesToCopy.map((file) => ({ src: file, dest: "dist" }))],
}),
{
name: "remove-glob-weirdness",
renderChunk(code) {
// No clue why `glob_1.Glob;` ends up in bundle... useless line of code that actually creates fatal error >:(
return code.replace(/glob_1\.Glob;/g, "");
},
},
];
export default [
{
input: "src/node/index.js",
output: {
format: "es",
inlineDynamicImports: true,
file: "dist/index.js",
globals: {
lodash: "_",
},
},
plugins,
},
];