-
-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat; support css module name coversion
- Loading branch information
1 parent
5f0c02d
commit c6d6828
Showing
13 changed files
with
129 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
26 changes: 26 additions & 0 deletions
26
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,26 @@ | ||
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); | ||
} | ||
} | ||
console.log(resolvedCompilation.custom); | ||
} |
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