Skip to content

Commit b54865c

Browse files
test: cover function publicPath fallback for import.meta.env.BASE_URL
A function publicPath is resolved per-asset at runtime, so BASE_URL has no static value and falls back to "/" (while __webpack_public_path__ stays the runtime value).
1 parent 1e7f60a commit b54865c

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
it("should fall back import.meta.env.BASE_URL to '/' for a function publicPath", () => {
2+
// the function runs at runtime, so there is no static base to expose
3+
expect(import.meta.env.BASE_URL).toBe("/");
4+
expect(__webpack_public_path__).toBe("/from-fn/");
5+
expect(import.meta.env.MODE).toBe("production");
6+
expect(import.meta.env.SSR).toBe(false);
7+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"use strict";
2+
3+
/** @type {import("../../../../").Configuration} */
4+
module.exports = {
5+
mode: "production",
6+
target: "web",
7+
output: {
8+
// a function publicPath has no static value, so BASE_URL falls back to "/"
9+
publicPath: () => "/from-fn/"
10+
}
11+
};

0 commit comments

Comments
 (0)