Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions crates/pack-core/js/src/umd/runtime-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,6 @@ declare var TURBOPACK_NEXT_CHUNK_URLS: ChunkUrl[] | undefined;
declare var CHUNK_BASE_PATH: string;
declare var CHUNK_SUFFIX_PATH: string;

function normalizeChunkPath(path: string) {
if (path.startsWith("/")) {
path = path.substring(1);
} else if (path.startsWith("./")) {
path = path.substring(2);
}

if (!path.endsWith("/")) {
path += "/";
}

return path;
}

const NORMALIZED_CHUNK_BASE_PATH = normalizeChunkPath(CHUNK_BASE_PATH);

interface TurbopackBrowserBaseContext<M> extends TurbopackBaseContext<M> {
R: ResolvePathFromModule;
}
Expand Down Expand Up @@ -242,7 +226,7 @@ function instantiateRuntimeModule(
* Returns the URL relative to the origin where a chunk can be fetched from.
*/
function getChunkRelativeUrl(chunkPath: ChunkPath | ChunkListPath): ChunkUrl {
return `${NORMALIZED_CHUNK_BASE_PATH}${chunkPath
return `${CHUNK_BASE_PATH}${chunkPath
.split("/")
.map((p) => encodeURIComponent(p))
.join("/")}${CHUNK_SUFFIX_PATH}` as ChunkUrl;
Expand Down
6 changes: 6 additions & 0 deletions crates/pack-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,12 @@ impl Config {
.and_then(|o| o.public_path.clone())
.unwrap_or("".into());

// Special handling for "runtime" value - return a marker that will be
// replaced at runtime with window.publicPath
if public_path.as_str() == "runtime" {
return Ok(Vc::cell("__RUNTIME_PUBLIC_PATH__".into()));
}

Ok(Vc::cell(
format!("{}/", public_path.trim_end_matches("/")).into(),
))
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions crates/pack-tests/tests/snapshot/public_path/runtime/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"config": {
"entry": [
{
"import": "input/index.js",
"name": "main"
}
],
"output": {
"path": "output",
"publicPath": "runtime"
},
"optimization": {
"minify": false
}
},
"runtimeType": "Production"
}


Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import asset from "./asset.jpg";

export function getImageUrl() {
return asset;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading