fix(scripts/build): use import instead of require for asset generation

This commit is contained in:
PalmDevs 2025-06-07 09:59:30 +07:00
parent b7f1486b56
commit a4bd9f26c3
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA

View file

@ -234,10 +234,14 @@ async function generateAssets() {
if (await exists(path2)) continue
// We attempt to sanitize the path, but not the name as it should fail if name contains invalid characters
const uriPath = JSON.stringify(path)
const type = JSON.stringify(ext.slice(1))
promises.push(
writeFile(
path2,
`const ${name}=require('@revenge-mod/assets').registerAsset({name:'${name}',type:'${ext.slice(1)}',uri:require('~/../${path}')})/**@type {ReturnType<import('@revenge-mod/assets').registerAsset>}*/\nexport default ${name}`,
`import{registerAsset}from'@revenge-mod/assets';import uri from${uriPath};const ${name}=registerAsset({name:'${name}',type:${type},uri});export default ${name}`,
),
)
}