-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: less support "globalVars" (#1465)
* feat: less support globalVars * test: add globalVars test case * test case text * docs * test case
- Loading branch information
Showing
14 changed files
with
118 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default { | ||
mfsu: false, | ||
mako: {}, | ||
lessLoader: { | ||
globalVars: { | ||
globalColorInConfig: '#ff0033', | ||
hack: 'true; @import "./var.less";', | ||
overrideInConfig: '#000012', | ||
'@useAtPrefix': '#000013', | ||
}, | ||
}, | ||
}; |
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,56 @@ | ||
const assert = require("assert"); | ||
const { parseBuildResult, moduleReg } = require("../../../scripts/test-utils"); | ||
const { files } = parseBuildResult(__dirname); | ||
|
||
/** @type string */ | ||
let content = files["pages_index_tsx-async.css"]; | ||
|
||
// remove sourcemap | ||
content = content.slice(0, content.indexOf("/*")).trim(); | ||
|
||
// 分割成单条 rule | ||
// .a{...} | ||
// .b{...} | ||
let cssRules = content | ||
.split(".") | ||
.filter((item) => !!item) | ||
.map((item) => "." + item.replace(/\s/g, "")); | ||
|
||
/** @type {Record<string, string>} */ | ||
let cssDecls = cssRules.reduce((pre, cur) => { | ||
let splitIndex = cur.indexOf("{"); | ||
let selector = cur.slice(0, splitIndex); | ||
let decl = cur.slice(splitIndex); | ||
pre[selector] = decl; | ||
|
||
return pre; | ||
}, {}); | ||
|
||
assert( | ||
cssDecls[".normal"].includes("color:#ff0000;"), | ||
"should available globalVars" | ||
); | ||
assert( | ||
cssDecls[".override"].includes("color:#ff0022;"), | ||
"should available override globalVars" | ||
); | ||
assert( | ||
cssDecls[".inConfig"].includes("color:#ff0033;"), | ||
"should available globalVars in .umirc config" | ||
); | ||
assert( | ||
cssDecls[".overrideInConfig"].includes("color:#000012"), | ||
"should available override globalVars in .umirc config" | ||
); | ||
assert( | ||
cssDecls[".useAtPrefix"].includes("color:#000013"), | ||
"should available use '@' prefix" | ||
); | ||
assert( | ||
cssDecls[".normalA"].includes("color:#ff0000;"), | ||
"should available globalVars in all less files" | ||
); | ||
assert( | ||
cssDecls[".normalB"].includes("color:#ff0000;"), | ||
"should available globalVars in all less files" | ||
); |
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,3 @@ | ||
.normalA { | ||
color: @primaryColor; | ||
} |
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,3 @@ | ||
.normalB { | ||
color: @primaryColor; | ||
} |
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,21 @@ | ||
@testOverride: #ff0022; | ||
|
||
.normal { | ||
color: @primaryColor; | ||
} | ||
|
||
.override { | ||
color: @testOverride; | ||
} | ||
|
||
.inConfig { | ||
color: @globalColorInConfig; | ||
} | ||
|
||
.overrideInConfig { | ||
color: @overrideInConfig; | ||
} | ||
|
||
.useAtPrefix { | ||
color: @useAtPrefix; | ||
} |
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,3 @@ | ||
import React from 'react'; | ||
import './index.less'; | ||
export default () => <div>1</div>; |
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,3 @@ | ||
@primaryColor: #ff0000; | ||
@testOverride: #ff0011; | ||
@overrideInConfig: #000011; |
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