Repository navigation
Expand file tree
/
Copy pathrolldown.base.mjs
More file actions
52 lines (47 loc) · 1.51 KB
/
Copy pathrolldown.base.mjs
File metadata and controls
52 lines (47 loc) · 1.51 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
import * as path from "node:path";
import { defineConfig } from "rolldown";
export const mode = process.env.NODE_ENV === "production" ? "production" : "development";
export const mainOutputDirectory = path.resolve(import.meta.dirname, "src", "main", "build");
/**
* @param {import("rolldown").InputOptions} input
* @param {string} output
* @param {"cjs" | "esm"} format
* @param {import("rolldown").Plugin[]} [customPlugins=[]]
* @param {import("rolldown").ExternalOption} [external=undefined]
* @returns {import("rolldown").RolldownOptions}
* */
export function createConfig(input, output, format, customPlugins = [], external = undefined) {
return defineConfig({
input: input,
platform: "node",
plugins: customPlugins,
external: external,
onLog: (level, log, defaultHandler) => {
if (log.code === "UNRESOLVED_IMPORT") {
defaultHandler("error", log);
return;
}
defaultHandler(level, log);
},
transform: {
define: {
"process.env.NODE_ENV": `"${mode}"`,
},
},
output: {
file: output,
format: format,
dynamicImportInCjs: false,
minify: mode === "production",
comments: false,
sourcemap: true,
sourcemapPathTransform:
mode === "production"
? undefined
: (relativeSourcePath, sourcemapPath) => {
// Turn relative sourcemap paths into absolute paths
return path.resolve(path.dirname(sourcemapPath), relativeSourcePath);
},
},
});
}