chiya/assets/build.js
2023-09-09 13:06:27 +02:00

53 lines
No EOL
897 B
JavaScript

const esbuild = require('esbuild')
const postCssPlugin = require('esbuild-style-plugin')
const args = process.argv.slice(2)
const watch = args.includes('--watch')
const deploy = args.includes('--deploy')
const loader = {
// Add loaders for images/fonts/etc, e.g. { '.svg': 'file' }
'.js': 'jsx'
}
const plugins = [
// Add and configure plugins here
postCssPlugin({
postcss: {
plugins: [
require('tailwindcss'),
require('autoprefixer')
]
}
})
]
let opts = {
entryPoints: ['js/app.js', 'js/public.js'],
bundle: true,
target: 'es2016',
outdir: '../priv/static/assets',
logLevel: 'info',
loader,
plugins
}
if (watch) {
opts = {
...opts,
sourcemap: 'inline'
}
}
if (deploy) {
opts = {
...opts,
minify: true
}
}
const promise = esbuild.build(opts)
if (watch) {
esbuild.context(opts).then(ctx => ctx.watch())
}