forked from excalidraw/excalidraw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildUtils.js
123 lines (112 loc) · 3.05 KB
/
buildUtils.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
const { build } = require("esbuild");
const { sassPlugin } = require("esbuild-sass-plugin");
const fs = require("fs");
const browserConfig = {
entryPoints: ["index.ts"],
bundle: true,
format: "esm",
plugins: [sassPlugin()],
};
// Will be used later for treeshaking
// function getFiles(dir, files = []) {
// const fileList = fs.readdirSync(dir);
// for (const file of fileList) {
// const name = `${dir}/${file}`;
// if (
// name.includes("node_modules") ||
// name.includes("config") ||
// name.includes("package.json") ||
// name.includes("main.js") ||
// name.includes("index-node.ts") ||
// name.endsWith(".d.ts") ||
// name.endsWith(".md")
// ) {
// continue;
// }
// if (fs.statSync(name).isDirectory()) {
// getFiles(name, files);
// } else if (
// name.match(/\.(sa|sc|c)ss$/) ||
// name.match(/\.(woff|woff2|eot|ttf|otf)$/) ||
// name.match(/locales\/[^/]+\.json$/)
// ) {
// continue;
// } else {
// files.push(name);
// }
// }
// return files;
// }
const createESMBrowserBuild = async () => {
// Development unminified build with source maps
const browserDev = await build({
...browserConfig,
outdir: "dist/browser/dev",
sourcemap: true,
metafile: true,
define: {
"import.meta.env": JSON.stringify({ DEV: true }),
},
});
fs.writeFileSync(
"meta-browser-dev.json",
JSON.stringify(browserDev.metafile),
);
// production minified build without sourcemaps
const browserProd = await build({
...browserConfig,
outdir: "dist/browser/prod",
minify: true,
metafile: true,
define: {
"import.meta.env": JSON.stringify({ PROD: true }),
},
});
fs.writeFileSync(
"meta-browser-prod.json",
JSON.stringify(browserProd.metafile),
);
};
const rawConfig = {
entryPoints: ["index.ts"],
bundle: true,
format: "esm",
packages: "external",
plugins: [sassPlugin()],
};
// const BASE_PATH = `${path.resolve(`${__dirname}/..`)}`;
// const filesinExcalidrawPackage = getFiles(`${BASE_PATH}/packages/utils`);
// const filesToTransform = filesinExcalidrawPackage.filter((file) => {
// return !(
// file.includes("/__tests__/") ||
// file.includes(".test.") ||
// file.includes("/tests/") ||
// file.includes("example")
// );
// });
const createESMRawBuild = async () => {
// Development unminified build with source maps
const rawDev = await build({
...rawConfig,
outdir: "dist/dev",
sourcemap: true,
metafile: true,
define: {
"import.meta.env": JSON.stringify({ DEV: true }),
},
});
fs.writeFileSync("meta-raw-dev.json", JSON.stringify(rawDev.metafile));
// production minified build without sourcemaps
const rawProd = await build({
...rawConfig,
outdir: "dist/prod",
minify: true,
metafile: true,
define: {
"import.meta.env": JSON.stringify({ PROD: true }),
},
});
fs.writeFileSync("meta-raw-prod.json", JSON.stringify(rawProd.metafile));
};
createESMRawBuild();
createESMBrowserBuild();