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
2023-03-27 23:14:37 +02:00

53 lines
1.4 KiB
TypeScript

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