Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F10361494
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/esbuild-plugins/rewrite-asset-imports.ts b/src/esbuild-plugins/rewrite-asset-imports.ts
index 8a12122..2597500 100644
--- a/src/esbuild-plugins/rewrite-asset-imports.ts
+++ b/src/esbuild-plugins/rewrite-asset-imports.ts
@@ -1,44 +1,44 @@
import { promises as fs } from "fs";
import { extname, resolve } 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 = (project_dir: string) => ({
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) => {
line = line.replace(`.${ext}"`, '.js"');
return line;
});
}
const regex_import = new RegExp(
- `^import (\\w+|{[^}]+}) from "([^"]+)";`,
+ `^import ([^ ]+, )?(\\w+|{[^}]+}) from "([^"]+)";`,
"gm"
);
contents = contents.replaceAll(
regex_import,
(line, _: string, original_path: string) => {
- return line.replace(
+ const replaced = line.replace(
`"src/`,
`"` + resolve(project_dir, "./dist") + "/"
);
+ return replaced;
}
);
contents = removeNamedImports(contents) as string;
-
return {
contents,
loader: extname(args.path) === ".tsx" ? "tsx" : "ts",
};
});
},
});
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Nov 8, 14:05 (9 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1034651
Default Alt Text
(1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment