fix(scripts/build): syntax error
This commit is contained in:
parent
e389a6b61b
commit
790f1f9ee3
2 changed files with 8 additions and 5 deletions
|
|
@ -42,8 +42,9 @@ export default async function build(dev = Dev, log = true) {
|
||||||
input: 'src/index.ts',
|
input: 'src/index.ts',
|
||||||
platform: 'neutral',
|
platform: 'neutral',
|
||||||
optimization: {
|
optimization: {
|
||||||
// ! BROKEN, DO NOT USE!
|
inlineConst: {
|
||||||
// inlineConst: true,
|
mode: 'smart',
|
||||||
|
},
|
||||||
// @ts-expect-error: Option not documented, but added in 1.0.0-beta.30
|
// @ts-expect-error: Option not documented, but added in 1.0.0-beta.30
|
||||||
pifeForModuleWrappers: true,
|
pifeForModuleWrappers: true,
|
||||||
},
|
},
|
||||||
|
|
@ -91,8 +92,8 @@ export default async function build(dev = Dev, log = true) {
|
||||||
asRequire(),
|
asRequire(),
|
||||||
shimAliases(ShimsDir),
|
shimAliases(ShimsDir),
|
||||||
importGlobPlugin(),
|
importGlobPlugin(),
|
||||||
importDefer(),
|
|
||||||
hermesSwcPlugin(),
|
hermesSwcPlugin(),
|
||||||
|
importDefer(),
|
||||||
hermesCPlugin({
|
hermesCPlugin({
|
||||||
flags: [
|
flags: [
|
||||||
dev ? '-Og' : '-O',
|
dev ? '-Og' : '-O',
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ const DEFER_NAMESPACE_IMPORT_REGEX =
|
||||||
/**
|
/**
|
||||||
* Really wacky support for `import defer` statements by transforming them to `require()`.
|
* Really wacky support for `import defer` statements by transforming them to `require()`.
|
||||||
*
|
*
|
||||||
|
* Only supports JavaScript files. TypeScript files with conflicting type names may cause issues.
|
||||||
|
*
|
||||||
* `import defer` statements are transformed to provide on-demand/lazy loading.
|
* `import defer` statements are transformed to provide on-demand/lazy loading.
|
||||||
*
|
*
|
||||||
* This is achieved by creating a scoped closure to cache the module.
|
* This is achieved by creating a scoped closure to cache the module.
|
||||||
|
|
@ -41,7 +43,7 @@ export default function importDefer() {
|
||||||
hasReplacements = true
|
hasReplacements = true
|
||||||
|
|
||||||
// Find all usages of the imported identifier
|
// Find all usages of the imported identifier
|
||||||
const usageRegex = new RegExp(`\\b${localName}\\b`, 'g');
|
const usageRegex = new RegExp(`\\b${localName}\\b`, 'g')
|
||||||
|
|
||||||
for (const usageMatch of code.matchAll(usageRegex)) {
|
for (const usageMatch of code.matchAll(usageRegex)) {
|
||||||
// Original import declaration
|
// Original import declaration
|
||||||
|
|
@ -123,5 +125,5 @@ function generateDeferReplacement(bindings: Bindings, modulePath: string) {
|
||||||
const [{ local: localName }] = bindings
|
const [{ local: localName }] = bindings
|
||||||
const cacheVar = `_cache_${modulePath.replace(/[^a-zA-Z0-9]/g, '_')}`
|
const cacheVar = `_cache_${modulePath.replace(/[^a-zA-Z0-9]/g, '_')}`
|
||||||
|
|
||||||
return `var ${cacheVar};const ${localName}=()=>${cacheVar}??=require('${modulePath}')`
|
return `var ${cacheVar};const ${localName}=()=>${cacheVar}??=require('${modulePath}');`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue