btclock_v3/data/esbuild.mjs

59 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2023-11-08 11:18:59 +00:00
import esbuild from "esbuild";
import { sassPlugin } from "esbuild-sass-plugin";
import htmlPlugin from '@chialab/esbuild-plugin-html';
import handlebarsPlugin from "esbuild-plugin-handlebars";
import { clean } from 'esbuild-plugin-clean';
2023-11-14 22:09:23 +00:00
import { copy } from 'esbuild-plugin-copy';
2023-11-08 11:18:59 +00:00
import postcss from "postcss";
import autoprefixer from "autoprefixer";
const hbsOptions = {
additionalHelpers: { splitText: "helpers.js" },
additionalPartials: {},
precompileOptions: {}
2023-11-14 22:09:23 +00:00
}
2023-11-08 11:18:59 +00:00
esbuild
.build({
entryPoints: ["src/css/style.scss", "src/js/script.ts", "src/index.html", "src/js/helpers.js"],
outdir: "build",
bundle: true,
loader: {
".png": "dataurl",
".woff": "dataurl",
".woff2": "dataurl",
".eot": "dataurl",
".ttf": "dataurl",
".svg": "dataurl",
},
plugins: [
clean({
patterns: ['./build/*']
2023-11-14 22:09:23 +00:00
}),
2023-11-08 11:18:59 +00:00
htmlPlugin(),
sassPlugin({
async transform(source) {
const { css } = await postcss([autoprefixer]).process(
source
, { from: undefined });
return css;
},
}),
handlebarsPlugin(hbsOptions),
2023-11-14 22:09:23 +00:00
copy({
// this is equal to process.cwd(), which means we use cwd path as base path to resolve `to` path
// if not specified, this plugin uses ESBuild.build outdir/outfile options as base path.
resolveFrom: 'cwd',
assets: {
from: ['./src/api.*'],
to: ['./build'],
},
})
2023-11-08 11:18:59 +00:00
],
minify: true,
metafile: false,
sourcemap: false
})
.then(() => console.log("⚡ Build complete! ⚡"))
.catch(() => process.exit(1));