-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathesbuild.config.js
More file actions
41 lines (37 loc) · 1.34 KB
/
esbuild.config.js
File metadata and controls
41 lines (37 loc) · 1.34 KB
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
const esbuild = require("esbuild")
const path = require("path")
const fs = require("fs")
const jqueryGlobalPlugin = {
name: "jquery-global",
setup(build) {
// jquery を外部モジュールとして扱い、window.jQuery を参照するようにする
build.onResolve({ filter: /^jquery$/ }, () => {
return { path: "jquery", namespace: "jquery-global" }
})
build.onLoad({ filter: /.*/, namespace: "jquery-global" }, () => {
return {
contents: "module.exports = window.jQuery",
loader: "js",
}
})
// jquery-ujs の UMD 末尾を修正
build.onLoad({ filter: /jquery-ujs/ }, async (args) => {
let contents = fs.readFileSync(args.path, "utf8")
contents = contents.replace(/\}\)\(\s*jQuery\s*\)/, "})(window.jQuery)")
return { contents, loader: "js" }
})
// bootstrap の UMD パターンも修正
build.onLoad({ filter: /node_modules\/bootstrap\/js\// }, async (args) => {
let contents = fs.readFileSync(args.path, "utf8")
contents = contents.replace(/\}\)\(\s*jQuery\s*\)/g, "})(window.jQuery)")
return { contents, loader: "js" }
})
},
}
esbuild.build({
entryPoints: ["app/javascript/application.js"],
bundle: true,
sourcemap: true,
outdir: path.join("app", "assets", "builds"),
plugins: [jqueryGlobalPlugin],
}).catch(() => process.exit(1))