Skip to content

Commit b97d997

Browse files
feat: schema options
1 parent 453248f commit b97d997

File tree

6 files changed

+481
-236
lines changed

6 files changed

+481
-236
lines changed

lib/loader.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5+
const validateOptions = require('schema-utils');
56
const postcss = require('postcss');
67
const postcssPkg = require('postcss/package.json');
78
const localByDefault = require('postcss-modules-local-by-default');
@@ -17,6 +18,7 @@ const {
1718
stringifyRequest,
1819
} = require('loader-utils');
1920

21+
const schema = require('./options.json');
2022
const { importParser, icssParser, urlParser } = require('./plugins');
2123
const {
2224
getLocalIdent,
@@ -28,8 +30,11 @@ const Warning = require('./Warning');
2830
const CssSyntaxError = require('./CssSyntaxError');
2931

3032
module.exports = function loader(content, map, meta) {
31-
const callback = this.async();
3233
const options = getOptions(this) || {};
34+
35+
validateOptions(schema, options, 'CSS Loader');
36+
37+
const callback = this.async();
3338
const sourceMap = options.sourceMap || false;
3439

3540
/* eslint-disable no-param-reassign */

lib/options.json

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"additionalProperties": false,
3+
"properties": {
4+
"url": {
5+
"type": "boolean"
6+
},
7+
"import": {
8+
"type": "boolean"
9+
},
10+
"modules": {
11+
"anyOf": [
12+
{
13+
"type": "boolean"
14+
},
15+
{
16+
"type": "string",
17+
"enum": ["local", "global"]
18+
}
19+
]
20+
},
21+
"localIdentName": {
22+
"type": "string"
23+
},
24+
"localIdentRegExp": {
25+
"anyOf": [
26+
{
27+
"type": "string"
28+
},
29+
{
30+
"instanceof": "RegExp"
31+
}
32+
]
33+
},
34+
"context": {
35+
"type": "string"
36+
},
37+
"hashPrefix": {
38+
"type": "string"
39+
},
40+
"getLocalIdent": {
41+
"instanceof": "Function"
42+
},
43+
"sourceMap": {
44+
"type": "boolean"
45+
},
46+
"camelCase": {
47+
"anyOf": [
48+
{
49+
"type": "boolean"
50+
},
51+
{
52+
"type": "string",
53+
"enum": ["dashes", "only", "dashesOnly"]
54+
}
55+
]
56+
},
57+
"importLoaders": {
58+
"type": "number"
59+
},
60+
"exportOnlyLocals": {
61+
"type": "boolean"
62+
}
63+
},
64+
"type": "object"
65+
}

0 commit comments

Comments
 (0)