1
0
Fork 0
mirror of https://github.com/Findus23/lw1.at.git synced 2024-09-16 12:13:44 +02:00
lw1.at/build.ts

54 lines
1.4 KiB
TypeScript
Raw Permalink Normal View History

2022-04-24 16:57:44 +02:00
import {sassPlugin} from 'esbuild-sass-plugin'
2023-02-21 18:49:49 +01:00
import {build, BuildOptions, context} from "esbuild";
2022-04-24 16:57:44 +02:00
import * as fs from "fs";
const commonOption: BuildOptions = {
entryPoints: ['assets/main.ts', 'assets/redirector.ts', "assets/scss/main.scss", 'assets/katex.css'],
target: "esnext",
2023-03-27 23:14:37 +02:00
format: "esm",
2022-04-24 16:57:44 +02:00
bundle: true,
sourcemap: true,
minify: true,
outdir: "public/assets",
2023-03-27 23:14:37 +02:00
splitting: true,
2023-01-02 20:57:47 +01:00
// @ts-ignore https://github.com/glromeo/esbuild-sass-plugin/issues/109
2022-04-24 16:57:44 +02:00
plugins: [sassPlugin()],
loader: {
".ttf": "file",
".woff": "file",
2022-04-24 22:32:55 +02:00
".woff2": "file",
2023-03-27 23:14:37 +02:00
".svg": "text",
2022-04-24 22:32:55 +02:00
".png": "base64"
2022-04-24 16:57:44 +02:00
},
entryNames: "[name]"
}
switch (process.argv[2]) {
case "build":
commonOption.metafile = true
2022-04-24 22:32:55 +02:00
commonOption.entryNames = "[name]-[hash]"
2022-04-24 16:57:44 +02:00
build(commonOption).then(result => {
fs.writeFileSync(commonOption.outdir + "/meta.json", JSON.stringify(result.metafile))
})
break
case "serve":
commonOption.minify = false
commonOption
2023-02-21 18:49:49 +01:00
context(commonOption).then(ctx => {
ctx.serve({
port: 1234,
servedir: "public"
}).catch((e) => {
console.error(e)
process.exit(1)
}).then(data => console.log(data))
})
2022-04-24 16:57:44 +02:00
break
default:
console.log(process.argv)
}