-
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(css): support css module name coversion (#1784)
* feat: support css module name coversion * fix: remove unuse code --------- Co-authored-by: 苏向夜 <46275354+fu050409@users.noreply.github.com>
- Loading branch information
1 parent
4a99f4e
commit e17551a
Showing
13 changed files
with
128 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@farmfe/core": patch | ||
--- | ||
|
||
support css module name coversion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use heck::{ToLowerCamelCase, ToSnakeCase, ToUpperCamelCase}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, Default)] | ||
pub enum NameConversion { | ||
/// | ||
/// to keep the original name | ||
/// | ||
#[default] | ||
#[serde(rename = "asIs")] | ||
AsIs, | ||
/// | ||
/// ```md | ||
/// "It is we who built these palaces and cities." | ||
/// // => | ||
/// "itIsWeWhoBuiltThesePalacesAndCities" | ||
/// ``` | ||
#[serde(rename = "lowerCamel")] | ||
LowerCamel, | ||
/// ```md | ||
/// "We are not in the least afraid of ruins." | ||
/// // => | ||
/// "WeAreNotInTheLeastAfraidOfRuins" | ||
/// ``` | ||
#[serde(rename = "upperCamel")] | ||
UpperCamel, | ||
|
||
/// ```md | ||
/// "We carry a new world here, in our hearts." | ||
/// // => | ||
/// "we_carry_a_new_world_here_in_our_hearts" | ||
/// ``` | ||
#[serde(rename = "snake")] | ||
Snake, | ||
} | ||
|
||
impl NameConversion { | ||
pub fn transform(&self, name: &str) -> String { | ||
match self { | ||
NameConversion::LowerCamel => name.to_lower_camel_case(), | ||
NameConversion::UpperCamel => name.to_upper_camel_case(), | ||
NameConversion::Snake => name.to_snake_case(), | ||
NameConversion::AsIs => name.to_string(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ | |
"concurrentify", | ||
"Consolas", | ||
"consts", | ||
"Convertion", | ||
"cpus", | ||
"csspart", | ||
"ctxt", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/core/src/config/normalize-config/normalize-css.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { CUSTOM_KEYS } from '../constants.js'; | ||
import { ResolvedCompilation, UserConfig } from '../types.js'; | ||
|
||
export function normalizeCss( | ||
config: UserConfig, | ||
resolvedCompilation: ResolvedCompilation | ||
) { | ||
if (config.compilation?.css?.modules) { | ||
normalizeCssModules(config, resolvedCompilation); | ||
} | ||
} | ||
|
||
function normalizeCssModules( | ||
config: UserConfig, | ||
resolvedCompilation: ResolvedCompilation | ||
) { | ||
if (config.compilation.css.modules.localsConversion) { | ||
const localsConvention = config.compilation.css.modules.localsConversion; | ||
delete resolvedCompilation.css.modules.localsConversion; | ||
if (typeof localsConvention === 'string') { | ||
resolvedCompilation.custom[CUSTOM_KEYS.css_locals_conversion] = | ||
JSON.stringify(localsConvention); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters