refactor: optimize type and deserialize for config #837
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
对配置文件的类型及反序列化值做优化,改动点:
manifest: bool
和manifest_config: { ... }
合并为manifest: Option<{ ... }>
hmr: bool
和hmr_config: { ... }
合并为hmr: Option<{ ... }>
px2rem: bool
和px2rem_onfig: { ... }
合并为px2rem: Option<{ ... }>
umd: String
调整为umd: Option<String>
,用None
替代特殊字符串值none
CodeSplittingStrategy::None
调整为Option<CodeSplittingStrategy>
,用None
替代特殊枚举值None
treeShake
调整为_treeShaking
,标记为私有配置并从文档中去除TreeShaking::None
调整为Option<CodeSplittingStrategy>
,用None
替代特殊枚举值None
DevtoolConfig::None
调整为Option<DevtoolConfig>
,用None
替代特殊枚举值None
less
配置项Option<T>
均支持false
值并禁用null
,前者更符合 JavaScript 用户习惯,Mako 会自动将false
反序列化为None
以便后续逻辑消费Option
学到的经验(踩到的坑),config crate 里
add_source
覆盖的前提是类型相同做合并,比如(伪代码):所以如果希望提供默认关闭的配置项,不应该在第一个
add_source
的内容里将它设置为false
,而是应该用 default attribute,比如(伪代码):