Skip to content

Commit

Permalink
refactor: use option for umd config
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachScript committed Jan 2, 2024
1 parent 9f4a989 commit b925e65
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
6 changes: 1 addition & 5 deletions crates/mako/src/chunk_pot/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ pub(crate) fn empty_module_fn_expr() -> FnExpr {
create = "{ SizedCache::with_size(5) }"
)]
pub(crate) fn runtime_code(context: &Arc<Context>) -> Result<String> {
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;
Expand Down
11 changes: 4 additions & 7 deletions crates/mako/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
pub write_to_disk: bool,
pub transform_import: Vec<TransformImportConfig>,
pub dev_eval: bool,
Expand Down Expand Up @@ -440,7 +440,6 @@ const DEFAULT_CONFIG: &str = r#"
"autoCSSModules": false,
"ignoreCSSParserErrors": false,
"dynamicImportToRequire": false,
"umd": "none",
"writeToDisk": true,
"transformImport": [],
"devEval": false,
Expand Down Expand Up @@ -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<String>, 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();

Expand All @@ -648,7 +645,7 @@ fn get_default_chunk_loading_global(umd: String, root: &Path) -> String {
}

pkg_name
};
});

format!("makoChunk_{}", unique_name)
}
Expand Down
6 changes: 3 additions & 3 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,12 @@ publicPath 配置。注:有个特殊值 `"runtime"`,表示会切换到 runti

## umd

- 类型:`"none" | string`
- 默认值:`"none"`
- 类型:`null | string`
- 默认值:`null`

是否输出 umd 格式的代码。

注:1)后续会改成 `Object` 类型,支持更多子配置用于控制 umd 参数;2)`"none"` 会改成 `false` 类型
注:后续会改成 `Object` 类型,支持更多子配置用于控制 umd 参数。

## writeToDisk

Expand Down

0 comments on commit b925e65

Please sign in to comment.