Fix .png and .svg loading errors (#7442)

* Fix resource building

* Simplify plugin regex

* Include `.svg` files in regex
This commit is contained in:
somebody1234 2023-08-01 21:08:31 +10:00 committed by GitHub
parent ece18537e4
commit 7441a9a62c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -127,18 +127,31 @@ export function bundlerOptions(args: Arguments) {
outbase: 'src', outbase: 'src',
plugins: [ plugins: [
{ {
// This file MUST be in CommonJS format because it is loaded using `Function()` name: 'override-loaders',
// in `ensogl/pack/js/src/runner/index.ts`.
// All other files are ESM because of `"type": "module"` in `package.json`.
name: 'pkg-js-is-cjs',
setup: build => { setup: build => {
build.onLoad({ filter: /[/\\]pkg.js$/ }, async info => { // This file MUST be in CommonJS format because it is loaded using `Function()`
// in `ensogl/pack/js/src/runner/index.ts`.
// All other files are ESM because of `"type": "module"` in `package.json`.
build.onLoad({ filter: /[/\\]pkg\.js$/ }, async info => {
const { path } = info const { path } = info
return { return {
contents: await fs.readFile(path), contents: await fs.readFile(path),
loader: 'copy', loader: 'copy',
} }
}) })
// `.png` and `.svg` files not in the `assets` module should not use the `file`
// loader.
build.onLoad({ filter: /(?:\.png|\.svg)$/ }, async info => {
const { path } = info
if (!/[/\\]assets[/\\][^/\\]*(?:\.png|\.svg)$/.test(path)) {
return {
contents: await fs.readFile(path),
loader: 'copy',
}
} else {
return
}
})
}, },
}, },
esbuildPluginCopyDirectories(), esbuildPluginCopyDirectories(),