fix(vite): asset handling (#3225)
This PR reworks asset handling in our vite plugin. Importing assets in js is now supported.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { expect } from "@std/expect/expect";
|
||||
import * as babel from "@babel/core";
|
||||
import { httpAbsolute } from "./http_absolute.ts";
|
||||
|
||||
function runTest(options: { input: string; expected: string; url?: URL }) {
|
||||
const res = babel.transformSync(options.input, {
|
||||
filename: "foo.js",
|
||||
babelrc: false,
|
||||
plugins: [httpAbsolute(options.url ?? null)],
|
||||
});
|
||||
|
||||
const output = res?.code ?? "";
|
||||
expect(output).toEqual(options.expected);
|
||||
}
|
||||
|
||||
Deno.test("http absolute - change import sources", () => {
|
||||
runTest({
|
||||
input: `import foo from "/foo.js"`,
|
||||
expected: `import foo from "deno-http::http://localhost/foo.js";`,
|
||||
url: new URL("http://localhost"),
|
||||
});
|
||||
});
|
||||
|
||||
Deno.test("http absolute - change export all sources", () => {
|
||||
runTest({
|
||||
input: `export * as foo from "/foo.js"`,
|
||||
expected: `export * as foo from "deno-http::http://localhost/foo.js";`,
|
||||
url: new URL("http://localhost"),
|
||||
});
|
||||
});
|
||||
|
||||
Deno.test("http absolute - change export sources", () => {
|
||||
runTest({
|
||||
input: `export { foo } from "/foo.js"`,
|
||||
expected: `export { foo } from "deno-http::http://localhost/foo.js";`,
|
||||
url: new URL("http://localhost"),
|
||||
});
|
||||
});
|
||||
|
||||
Deno.test("http absolute - change import()", () => {
|
||||
runTest({
|
||||
input: `import("/foo.js")`,
|
||||
expected: `import("deno-http::http://localhost/foo.js");`,
|
||||
url: new URL("http://localhost"),
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user