-
-
Notifications
You must be signed in to change notification settings - Fork 94
/
index.js
40 lines (32 loc) · 858 Bytes
/
index.js
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
/* eslint global-require: 0 */
/* eslint import/no-dynamic-require: 0 */
const { resolve } = require("path")
const { existsSync } = require("fs")
const { merge } = require("webpack-merge")
const getLoaderExtension = (filename) => {
const matchData = filename.match(/\.([jt]sx?)?(\.erb)?$/)
if (!matchData) {
return "js"
}
return matchData[1]
}
const getCustomConfig = () => {
const path = resolve("config", "esbuild.config.js")
if (existsSync(path)) {
return require(path)
}
return {}
}
const getEsbuildLoaderConfig = (filenameToProcess) => {
const customConfig = getCustomConfig()
const defaultConfig = {
loader: require.resolve("esbuild-loader"),
options: {
loader: getLoaderExtension(filenameToProcess)
}
}
return merge(defaultConfig, customConfig)
}
module.exports = {
getEsbuildLoaderConfig
}