chiya/assets/build.js

54 lines
937 B
JavaScript
Raw Normal View History

2023-03-20 11:20:40 +01:00
const esbuild = require('esbuild')
2023-09-09 12:47:25 +02:00
const postCssPlugin = require('esbuild-style-plugin')
2023-03-20 11:20:40 +01:00
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' }
2023-03-21 07:19:10 +01:00
'.js': 'jsx'
2023-03-20 11:20:40 +01:00
}
const plugins = [
// Add and configure plugins here
2023-09-09 12:47:25 +02:00
postCssPlugin({
postcss: {
plugins: [
2023-09-09 12:54:42 +02:00
require('tailwindcss/nesting'),
2023-09-09 12:47:25 +02:00
require('tailwindcss'),
require('autoprefixer')
]
}
})
2023-03-20 11:20:40 +01:00
]
let opts = {
2023-03-31 17:33:42 +02:00
entryPoints: ['js/app.js', 'js/public.js'],
2023-03-20 11:20:40 +01:00
bundle: true,
target: 'es2017',
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)
2023-03-21 07:19:10 +01:00
if (watch) {
esbuild.context(opts).then(ctx => ctx.watch())
2023-07-19 20:45:45 +02:00
}