postcss-modules 4.3.1 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +19 -0
- package/CHANGELOG.md +90 -50
- package/README.md +77 -77
- package/build/FileSystemLoader.js +140 -0
- package/build/{css-loader-core/parser.js → Parser.js} +22 -15
- package/build/fs.js +24 -0
- package/build/index.js +8 -174
- package/build/localsConvention.js +47 -0
- package/build/pluginFactory.js +107 -0
- package/build/saveJSON.js +5 -2
- package/build/scoping.js +77 -0
- package/build/{unquote/index.js → unquote.js} +4 -2
- package/index.d.ts +24 -36
- package/package.json +8 -7
- package/build/behaviours.js +0 -50
- package/build/css-loader-core/loader.js +0 -121
- package/build/generateScopedName.js +0 -20
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
extends: "eslint:recommended",
|
|
3
|
+
parserOptions: {
|
|
4
|
+
sourceType: "module",
|
|
5
|
+
babelOptions: {
|
|
6
|
+
cwd: __dirname
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
env: {
|
|
10
|
+
node: true,
|
|
11
|
+
es6: true,
|
|
12
|
+
"jest/globals": true,
|
|
13
|
+
},
|
|
14
|
+
parser: "@babel/eslint-parser",
|
|
15
|
+
plugins: ["jest"],
|
|
16
|
+
rules: {
|
|
17
|
+
"import/no-extraneous-dependencies": 0,
|
|
18
|
+
},
|
|
19
|
+
};
|
package/CHANGELOG.md
CHANGED
|
@@ -1,186 +1,226 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 6.0.0
|
|
4
|
+
|
|
5
|
+
### Breaking
|
|
6
|
+
|
|
7
|
+
The `resolve` option has two parameters now and can return `null`. Thanks to Rene Haas (@KingSora)
|
|
8
|
+
https://github.com/madyankin/postcss-modules/commit/86d8135cb5014d0b2848ef395608ee74d82bd179
|
|
9
|
+
|
|
10
|
+
Parameters:
|
|
11
|
+
|
|
12
|
+
- `file` — a module we want to resolve
|
|
13
|
+
- `importer` — the file that imports the module we want to resolve
|
|
14
|
+
|
|
15
|
+
Return value: `string | null | Promise<string | null>`
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
postcss([
|
|
19
|
+
require("postcss-modules")({
|
|
20
|
+
resolve: function (file, importer) {
|
|
21
|
+
return path.resolve(
|
|
22
|
+
path.dirname(importer),
|
|
23
|
+
file.replace(/^@/, process.cwd()
|
|
24
|
+
);
|
|
25
|
+
},
|
|
26
|
+
}),
|
|
27
|
+
]);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
- #140 "'Failed to obtain root' error on Windows" fixed by Pierre LeMoine (@DrInfiniteExplorer) https://github.com/madyankin/postcss-modules/pull/144
|
|
33
|
+
|
|
34
|
+
### Improved
|
|
35
|
+
|
|
36
|
+
- `icss-replace-symbols` replaced with with `icss-utils` by Jason Quense (@jquense). The updated replacer works better and will replace values in selectors, which didn't work until now. https://github.com/madyankin/postcss-modules/pull/145
|
|
37
|
+
|
|
38
|
+
## 5.0.0
|
|
39
|
+
|
|
40
|
+
- Fixed `composes` on Windows by @sapphi-red https://github.com/madyankin/postcss-modules/pull/135
|
|
41
|
+
- Updated Babel to v7 by @sapphi-red. Minimal supported version of Node.js is 10 from now https://github.com/madyankin/postcss-modules/pull/134
|
|
42
|
+
|
|
3
43
|
## 4.3.1
|
|
4
44
|
|
|
5
|
-
-
|
|
45
|
+
- Fixed errors when using shorthand selectors by Felix Bruns (@fxb) https://github.com/madyankin/postcss-modules/pull/130
|
|
6
46
|
|
|
7
47
|
## 4.3.0
|
|
8
48
|
|
|
9
|
-
-
|
|
49
|
+
- Updated the `generic-names` dependency to reduce packages size by Bogdan Chadkin (@TrySound) https://github.com/madyankin/postcss-modules/pull/129
|
|
10
50
|
|
|
11
51
|
## 4.2.2
|
|
12
52
|
|
|
13
|
-
-
|
|
53
|
+
- Fix the build
|
|
14
54
|
|
|
15
55
|
## 4.2.1
|
|
16
56
|
|
|
17
|
-
-
|
|
57
|
+
- Fixed the `resolve` option behaviour by @kamilic https://github.com/madyankin/postcss-modules/pull/127
|
|
18
58
|
|
|
19
59
|
## 4.2.0
|
|
20
60
|
|
|
21
|
-
-
|
|
61
|
+
- Added the `resolve` option to configure lookup paths for composes/from by @kamilic https://github.com/madyankin/postcss-modules/pull/126
|
|
22
62
|
|
|
23
63
|
## 4.1.3
|
|
24
64
|
|
|
25
|
-
-
|
|
65
|
+
- Fixed package contents
|
|
26
66
|
|
|
27
67
|
## 4.1.1
|
|
28
68
|
|
|
29
|
-
-
|
|
69
|
+
- Fixed TypeScript typings by Shuman Lim (@origin-master) https://github.com/madyankin/postcss-modules/pull/124
|
|
30
70
|
|
|
31
71
|
## 4.1.0
|
|
32
72
|
|
|
33
|
-
-
|
|
73
|
+
- Added TypeScript typings by Shuman Lim (@origin-master) https://github.com/madyankin/postcss-modules/pull/123
|
|
34
74
|
|
|
35
75
|
## 4.0.0
|
|
36
76
|
|
|
37
|
-
-
|
|
77
|
+
- Upgraded to PostCSS 8 by Evan You (@yyx990803) https://github.com/css-modules/postcss-modules/pull/114
|
|
38
78
|
|
|
39
79
|
## 3.2.2
|
|
40
80
|
|
|
41
81
|
### Fixed
|
|
42
82
|
|
|
43
|
-
-
|
|
83
|
+
- Fixed user plugins order by Tom Jenkinson (@tjenkinson) https://github.com/css-modules/postcss-modules/pull/112
|
|
44
84
|
|
|
45
85
|
## 3.2.1
|
|
46
86
|
|
|
47
87
|
### Fixed
|
|
48
88
|
|
|
49
|
-
-
|
|
89
|
+
- Fixed an issue when some plugins were running multiple times by Tom Jenkinson (@tjenkinson) https://github.com/css-modules/postcss-modules/pull/111
|
|
50
90
|
|
|
51
91
|
## 3.2.0
|
|
52
92
|
|
|
53
93
|
### Changed
|
|
54
94
|
|
|
55
|
-
-
|
|
95
|
+
- [`localsConvention` option] now supports a custom function `(originalClassName: string, generatedClassName: string, inputFile: string) => className: string` by Gregory Waxman (@Akkuma) https://github.com/css-modules/postcss-modules/pull/109
|
|
56
96
|
|
|
57
97
|
## 3.1.0
|
|
58
98
|
|
|
59
99
|
### Added
|
|
60
100
|
|
|
61
|
-
-
|
|
101
|
+
- Added `exportGlobals` option
|
|
62
102
|
|
|
63
103
|
## 3.0.0
|
|
64
104
|
|
|
65
105
|
### Changed
|
|
66
106
|
|
|
67
|
-
-
|
|
68
|
-
-
|
|
107
|
+
- Dropped `css-modules-loader-core` dependency
|
|
108
|
+
- [Upgraded all the dependencies](https://github.com/css-modules/postcss-modules/pull/108)
|
|
69
109
|
|
|
70
110
|
### Breaking changes
|
|
71
111
|
|
|
72
|
-
-
|
|
112
|
+
- Dropped support for unsupported Node versions. Supported versions are 10, 12 and 14+ https://nodejs.org/en/about/releases/
|
|
73
113
|
|
|
74
114
|
## 2.0.0
|
|
75
115
|
|
|
76
116
|
### Added
|
|
77
117
|
|
|
78
|
-
-
|
|
118
|
+
- [`localsConvention` option](https://github.com/css-modules/postcss-modules#localsconvention) by Hamza Mihai Daniel (@allocenx) <https://github.com/css-modules/postcss-modules/pull/103>, <https://github.com/css-modules/postcss-modules/issues/93>
|
|
79
119
|
|
|
80
120
|
### Breaking changes
|
|
81
121
|
|
|
82
|
-
-
|
|
122
|
+
- `camelCase` camelCase removed, use the [`localsConvention` option](https://github.com/css-modules/postcss-modules#localsconvention) instead.
|
|
83
123
|
|
|
84
124
|
## 1.5.0
|
|
85
125
|
|
|
86
|
-
-
|
|
126
|
+
- Added `hashPrefix` option by Jesse Thomson (@jessethomson) <https://github.com/css-modules/postcss-modules/pull/98>
|
|
87
127
|
|
|
88
128
|
## 1.4.1
|
|
89
129
|
|
|
90
|
-
-
|
|
130
|
+
- Rebublished the previous release. Sorry :(
|
|
91
131
|
|
|
92
132
|
## 1.4.0
|
|
93
133
|
|
|
94
|
-
-
|
|
134
|
+
- Added export for other plugins by Evilebot Tnawi (@evilebottnawi) <https://github.com/css-modules/postcss-modules/pull/88>, <https://github.com/css-modules/postcss-modules/issues/29>
|
|
95
135
|
|
|
96
136
|
## 1.3.1
|
|
97
137
|
|
|
98
|
-
-
|
|
138
|
+
- Move dev tools to devDependecies by Anton Khlynovskiy (@ubzey) <https://github.com/css-modules/postcss-modules/pull/85>
|
|
99
139
|
|
|
100
140
|
## 1.3.0
|
|
101
141
|
|
|
102
|
-
-
|
|
103
|
-
-
|
|
142
|
+
- Updated dependecies
|
|
143
|
+
- Added prettier to format code
|
|
104
144
|
|
|
105
145
|
## 1.2.0
|
|
106
146
|
|
|
107
|
-
-
|
|
147
|
+
- Added option to transform classes to camelCase by Igor Ribeiro (@igor-ribeiro) <https://github.com/css-modules/postcss-modules/pull/82>
|
|
108
148
|
|
|
109
149
|
## 1.1.0
|
|
110
150
|
|
|
111
|
-
-
|
|
151
|
+
- Added ability to transmit outputFileName into getJSON by @lutien <https://github.com/css-modules/postcss-modules/pull/72>
|
|
112
152
|
|
|
113
153
|
## 1.0.0
|
|
114
154
|
|
|
115
|
-
-
|
|
116
|
-
-
|
|
155
|
+
- Dropped support for Node < 6
|
|
156
|
+
- Updated dependencies
|
|
117
157
|
|
|
118
158
|
## 0.8.0
|
|
119
159
|
|
|
120
|
-
-
|
|
160
|
+
- Updated PostCSS to 6 by Alexey Litvinov (@sullenor) <https://github.com/css-modules/postcss-modules/pull/65>
|
|
121
161
|
|
|
122
162
|
## 0.7.1
|
|
123
163
|
|
|
124
|
-
-
|
|
164
|
+
- Allowed empty string as opts.root by Sharon Rolel (@Mosho1) <https://github.com/css-modules/postcss-modules/pull/56>
|
|
125
165
|
|
|
126
166
|
## 0.7.0
|
|
127
167
|
|
|
128
|
-
-
|
|
168
|
+
- Allow async getJSON by Philipp A. (@flying-sheep) <https://github.com/css-modules/postcss-modules/pull/59>
|
|
129
169
|
|
|
130
170
|
## 0.6.4
|
|
131
171
|
|
|
132
|
-
-
|
|
172
|
+
- Added the `root` option to pass the root path by Sharon Rolel (@Mosho1) (<https://github.com/css-modules/postcss-modules/pull/55>)
|
|
133
173
|
|
|
134
174
|
## 0.6.3
|
|
135
175
|
|
|
136
|
-
-
|
|
176
|
+
- Fixed regression in `isValidBehaviour` function (<https://github.com/css-modules/postcss-modules/issues/53>)
|
|
137
177
|
|
|
138
178
|
## 0.6.2
|
|
139
179
|
|
|
140
|
-
-
|
|
180
|
+
- Refactored `getDefaultPluginsList` function
|
|
141
181
|
|
|
142
182
|
## 0.6.1
|
|
143
183
|
|
|
144
|
-
-
|
|
184
|
+
- Fixed `generateScopedName` bug with multiple postcss-modules instances (<https://github.com/css-modules/postcss-modules/issues/37>)
|
|
145
185
|
|
|
146
186
|
## 0.6.0
|
|
147
187
|
|
|
148
|
-
-
|
|
149
|
-
-
|
|
188
|
+
- Added `globalModulePaths` option (Thanks to @pospi).
|
|
189
|
+
- Refactored all the things.
|
|
150
190
|
|
|
151
191
|
## 0.5.2
|
|
152
192
|
|
|
153
|
-
-
|
|
193
|
+
- Updated dependencies
|
|
154
194
|
|
|
155
195
|
## 0.5.1
|
|
156
196
|
|
|
157
|
-
-
|
|
197
|
+
- Fixed sorting for composed dependencies by Josh Johnston (@joshwnj) (<https://github.com/css-modules/postcss-modules/issues/38>)
|
|
158
198
|
|
|
159
199
|
## 0.5.0
|
|
160
200
|
|
|
161
|
-
-
|
|
162
|
-
-
|
|
163
|
-
-
|
|
201
|
+
- Added `scopeBehaviour` option (<https://github.com/css-modules/postcss-modules/issues/22>)
|
|
202
|
+
- Added ability to pass a string to `generateScopedName` (<https://github.com/css-modules/postcss-modules/issues/21>)
|
|
203
|
+
- Updated dependencies
|
|
164
204
|
|
|
165
205
|
## 0.4.1
|
|
166
206
|
|
|
167
|
-
-
|
|
207
|
+
- Fixed processing errors capturing by Boris Serdiuk (@just-boris)
|
|
168
208
|
|
|
169
209
|
## 0.4.0
|
|
170
210
|
|
|
171
|
-
-
|
|
211
|
+
- Added support for custom loaders by Björn Brauer (@ZauberNerd)
|
|
172
212
|
|
|
173
213
|
## 0.3.0
|
|
174
214
|
|
|
175
|
-
-
|
|
176
|
-
-
|
|
215
|
+
- Fixed processing for imported CSS
|
|
216
|
+
- Added default callback for saving exported JSON
|
|
177
217
|
|
|
178
218
|
## 0.2.0
|
|
179
219
|
|
|
180
|
-
-
|
|
181
|
-
-
|
|
182
|
-
-
|
|
183
|
-
-
|
|
220
|
+
- Fixed JSON export with shallow imports (<https://github.com/outpunk/postcss-modules/issues/12>)
|
|
221
|
+
- Fixed lookup paths (<https://github.com/outpunk/postcss-modules/issues/13>)
|
|
222
|
+
- Fixed imports overriding (<https://github.com/outpunk/postcss-modules/issues/15>)
|
|
223
|
+
- Global refactoring under the hood
|
|
184
224
|
|
|
185
225
|
## 0.1.3
|
|
186
226
|
|
package/README.md
CHANGED
|
@@ -5,13 +5,6 @@ A [PostCSS] plugin to use [CSS Modules] everywhere. Not only at the client side.
|
|
|
5
5
|
[postcss]: https://github.com/postcss/postcss
|
|
6
6
|
[css modules]: https://github.com/css-modules/css-modules
|
|
7
7
|
|
|
8
|
-
## Support the developer
|
|
9
|
-
|
|
10
|
-
I maintain the plugin in my free time, so I don't receive any payment for this work.
|
|
11
|
-
To have better docs, new features and integrations with frameworks, you can [support me on Patreon](https://www.patreon.com/bePatron?u=25976212).
|
|
12
|
-
|
|
13
|
-
The sponsors are listed [below in the README](#sponsors)
|
|
14
|
-
|
|
15
8
|
## What is this?
|
|
16
9
|
|
|
17
10
|
For example, you have the following CSS:
|
|
@@ -19,26 +12,26 @@ For example, you have the following CSS:
|
|
|
19
12
|
```css
|
|
20
13
|
/* styles.css */
|
|
21
14
|
:global .page {
|
|
22
|
-
|
|
15
|
+
padding: 20px;
|
|
23
16
|
}
|
|
24
17
|
|
|
25
18
|
.title {
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
composes: title from "./mixins.css";
|
|
20
|
+
color: green;
|
|
28
21
|
}
|
|
29
22
|
|
|
30
23
|
.article {
|
|
31
|
-
|
|
24
|
+
font-size: 16px;
|
|
32
25
|
}
|
|
33
26
|
|
|
34
27
|
/* mixins.css */
|
|
35
28
|
.title {
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
color: black;
|
|
30
|
+
font-size: 40px;
|
|
38
31
|
}
|
|
39
32
|
|
|
40
33
|
.title:hover {
|
|
41
|
-
|
|
34
|
+
color: red;
|
|
42
35
|
}
|
|
43
36
|
```
|
|
44
37
|
|
|
@@ -46,24 +39,24 @@ After the transformation it will become like this:
|
|
|
46
39
|
|
|
47
40
|
```css
|
|
48
41
|
._title_116zl_1 {
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
color: black;
|
|
43
|
+
font-size: 40px;
|
|
51
44
|
}
|
|
52
45
|
|
|
53
46
|
._title_116zl_1:hover {
|
|
54
|
-
|
|
47
|
+
color: red;
|
|
55
48
|
}
|
|
56
49
|
|
|
57
50
|
.page {
|
|
58
|
-
|
|
51
|
+
padding: 20px;
|
|
59
52
|
}
|
|
60
53
|
|
|
61
54
|
._title_xkpkl_5 {
|
|
62
|
-
|
|
55
|
+
color: green;
|
|
63
56
|
}
|
|
64
57
|
|
|
65
58
|
._article_xkpkl_10 {
|
|
66
|
-
|
|
59
|
+
font-size: 16px;
|
|
67
60
|
}
|
|
68
61
|
```
|
|
69
62
|
|
|
@@ -71,8 +64,8 @@ And the plugin will give you a JSON object for transformed classes:
|
|
|
71
64
|
|
|
72
65
|
```json
|
|
73
66
|
{
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
"title": "_title_xkpkl_5 _title_116zl_1",
|
|
68
|
+
"article": "_article_xkpkl_10"
|
|
76
69
|
}
|
|
77
70
|
```
|
|
78
71
|
|
|
@@ -86,14 +79,14 @@ use the `getJSON` callback. For example, save data about classes into a correspo
|
|
|
86
79
|
|
|
87
80
|
```js
|
|
88
81
|
postcss([
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
82
|
+
require("postcss-modules")({
|
|
83
|
+
getJSON: function (cssFileName, json, outputFileName) {
|
|
84
|
+
var path = require("path");
|
|
85
|
+
var cssName = path.basename(cssFileName, ".css");
|
|
86
|
+
var jsonFileName = path.resolve("./build/" + cssName + ".json");
|
|
87
|
+
fs.writeFileSync(jsonFileName, JSON.stringify(json));
|
|
88
|
+
},
|
|
89
|
+
}),
|
|
97
90
|
]);
|
|
98
91
|
```
|
|
99
92
|
|
|
@@ -106,9 +99,9 @@ this behaviour using the `scopeBehaviour` option:
|
|
|
106
99
|
|
|
107
100
|
```js
|
|
108
101
|
postcss([
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
102
|
+
require("postcss-modules")({
|
|
103
|
+
scopeBehaviour: "global", // can be 'global' or 'local',
|
|
104
|
+
}),
|
|
112
105
|
]);
|
|
113
106
|
```
|
|
114
107
|
|
|
@@ -127,16 +120,16 @@ To generate custom classes, use the `generateScopedName` callback:
|
|
|
127
120
|
|
|
128
121
|
```js
|
|
129
122
|
postcss([
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
123
|
+
require("postcss-modules")({
|
|
124
|
+
generateScopedName: function (name, filename, css) {
|
|
125
|
+
var path = require("path");
|
|
126
|
+
var i = css.indexOf("." + name);
|
|
127
|
+
var line = css.substr(0, i).split(/[\r\n]/).length;
|
|
128
|
+
var file = path.basename(filename, ".css");
|
|
129
|
+
|
|
130
|
+
return "_" + file + "_" + line + "_" + name;
|
|
131
|
+
},
|
|
132
|
+
}),
|
|
140
133
|
]);
|
|
141
134
|
```
|
|
142
135
|
|
|
@@ -145,9 +138,9 @@ Or just pass an interpolated string to the `generateScopedName` option
|
|
|
145
138
|
|
|
146
139
|
```js
|
|
147
140
|
postcss([
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
141
|
+
require("postcss-modules")({
|
|
142
|
+
generateScopedName: "[name]__[local]___[hash:base64:5]",
|
|
143
|
+
}),
|
|
151
144
|
]);
|
|
152
145
|
```
|
|
153
146
|
|
|
@@ -155,10 +148,10 @@ It's possible to add custom hash to generate more unique classes using the `hash
|
|
|
155
148
|
|
|
156
149
|
```js
|
|
157
150
|
postcss([
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
151
|
+
require("postcss-modules")({
|
|
152
|
+
generateScopedName: "[name]__[local]___[hash:base64:5]",
|
|
153
|
+
hashPrefix: "prefix",
|
|
154
|
+
}),
|
|
162
155
|
]);
|
|
163
156
|
```
|
|
164
157
|
|
|
@@ -168,9 +161,9 @@ If you need to export global names via the JSON object along with the local ones
|
|
|
168
161
|
|
|
169
162
|
```js
|
|
170
163
|
postcss([
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
164
|
+
require("postcss-modules")({
|
|
165
|
+
exportGlobals: true,
|
|
166
|
+
}),
|
|
174
167
|
]);
|
|
175
168
|
```
|
|
176
169
|
|
|
@@ -180,9 +173,9 @@ If you need, you can pass a custom loader (see [FileSystemLoader] for example):
|
|
|
180
173
|
|
|
181
174
|
```js
|
|
182
175
|
postcss([
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
176
|
+
require("postcss-modules")({
|
|
177
|
+
Loader: CustomLoader,
|
|
178
|
+
}),
|
|
186
179
|
]);
|
|
187
180
|
```
|
|
188
181
|
|
|
@@ -214,22 +207,29 @@ In lieu of a string, a custom function can generate the exported class names.
|
|
|
214
207
|
|
|
215
208
|
### Resolve path alias
|
|
216
209
|
|
|
217
|
-
You can rewrite paths for `composes/from` by using `resolve`
|
|
210
|
+
You can rewrite paths for `composes/from` by using the `resolve` option.
|
|
218
211
|
It's useful when you need to resolve custom path alias.
|
|
219
212
|
|
|
213
|
+
Parameters:
|
|
214
|
+
|
|
215
|
+
- `file` — a module we want to resolve
|
|
216
|
+
- `importer` — the file that imports the module we want to resolve
|
|
217
|
+
|
|
218
|
+
Return value: `string | null | Promise<string | null>`
|
|
219
|
+
|
|
220
220
|
```js
|
|
221
221
|
postcss([
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
222
|
+
require("postcss-modules")({
|
|
223
|
+
resolve: function (file, importer) {
|
|
224
|
+
return path.resolve(
|
|
225
|
+
path.dirname(importer),
|
|
226
|
+
file.replace(/^@/, process.cwd()
|
|
227
|
+
);
|
|
228
|
+
},
|
|
229
|
+
}),
|
|
227
230
|
]);
|
|
228
231
|
```
|
|
229
232
|
|
|
230
|
-
`resolve` may also return a `Promise<string>`.
|
|
231
|
-
|
|
232
|
-
|
|
233
233
|
## Integration with templates
|
|
234
234
|
|
|
235
235
|
The plugin only transforms CSS classes to CSS modules.
|
|
@@ -240,8 +240,8 @@ Assume you've saved project's CSS modules in `cssModules.json`:
|
|
|
240
240
|
|
|
241
241
|
```json
|
|
242
242
|
{
|
|
243
|
-
|
|
244
|
-
|
|
243
|
+
"title": "_title_xkpkl_5 _title_116zl_1",
|
|
244
|
+
"article": "_article_xkpkl_10"
|
|
245
245
|
}
|
|
246
246
|
```
|
|
247
247
|
|
|
@@ -268,7 +268,7 @@ And you'll get the following HTML:
|
|
|
268
268
|
```html
|
|
269
269
|
<h1 class="_title_xkpkl_5 _title_116zl_1">postcss-modules</h1>
|
|
270
270
|
<article class="_article_xkpkl_10">
|
|
271
|
-
|
|
271
|
+
A PostCSS plugin to use CSS Modules everywhere
|
|
272
272
|
</article>
|
|
273
273
|
```
|
|
274
274
|
|
|
@@ -285,7 +285,7 @@ Here is our template `about.html`:
|
|
|
285
285
|
```html
|
|
286
286
|
<h1 css-module="title">postcss-modules</h1>
|
|
287
287
|
<article css-module="article">
|
|
288
|
-
|
|
288
|
+
A PostCSS plugin to use CSS Modules everywhere
|
|
289
289
|
</article>
|
|
290
290
|
```
|
|
291
291
|
|
|
@@ -298,20 +298,20 @@ var posthtmlCssModules = require("posthtml-css-modules");
|
|
|
298
298
|
var template = fs.readFileSync("./about.html", "utf8");
|
|
299
299
|
|
|
300
300
|
posthtml([posthtmlCssModules("./cssModules.json")])
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
301
|
+
.process(template)
|
|
302
|
+
.then(function (result) {
|
|
303
|
+
console.log(result.html);
|
|
304
|
+
});
|
|
305
305
|
```
|
|
306
306
|
|
|
307
|
-
(for using other build systems please check [the documentation of PostHTML](https://github.com/posthtml/posthtml/blob/master/
|
|
307
|
+
(for using other build systems please check [the documentation of PostHTML](https://github.com/posthtml/posthtml/blob/master/readme.md))
|
|
308
308
|
|
|
309
309
|
And you'll get the following HTML:
|
|
310
310
|
|
|
311
311
|
```html
|
|
312
312
|
<h1 class="_title_xkpkl_5 _title_116zl_1">postcss-modules</h1>
|
|
313
313
|
<article class="_article_xkpkl_10">
|
|
314
|
-
|
|
314
|
+
A PostCSS plugin to use CSS Modules everywhere
|
|
315
315
|
</article>
|
|
316
316
|
```
|
|
317
317
|
|
|
@@ -327,6 +327,6 @@ npm install --save-dev postcss postcss-modules
|
|
|
327
327
|
|
|
328
328
|
[filesystemloader]: https://github.com/css-modules/css-modules-loader-core/blob/master/src/file-system-loader.js
|
|
329
329
|
|
|
330
|
-
|
|
331
330
|
## Sponsors
|
|
332
|
-
|
|
331
|
+
|
|
332
|
+
- Dmitry Olyenyov
|