Page MenuHomeSealhub

No OneTemporary

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

Mime Type
text/x-diff
Expires
Sat, Nov 8, 14:05 (5 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1034651
Default Alt Text
(1 KB)

Event Timeline