diff --git a/crates/mako/src/chunk_pot/util.rs b/crates/mako/src/chunk_pot/util.rs index 14a00099a..5ea1fc1c4 100644 --- a/crates/mako/src/chunk_pot/util.rs +++ b/crates/mako/src/chunk_pot/util.rs @@ -92,11 +92,7 @@ pub(crate) fn empty_module_fn_expr() -> FnExpr { create = "{ SizedCache::with_size(5) }" )] pub(crate) fn runtime_code(context: &Arc) -> Result { - let umd = if context.config.umd != "none" { - Some(context.config.umd.clone()) - } else { - None - }; + let umd = context.config.umd.clone(); let chunk_graph = context.chunk_graph.read().unwrap(); let has_dynamic_chunks = chunk_graph.get_all_chunks().len() > 1; let has_hmr = context.args.watch; diff --git a/crates/mako/src/config.rs b/crates/mako/src/config.rs index ca9367dcb..601e7a17b 100644 --- a/crates/mako/src/config.rs +++ b/crates/mako/src/config.rs @@ -287,7 +287,7 @@ pub struct Config { #[serde(rename = "ignoreCSSParserErrors")] pub ignore_css_parser_errors: bool, pub dynamic_import_to_require: bool, - pub umd: String, + pub umd: Option, pub write_to_disk: bool, pub transform_import: Vec, pub dev_eval: bool, @@ -440,7 +440,6 @@ const DEFAULT_CONFIG: &str = r#" "autoCSSModules": false, "ignoreCSSParserErrors": false, "dynamicImportToRequire": false, - "umd": "none", "writeToDisk": true, "transformImport": [], "devEval": false, @@ -631,10 +630,8 @@ impl Default for Config { } } -fn get_default_chunk_loading_global(umd: String, root: &Path) -> String { - let unique_name = if umd != "none" { - umd - } else { +fn get_default_chunk_loading_global(umd: Option, root: &Path) -> String { + let unique_name = umd.unwrap_or_else(|| { let pkg_json_path = root.join("package.json"); let mut pkg_name = "global".to_string(); @@ -648,7 +645,7 @@ fn get_default_chunk_loading_global(umd: String, root: &Path) -> String { } pkg_name - }; + }); format!("makoChunk_{}", unique_name) } diff --git a/docs/config.md b/docs/config.md index 570455cc5..72ddb5e0d 100644 --- a/docs/config.md +++ b/docs/config.md @@ -358,12 +358,12 @@ publicPath 配置。注:有个特殊值 `"runtime"`,表示会切换到 runti ## umd -- 类型:`"none" | string` -- 默认值:`"none"` +- 类型:`null | string` +- 默认值:`null` 是否输出 umd 格式的代码。 -注:1)后续会改成 `Object` 类型,支持更多子配置用于控制 umd 参数;2)`"none"` 会改成 `false` 类型。 +注:后续会改成 `Object` 类型,支持更多子配置用于控制 umd 参数。 ## writeToDisk