-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathesbuild.config.mjs
75 lines (72 loc) · 1.98 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
71
72
73
74
75
#!/usr/bin/env node
import * as esbuild from 'esbuild'
import { copy } from 'esbuild-plugin-copy'
import rails from 'esbuild-rails'
import path from 'path'
import { sassPlugin } from 'esbuild-sass-plugin'
const config = {
entryPoints: ['javascripts/application.js', 'stylesheets/application.scss'],
bundle: true,
sourcemap: process.argv.includes('--sourcemap'),
//resolveExtensions: ['.ts', '.js'],
logLevel: 'info',
outdir: 'builds',
outbase: path.join(process.cwd(), 'app/assets'),
absWorkingDir: path.join(process.cwd(), 'app/assets'),
metafile: true,
entryNames: '[name]',
minify: process.env.RAILS_ENV == 'production',
//external: ['*.css', '*.woff', '*.png', '*.svg'],
loader: {
'.jpeg': 'file',
'.png': 'file',
'.woff': 'dataurl',
'.woff2': 'dataurl',
'.eot': 'dataurl',
'.ttf': 'dataurl',
'.svg': 'file'
},
define: {
'process.env.RELEASE_STAGE': JSON.stringify(
process.env.RAILS_ENV || 'production'
),
'process.env.BUILD_AT': JSON.stringify(process.env.BUILD_AT || Date.now()),
global: 'window'
},
// platform: 'node',
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/@tabler/icons/icons/**/*.svg'],
to: ['./icons'],
keepStructure: true
}
]
}),
sassPlugin()
]
}
if (process.argv.includes('--watch')) {
let context = await esbuild.context({ ...config, logLevel: 'info' })
console.log(
`⚡ Build node esbuild for ${process.env.RAILS_ENV} complete! ⚡, watching...`
)
context.watch()
} else {
esbuild.build(config).catch(error => {
console.error(error)
process.exit(1)
})
console.log(`⚡ Build node esbuild for ${process.env.RAILS_ENV} complete! ⚡`)
}