diff --git a/crates/mako/src/generate/chunk_pot/str_impl.rs b/crates/mako/src/generate/chunk_pot/str_impl.rs index 238e3d5d8..3f71acd0d 100644 --- a/crates/mako/src/generate/chunk_pot/str_impl.rs +++ b/crates/mako/src/generate/chunk_pot/str_impl.rs @@ -112,12 +112,16 @@ pub(super) fn render_normal_js_chunk( ) -> Result { let (content_buf, source_map_buf) = { let pot = chunk_pot; + + // to avoid ' or " been included in chunk_loading_global + let safe_prop = + serde_json::from_str::(&context.config.output.chunk_loading_global) + .unwrap(); + let chunk_prefix_code = format!( - r#"((typeof globalThis !== 'undefined' ? globalThis : self)['{}'] = (typeof globalThis !== 'undefined' ? globalThis : self)['{}'] || []).push([ -['{}'],"#, - context.config.output.chunk_loading_global, - context.config.output.chunk_loading_global, - pot.chunk_id, + r#"((typeof globalThis !== 'undefined' ? globalThis : self)[{}] = (typeof globalThis !== 'undefined' ? globalThis : self)[{}] || []).push([ + ['{}'],"#, + safe_prop, safe_prop, pot.chunk_id, ); let (chunk_content, chunk_raw_sourcemap) = pot_to_chunk_module_object_string(