Skip to content

Commit b5d3788

Browse files
committed
feat(css): experimenting with css-modules base
1 parent 5edc7ef commit b5d3788

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

lib/CssModulesPlugin.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const CssParser = require("./CssParser");
2+
3+
class CssModulesPlugin {
4+
apply(compiler) {
5+
compiler.hooks.compilation.tap("CssModulesPlugin", (compilation, { normalModuleFactory }) => {
6+
normalModuleFactory.hooks.createParser.for("css/experimental").tap("CssModulesPlugin", () => {
7+
return new CssParser();
8+
});
9+
});
10+
}
11+
}
12+
13+
module.exports = CssModulesPlugin;

lib/CssParser.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const Tapable = require("tapable").Tapable;
2+
const { Parser } = require("postcss");
3+
4+
class CssParser extends Tapable {
5+
constructor(options) {
6+
super();
7+
this.hooks = {};
8+
this.options = options;
9+
}
10+
11+
parse(source, state, callback) {
12+
// TODO parse Css AST, identify/extract dependencies
13+
// TODO determine sigil for lazy-loading? @import?
14+
// TODO
15+
16+
const ast = Parser.parse(source);
17+
console.log(ast);
18+
}
19+
}
20+
21+
module.exports = CssParser;

lib/WebpackOptionsApply.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const OptionsApply = require("./OptionsApply");
99
const JavascriptModulesPlugin = require("./JavascriptModulesPlugin");
1010
const JsonModulesPlugin = require("./JsonModulesPlugin");
1111
const WebAssemblyModulesPlugin = require("./WebAssemblyModulesPlugin");
12+
const CssModulesPlugin = require("./CssModulesPlugin");
1213

1314
const LoaderTargetPlugin = require("./LoaderTargetPlugin");
1415
const FunctionModulePlugin = require("./FunctionModulePlugin");
@@ -257,7 +258,8 @@ class WebpackOptionsApply extends OptionsApply {
257258
compiler.apply(
258259
new JavascriptModulesPlugin(),
259260
new JsonModulesPlugin(),
260-
new WebAssemblyModulesPlugin()
261+
new WebAssemblyModulesPlugin(),
262+
new CssModulesPlugin()
261263
);
262264

263265
compiler.apply(new EntryOptionPlugin());

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"memory-fs": "~0.4.1",
1717
"mkdirp": "~0.5.0",
1818
"node-libs-browser": "^2.0.0",
19+
"postcss": "^6.0.14",
1920
"schema-utils": "^0.4.2",
2021
"source-map": "^0.5.3",
2122
"tapable": "^1.0.0-beta.5",

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4363,7 +4363,7 @@ postcss@^5.0.10, postcss@^5.0.11, postcss@^5.0.12, postcss@^5.0.13, postcss@^5.0
43634363
source-map "^0.5.6"
43644364
supports-color "^3.2.3"
43654365

4366-
postcss@^6.0.1:
4366+
postcss@^6.0.1, postcss@^6.0.14:
43674367
version "6.0.14"
43684368
resolved "https://registry.yarnpkg.com/postcss/-/postcss-6.0.14.tgz#5534c72114739e75d0afcf017db853099f562885"
43694369
dependencies:

0 commit comments

Comments
 (0)