Skip to content

Commit 3a96a3d

Browse files
refactor: the hashPrefix option was renamed to the localIdentHashPrefix option (#1118)
BREAKING CHANGE: the `hashPrefix` option was renamed to the `localIdentHashPrefix` option
1 parent 0080f88 commit 3a96a3d

File tree

6 files changed

+45
-44
lines changed

6 files changed

+45
-44
lines changed

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,13 @@ module.exports = {
528528
options: {
529529
modules: {
530530
mode: 'local',
531+
auto: true,
531532
exportGlobals: true,
532533
localIdentName: '[path][name]__[local]--[hash:base64:5]',
533-
localsConvention: 'camelCase',
534534
context: path.resolve(__dirname, 'src'),
535-
hashPrefix: 'my-custom-hash',
535+
localIdentHashPrefix: 'my-custom-hash',
536536
namedExport: true,
537+
localsConvention: 'camelCase',
537538
exportOnlyLocals: false,
538539
},
539540
},
@@ -834,7 +835,7 @@ module.exports = {
834835
};
835836
```
836837

837-
##### `hashPrefix`
838+
##### `localIdentHashPrefix`
838839

839840
Type: `String`
840841
Default: `undefined`
@@ -852,7 +853,7 @@ module.exports = {
852853
loader: 'css-loader',
853854
options: {
854855
modules: {
855-
hashPrefix: 'hash',
856+
localIdentHashPrefix: 'hash',
856857
},
857858
},
858859
},

src/options.json

+16-16
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@
6565
"localIdentName": {
6666
"type": "string"
6767
},
68+
"context": {
69+
"type": "string"
70+
},
71+
"localIdentHashPrefix": {
72+
"type": "string"
73+
},
6874
"localIdentRegExp": {
6975
"anyOf": [
7076
{
@@ -75,22 +81,6 @@
7581
}
7682
]
7783
},
78-
"localsConvention": {
79-
"description": "Style of exported classnames (https://github.com/webpack-contrib/css-loader#localsconvention).",
80-
"enum": [
81-
"asIs",
82-
"camelCase",
83-
"camelCaseOnly",
84-
"dashes",
85-
"dashesOnly"
86-
]
87-
},
88-
"context": {
89-
"type": "string"
90-
},
91-
"hashPrefix": {
92-
"type": "string"
93-
},
9484
"getLocalIdent": {
9585
"anyOf": [
9686
{
@@ -101,6 +91,16 @@
10191
}
10292
]
10393
},
94+
"localsConvention": {
95+
"description": "Style of exported classnames (https://github.com/webpack-contrib/css-loader#localsconvention).",
96+
"enum": [
97+
"asIs",
98+
"camelCase",
99+
"camelCaseOnly",
100+
"dashes",
101+
"dashesOnly"
102+
]
103+
},
104104
"namedExport": {
105105
"description": "Use the named export ES modules.",
106106
"type": "boolean"

src/utils.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ function getModulesOptions(rawOptions, loaderContext) {
126126
auto: true,
127127
mode: 'local',
128128
localIdentName: '[hash:base64]',
129+
localIdentHashPrefix: '',
129130
// eslint-disable-next-line no-undefined
130131
localIdentRegExp: undefined,
131132
localsConvention: 'asIs',
132133
getLocalIdent,
133-
hashPrefix: '',
134134
exportGlobals: false,
135135
namedExport: false,
136136
exportOnlyLocals: false,
@@ -246,7 +246,7 @@ function getModulesPlugins(options, loaderContext) {
246246
exportName,
247247
{
248248
context: options.modules.context,
249-
hashPrefix: options.modules.hashPrefix,
249+
hashPrefix: options.modules.localIdentHashPrefix,
250250
regExp: options.modules.localIdentRegExp,
251251
}
252252
);
@@ -259,7 +259,7 @@ function getModulesPlugins(options, loaderContext) {
259259
exportName,
260260
{
261261
context: options.modules.context,
262-
hashPrefix: options.modules.hashPrefix,
262+
hashPrefix: options.modules.localIdentHashPrefix,
263263
regExp: options.modules.localIdentRegExp,
264264
}
265265
);

test/__snapshots__/validate-options.test.js.snap

+17-17
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ exports[`validate options should throw an error on the "importLoaders" option wi
3939
exports[`validate options should throw an error on the "modules" option with "{"auto":"invalid"}" value 1`] = `
4040
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
4141
- options.modules should be one of these:
42-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, localIdentRegExp?, localsConvention?, context?, hashPrefix?, getLocalIdent?, namedExport?, exportOnlyLocals? }
42+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, context?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, localsConvention?, namedExport?, exportOnlyLocals? }
4343
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
4444
Details:
4545
* options.modules.auto should be one of these:
@@ -69,7 +69,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
6969
exports[`validate options should throw an error on the "modules" option with "{"getLocalIdent":[]}" value 1`] = `
7070
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
7171
- options.modules should be one of these:
72-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, localIdentRegExp?, localsConvention?, context?, hashPrefix?, getLocalIdent?, namedExport?, exportOnlyLocals? }
72+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, context?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, localsConvention?, namedExport?, exportOnlyLocals? }
7373
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
7474
Details:
7575
* options.modules.getLocalIdent should be one of these:
@@ -79,9 +79,9 @@ exports[`validate options should throw an error on the "modules" option with "{"
7979
* options.modules.getLocalIdent should be an instance of function."
8080
`;
8181
82-
exports[`validate options should throw an error on the "modules" option with "{"hashPrefix":true}" value 1`] = `
82+
exports[`validate options should throw an error on the "modules" option with "{"localIdentHashPrefix":true}" value 1`] = `
8383
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
84-
- options.modules.hashPrefix should be a string."
84+
- options.modules.localIdentHashPrefix should be a string."
8585
`;
8686
8787
exports[`validate options should throw an error on the "modules" option with "{"localIdentName":true}" value 1`] = `
@@ -92,7 +92,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
9292
exports[`validate options should throw an error on the "modules" option with "{"localIdentRegExp":true}" value 1`] = `
9393
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
9494
- options.modules should be one of these:
95-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, localIdentRegExp?, localsConvention?, context?, hashPrefix?, getLocalIdent?, namedExport?, exportOnlyLocals? }
95+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, context?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, localsConvention?, namedExport?, exportOnlyLocals? }
9696
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
9797
Details:
9898
* options.modules.localIdentRegExp should be one of these:
@@ -112,7 +112,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
112112
exports[`validate options should throw an error on the "modules" option with "{"mode":"globals"}" value 1`] = `
113113
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
114114
- options.modules should be one of these:
115-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, localIdentRegExp?, localsConvention?, context?, hashPrefix?, getLocalIdent?, namedExport?, exportOnlyLocals? }
115+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, context?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, localsConvention?, namedExport?, exportOnlyLocals? }
116116
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
117117
Details:
118118
* options.modules.mode should be one of these:
@@ -126,7 +126,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
126126
exports[`validate options should throw an error on the "modules" option with "{"mode":"locals"}" value 1`] = `
127127
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
128128
- options.modules should be one of these:
129-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, localIdentRegExp?, localsConvention?, context?, hashPrefix?, getLocalIdent?, namedExport?, exportOnlyLocals? }
129+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, context?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, localsConvention?, namedExport?, exportOnlyLocals? }
130130
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
131131
Details:
132132
* options.modules.mode should be one of these:
@@ -140,7 +140,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
140140
exports[`validate options should throw an error on the "modules" option with "{"mode":"pures"}" value 1`] = `
141141
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
142142
- options.modules should be one of these:
143-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, localIdentRegExp?, localsConvention?, context?, hashPrefix?, getLocalIdent?, namedExport?, exportOnlyLocals? }
143+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, context?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, localsConvention?, namedExport?, exportOnlyLocals? }
144144
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
145145
Details:
146146
* options.modules.mode should be one of these:
@@ -154,7 +154,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
154154
exports[`validate options should throw an error on the "modules" option with "{"mode":true}" value 1`] = `
155155
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
156156
- options.modules should be one of these:
157-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, localIdentRegExp?, localsConvention?, context?, hashPrefix?, getLocalIdent?, namedExport?, exportOnlyLocals? }
157+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, context?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, localsConvention?, namedExport?, exportOnlyLocals? }
158158
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
159159
Details:
160160
* options.modules.mode should be one of these:
@@ -174,53 +174,53 @@ exports[`validate options should throw an error on the "modules" option with "{"
174174
exports[`validate options should throw an error on the "modules" option with "globals" value 1`] = `
175175
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
176176
- options.modules should be one of these:
177-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, localIdentRegExp?, localsConvention?, context?, hashPrefix?, getLocalIdent?, namedExport?, exportOnlyLocals? }
177+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, context?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, localsConvention?, namedExport?, exportOnlyLocals? }
178178
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
179179
Details:
180180
* options.modules should be a boolean.
181181
* options.modules should be one of these:
182182
\\"local\\" | \\"global\\" | \\"pure\\"
183183
* options.modules should be an object:
184-
object { auto?, mode?, exportGlobals?, localIdentName?, localIdentRegExp?, localsConvention?, context?, hashPrefix?, getLocalIdent?, namedExport?, exportOnlyLocals? }"
184+
object { auto?, mode?, exportGlobals?, localIdentName?, context?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, localsConvention?, namedExport?, exportOnlyLocals? }"
185185
`;
186186
187187
exports[`validate options should throw an error on the "modules" option with "locals" value 1`] = `
188188
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
189189
- options.modules should be one of these:
190-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, localIdentRegExp?, localsConvention?, context?, hashPrefix?, getLocalIdent?, namedExport?, exportOnlyLocals? }
190+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, context?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, localsConvention?, namedExport?, exportOnlyLocals? }
191191
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
192192
Details:
193193
* options.modules should be a boolean.
194194
* options.modules should be one of these:
195195
\\"local\\" | \\"global\\" | \\"pure\\"
196196
* options.modules should be an object:
197-
object { auto?, mode?, exportGlobals?, localIdentName?, localIdentRegExp?, localsConvention?, context?, hashPrefix?, getLocalIdent?, namedExport?, exportOnlyLocals? }"
197+
object { auto?, mode?, exportGlobals?, localIdentName?, context?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, localsConvention?, namedExport?, exportOnlyLocals? }"
198198
`;
199199
200200
exports[`validate options should throw an error on the "modules" option with "pures" value 1`] = `
201201
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
202202
- options.modules should be one of these:
203-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, localIdentRegExp?, localsConvention?, context?, hashPrefix?, getLocalIdent?, namedExport?, exportOnlyLocals? }
203+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, context?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, localsConvention?, namedExport?, exportOnlyLocals? }
204204
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
205205
Details:
206206
* options.modules should be a boolean.
207207
* options.modules should be one of these:
208208
\\"local\\" | \\"global\\" | \\"pure\\"
209209
* options.modules should be an object:
210-
object { auto?, mode?, exportGlobals?, localIdentName?, localIdentRegExp?, localsConvention?, context?, hashPrefix?, getLocalIdent?, namedExport?, exportOnlyLocals? }"
210+
object { auto?, mode?, exportGlobals?, localIdentName?, context?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, localsConvention?, namedExport?, exportOnlyLocals? }"
211211
`;
212212
213213
exports[`validate options should throw an error on the "modules" option with "true" value 1`] = `
214214
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
215215
- options.modules should be one of these:
216-
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, localIdentRegExp?, localsConvention?, context?, hashPrefix?, getLocalIdent?, namedExport?, exportOnlyLocals? }
216+
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | object { auto?, mode?, exportGlobals?, localIdentName?, context?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, localsConvention?, namedExport?, exportOnlyLocals? }
217217
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
218218
Details:
219219
* options.modules should be a boolean.
220220
* options.modules should be one of these:
221221
\\"local\\" | \\"global\\" | \\"pure\\"
222222
* options.modules should be an object:
223-
object { auto?, mode?, exportGlobals?, localIdentName?, localIdentRegExp?, localsConvention?, context?, hashPrefix?, getLocalIdent?, namedExport?, exportOnlyLocals? }"
223+
object { auto?, mode?, exportGlobals?, localIdentName?, context?, localIdentHashPrefix?, localIdentRegExp?, getLocalIdent?, localsConvention?, namedExport?, exportOnlyLocals? }"
224224
`;
225225
226226
exports[`validate options should throw an error on the "sourceMap" option with "true" value 1`] = `

test/modules-option.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ describe('"modules" option', () => {
156156
const compiler = getCompiler('./modules/localIdentName/localIdentName.js', {
157157
modules: {
158158
localIdentName: '[local]--[hash]',
159-
hashPrefix: 'x',
159+
localIdentHashPrefix: 'x',
160160
},
161161
});
162162
const stats = await compile(compiler);
@@ -242,7 +242,7 @@ describe('"modules" option', () => {
242242
modules: {
243243
localIdentRegExp: 'regExp',
244244
context: 'context',
245-
hashPrefix: 'hash',
245+
localIdentHashPrefix: 'hash',
246246
getLocalIdent(loaderContext, localIdentName, localName, options) {
247247
expect(loaderContext).toBeDefined();
248248
expect(typeof localIdentName).toBe('string');

test/validate-options.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('validate options', () => {
2323
{ mode: () => 'local' },
2424
{ localIdentName: '[path][name]__[local]--[hash:base64:5]' },
2525
{ context: 'context' },
26-
{ hashPrefix: 'hash' },
26+
{ localIdentHashPrefix: 'hash' },
2727
{ getLocalIdent: () => {} },
2828
{ localIdentRegExp: 'page-(.*)\\.js' },
2929
{ localIdentRegExp: /page-(.*)\.js/ },
@@ -53,7 +53,7 @@ describe('validate options', () => {
5353
{ mode: 'pures' },
5454
{ localIdentName: true },
5555
{ context: true },
56-
{ hashPrefix: true },
56+
{ localIdentHashPrefix: true },
5757
{ getLocalIdent: [] },
5858
{ localIdentRegExp: true },
5959
{ exportGlobals: 'invalid' },

0 commit comments

Comments
 (0)