Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F996266
rewrite-asset-imports.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
926 B
Referenced Files
None
Subscribers
None
rewrite-asset-imports.ts
View Options
import
{
promises
as
fs
}
from
"fs"
;
import
{
extname
}
from
"node:path"
;
import
{
embeddable_file_extensions
}
from
"../embeddable-file-extensions.js"
;
import
{
removeNamedImports
}
from
"../../remove-named-imports.js"
;
import
{
PluginBuild
}
from
"esbuild"
;
export
const
rewrite_asset_imports_plugin
=
{
name
:
"sealgen-rewrite-asset-imports"
,
setup
(
build
:
PluginBuild
)
{
build
.
onLoad
({
filter
:
/\.tsx?$/
},
async
(
args
)
=>
{
let
contents
=
await
fs
.
readFile
(
args
.
path
,
"utf8"
);
for
(
const
ext
of
embeddable_file_extensions
)
{
const
regex_assets
=
new
RegExp
(
`^import (\\w+|{[^}]+}) from "([^"]+.
${
ext
}
)";`
,
"gm"
);
contents
=
contents
.
replaceAll
(
regex_assets
,
(
line
)
=>
{
return
line
.
replace
(
`.
${
ext
}
"`
,
'.js"'
);
});
}
contents
=
removeNamedImports
(
contents
)
as
string
;
return
{
contents
,
loader
:
extname
(
args
.
path
)
===
".tsx"
?
"tsx"
:
"ts"
,
};
});
},
};
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Tue, Dec 24, 14:02 (21 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
557142
Default Alt Text
rewrite-asset-imports.ts (926 B)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment