forked from waki285/suzuneu.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
60 lines (54 loc) · 1.6 KB
/
build.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
const { context } = require("esbuild");
const { sassPlugin } = require("esbuild-sass-plugin");
const { copy: copyPlugin } = require("esbuild-plugin-copy");
const { default: postcss } = require("postcss");
const tailwindcss = require("tailwindcss");
const TailwindSettings = require("./tailwind.config.js");
const postcssPresetEnv = require("postcss-preset-env");
const isDev = process.argv.includes("--dev") || process.env.NODE_ENV === "development";
(async () => {
const ctx = await context({
entryPoints: ["src/js/client.tsx"],
bundle: true,
minify: isDev,
sourcemap: isDev ? "linked":false,
legalComments: "none",
target: "ES2021",
outdir: "dist",
platform: "browser",
tsconfig: "tsconfig.json",
external: ["tailwindcss", "autoprefixer"],
logLevel: "info",
loader: {
".webp": "file",
},
plugins: [
sassPlugin({
type: "style",
filter: /\.s(c|a)ss$/,
async transform(source, resolveDir) {
const { css } = await postcss([tailwindcss(TailwindSettings), require("autoprefixer"), require("cssnano"), postcssPresetEnv]).process(source, { from: undefined });
return css;
}
}),
copyPlugin({
resolveFrom: "cwd",
assets: [
{ from: "src/assets/icon.png", to: "dist/icon.png" },
{ from: "public/**/*", to: "dist/" }
]
}),
]
});
process.on("beforeExit", () => {
ctx.dispose();
});
if (!isDev) {
await ctx.rebuild();
process.exit(0);
}
await ctx.watch();
const { host, port } = await ctx.serve({
servedir: "dist",
});
})();