-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config-1741861642372.mjs
More file actions
112 lines (109 loc) · 3.53 KB
/
rollup.config-1741861642372.mjs
File metadata and controls
112 lines (109 loc) · 3.53 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
109
110
111
112
import fs from "fs";
import sourcemaps from "rollup-plugin-sourcemaps2";
import typescript from "@rollup/plugin-typescript";
import resolve from "@rollup/plugin-node-resolve";
import replace from "@rollup/plugin-replace";
import commonjs from "@rollup/plugin-commonjs";
import terser from "@rollup/plugin-terser";
import strip from "@rollup/plugin-strip";
import json from "@rollup/plugin-json";
// Common set of plugins/transformations shared across different rollup
// builds (main mapmetrics bundle, style-spec package, benchmarks bundle)
const nodeResolve = resolve({
browser: true,
preferBuiltins: false,
});
const plugins = (production) =>
[
json(),
// https://github.com/zaach/jison/issues/351
replace({
preventAssignment: true,
include: /\/jsonlint-lines-primitives\/lib\/jsonlint.js/,
delimiters: ["", ""],
values: {
"_token_stack:": "",
},
}),
production &&
strip({
sourceMap: true,
functions: ["PerformanceUtils.*"],
}),
production &&
terser({
compress: {
pure_getters: true,
passes: 3,
},
sourceMap: true,
}),
nodeResolve,
typescript(),
commonjs({
// global keyword handling causes Webpack compatibility issues, so we disabled it:
ignoreGlobal: true,
}),
].filter(Boolean);
const watchStagingPlugin = {
name: "watch-external",
buildStart() {
this.addWatchFile("staging/mapmetricsgl/index.js");
this.addWatchFile("staging/mapmetricsgl/shared.js");
this.addWatchFile("staging/mapmetricsgl/worker.js");
},
};
const { BUILD } = process.env;
const production = BUILD === "production";
const outputFile = production
? "dist/mapmetrics-gl.js"
: "dist/mapmetrics-gl-dev.js";
const config = [
{
input: ["src/index.ts", "src/source/worker.ts"],
output: {
dir: "staging/mapmetricsgl",
format: "amd",
sourcemap: "inline",
indent: false,
chunkFileNames: "shared.js",
amd: {
autoId: true,
},
minifyInternalExports: production,
},
onwarn: (message) => {
console.error(message);
throw message;
},
treeshake: production,
plugins: plugins(production),
},
{
input: "build/rollup/mapmetricsgl.js",
output: {
name: "mapmetricsgl",
file: outputFile,
format: "umd",
sourcemap: true,
indent: false,
intro: fs.readFileSync("build/rollup/bundle_prelude.js", "utf8"),
// banner,
},
watch: {
// give the staging chunks a chance to finish before rebuilding the dev build
buildDelay: 1000,
},
treeshake: false,
plugins: [
// Ingest the sourcemaps produced in the first step of the build.
// This is the only reason we use Rollup for this second pass
sourcemaps(),
// When running in development watch mode, tell rollup explicitly to watch
// for changes to the staging chunks built by the previous step. Otherwise
// only they get built, but not the merged dev build js
...(production ? [] : [watchStagingPlugin]),
],
},
];
export { config as default };