Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16577 from ahabhgk/type-css-auto
feat: 'css/auto' as a css module type
- Loading branch information
Showing
16 changed files
with
102 additions
and
4 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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"$ref": "../../WebpackOptions.json#/definitions/CssParserOptions" | ||
"$ref": "../../WebpackOptions.json#/definitions/CssGeneratorOptions" | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"$ref": "../../WebpackOptions.json#/definitions/CssGeneratorOptions" | ||
"$ref": "../../WebpackOptions.json#/definitions/CssParserOptions" | ||
} |
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,2 @@ | ||
export const red = '#f00'; | ||
export const green = '#0f0'; |
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 @@ | ||
body { | ||
color: green; | ||
} |
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,17 @@ | ||
import "./global.less"; | ||
import * as style1 from "./style1.module.less"; | ||
import * as style2 from "./style2.modules.less"; | ||
import * as style3 from "./style3.module.less!=!./loader.js!./style3.module.js"; | ||
import * as style4 from "./style4.module.less!=!./loader.js!./style4.js"; | ||
import * as style5 from "./style5.module.css!=!./loader.js!./style4.js"; | ||
|
||
it("should correctly compile css/auto", () => { | ||
const style = getComputedStyle(document.body); | ||
expect(style.getPropertyValue("color")).toBe(" green"); | ||
expect(style.getPropertyValue("background")).toBe(" #f00"); | ||
expect(style1.class).toBe("./style1.module.less-class"); | ||
expect(style2.class).toBe("./style2.modules.less-class"); | ||
expect(style3.class).toBe("./style3.module.less!=!./loader.js!./style3.module.js-class"); | ||
expect(style4.class).toBe("./style4.module.less!=!./loader.js!./style4.js-class"); | ||
expect(style5.class).toBe("./style5.module.css!=!./loader.js!./style4.js-class"); | ||
}); |
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,8 @@ | ||
/** @type {import("../../../../").PitchLoaderDefinitionFunction} */ | ||
exports.pitch = async function (remaining) { | ||
const result = await this.importModule( | ||
this.resourcePath + '.webpack[javascript/auto]' + '!=!' + remaining, { | ||
publicPath: '' | ||
}); | ||
return result.default || result; | ||
}; |
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 @@ | ||
.class { | ||
color: red; | ||
} |
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 @@ | ||
.class { | ||
color: blue; | ||
} |
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,6 @@ | ||
import { green, red } from './colors.js'; | ||
|
||
export default ` | ||
.class { color: ${green}; } | ||
body { background: ${red}; } | ||
`; |
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,6 @@ | ||
import { green, red } from './colors.js'; | ||
|
||
export default ` | ||
.class { color: ${green}; } | ||
body { background: ${red}; } | ||
`; |
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 @@ | ||
.class { | ||
color: blue; | ||
} |
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,8 @@ | ||
module.exports = { | ||
moduleScope(scope) { | ||
const link = scope.window.document.createElement("link"); | ||
link.rel = "stylesheet"; | ||
link.href = "bundle0.css"; | ||
scope.window.document.head.appendChild(link); | ||
} | ||
}; |
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,17 @@ | ||
/** @type {import("../../../../types").Configuration} */ | ||
module.exports = { | ||
target: "web", | ||
mode: "development", | ||
experiments: { | ||
css: true | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.less$/, | ||
use: "less-loader", | ||
type: "css/auto" | ||
} | ||
] | ||
} | ||
}; |