Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: schema options
  • Loading branch information
alexander-akait committed Dec 4, 2018
1 parent 453248f commit b97d997
Show file tree
Hide file tree
Showing 6 changed files with 481 additions and 236 deletions.
7 changes: 6 additions & 1 deletion lib/loader.js
Expand Up @@ -2,6 +2,7 @@
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
const validateOptions = require('schema-utils');
const postcss = require('postcss');
const postcssPkg = require('postcss/package.json');
const localByDefault = require('postcss-modules-local-by-default');
Expand All @@ -17,6 +18,7 @@ const {
stringifyRequest,
} = require('loader-utils');

const schema = require('./options.json');
const { importParser, icssParser, urlParser } = require('./plugins');
const {
getLocalIdent,
Expand All @@ -28,8 +30,11 @@ const Warning = require('./Warning');
const CssSyntaxError = require('./CssSyntaxError');

module.exports = function loader(content, map, meta) {
const callback = this.async();
const options = getOptions(this) || {};

validateOptions(schema, options, 'CSS Loader');

const callback = this.async();
const sourceMap = options.sourceMap || false;

/* eslint-disable no-param-reassign */
Expand Down
65 changes: 65 additions & 0 deletions lib/options.json
@@ -0,0 +1,65 @@
{
"additionalProperties": false,
"properties": {
"url": {
"type": "boolean"
},
"import": {
"type": "boolean"
},
"modules": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "string",
"enum": ["local", "global"]
}
]
},
"localIdentName": {
"type": "string"
},
"localIdentRegExp": {
"anyOf": [
{
"type": "string"
},
{
"instanceof": "RegExp"
}
]
},
"context": {
"type": "string"
},
"hashPrefix": {
"type": "string"
},
"getLocalIdent": {
"instanceof": "Function"
},
"sourceMap": {
"type": "boolean"
},
"camelCase": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "string",
"enum": ["dashes", "only", "dashesOnly"]
}
]
},
"importLoaders": {
"type": "number"
},
"exportOnlyLocals": {
"type": "boolean"
}
},
"type": "object"
}

0 comments on commit b97d997

Please sign in to comment.