-
-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathfile.js
29 lines (25 loc) · 813 Bytes
/
file.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
const { dirname } = require("path")
const {
additional_paths: additionalPaths,
source_path: sourcePath
} = require("../config")
module.exports = {
test: /\.(bmp|gif|jpe?g|png|tiff|ico|avif|webp|eot|otf|ttf|woff|woff2|svg)$/,
exclude: /\.(js|mjs|jsx|ts|tsx)$/,
type: "asset/resource",
generator: {
filename: (pathData) => {
const path = dirname(pathData.filename)
const stripPaths = [...additionalPaths, sourcePath]
const selectedStripPath = stripPaths.find((includePath) =>
path.startsWith(includePath)
)
const folders = path
.replace(`${selectedStripPath}`, "")
.split("/")
.filter(Boolean)
const foldersWithStatic = ["static", ...folders].join("/")
return `${foldersWithStatic}/[name]-[hash][ext][query]`
}
}
}