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
5 changes: 5 additions & 0 deletions crates/pack-core/src/client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,11 @@ pub async fn get_client_chunking_context(
builder = builder.chunk_loading_global(chunk_loading_global.clone());
}

// Read entry_root_export from config
if let Some(entry_root_export) = &*config.entry_root_export().await? {
builder = builder.entry_root_export(Some(entry_root_export.clone()));
}

if mode.is_development() {
builder = builder
.hot_module_replacement()
Expand Down
19 changes: 19 additions & 0 deletions crates/pack-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ pub struct OutputConfig {
/// This is similar to webpack's `output.chunkLoadingGlobal`.
/// Default: "TURBOPACK"
pub chunk_loading_global: Option<RcStr>,
/// Expose entry module exports to global scope with the specified name.
/// When set, all named exports from the entry module will be available on `window`/`globalThis`
/// under the specified name. If set to empty string, will use package.json name.
/// Default: None (no exposure)
pub entry_root_export: Option<RcStr>,
}

#[turbo_tasks::value]
Expand Down Expand Up @@ -981,6 +986,20 @@ impl Config {
Ok(Vc::cell(None))
}

#[turbo_tasks::function]
pub async fn entry_root_export(&self) -> Result<Vc<Option<RcStr>>> {
// Check if entry_root_export is configured
let entry_root_export = self
.output
.as_ref()
.and_then(|o| o.entry_root_export.as_ref());

match entry_root_export {
Some(name) if !name.is_empty() => Ok(Vc::cell(Some(name.clone()))),
_ => Ok(Vc::cell(None)),
}
}

#[turbo_tasks::function]
pub fn mode(&self) -> Vc<Mode> {
self.mode.unwrap_or_default().cell()
Expand Down
7 changes: 7 additions & 0 deletions crates/pack-schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ pub struct SchemaOutputConfig {
description = "The global variable name used by the runtime for loading chunks. Default: 'TURBOPACK'"
)]
pub chunk_loading_global: Option<String>,

/// Expose entry module exports to global scope with the specified name
#[serde(skip_serializing_if = "Option::is_none")]
#[schemars(
description = "Expose entry module exports to global scope with the specified name. When set, all named exports from the entry module will be available on window/globalThis under the specified name. If set to empty string, will use package.json name. Default: None (no exposure)"
)]
pub entry_root_export: Option<String>,
}

/// Output type
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"config": {
"entry": [
{
"import": "input/index.ts",
"name": "main"
}
],
"output": {
"path": "output",
"entryRootExport": "export-entry-exports"
}
},
"runtimeType": "Production"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export function setTernContainer(container: HTMLElement) {
console.log('Setting Tern container:', container);
return container;
}

export function initializeApp(config: { theme: string }) {
console.log('Initializing app with config:', config);
return { success: true, config };
}

export const APP_VERSION = '1.0.0';

export default {
setTernContainer,
initializeApp,
version: APP_VERSION
};

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