-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
esbuild.config.mjs
70 lines (66 loc) · 1.73 KB
/
esbuild.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env node
import * as esbuild from 'esbuild'
import rails from 'esbuild-rails'
import path from 'path'
import { exec } from 'child_process'
import { copy } from 'esbuild-plugin-copy'
const entryPoints = [
'application.js',
'service-worker.js'
]
const watchDirectories = [
'./app/assets/javascripts/**/*.js',
'./app/views/**/*.html.erb',
'./app/views/**/*.turbo_stream.erb',
'./app/assets/builds/**/*.css'
]
const config = {
absWorkingDir: path.join(process.cwd(), 'app/assets/javascripts'),
outdir: 'builds',
bundle: true,
entryPoints: entryPoints,
minify: process.env.RAILS_ENV == 'production',
outdir: path.join(process.cwd(), 'app/assets/builds'),
plugins: [
rails(),
copy({
resolveFrom: path.join(process.cwd(), 'public/assets'),
assets: [
{
from: [
'./node_modules/tinymce/**/*.js',
'./node_modules/tinymce/**/*.css'
],
to: ['./tinymce'],
keepStructure: true
},
{
from: [
'./node_modules/heroicons/24/**/*.svg',
],
to: ['./icons/heroicons'],
keepStructure: true
}
]
})
],
sourcemap: process.argv.includes('--sourcemap')
}
if (process.argv.includes('--watch')) {
let context = await esbuild.context({ ...config, logLevel: 'info' })
context.watch()
console.log('👀 Watching for changes...')
} else {
esbuild.build(config).catch(error => {
console.error(error)
process.exit(1)
})
}
console.log(`🚀 Build node esbuild complete!`)
console.log('📱 Inject PWA workbox...')
exec('workbox injectManifest workbox.config.js', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`)
return
}
});