3
3
Author Tobias Koppers @sokra
4
4
*/
5
5
6
+ const schema = require ( "./options.json" ) ;
7
+ const validate = require ( "@webpack-contrib/schema-utils" ) ;
6
8
const loaderUtils = require ( "loader-utils" ) ;
7
9
const postcss = require ( "postcss" ) ;
8
10
const plugin = require ( "./plugin" ) ;
@@ -11,13 +13,14 @@ const SyntaxError = require("./SyntaxError");
11
13
module . exports = function ( content , map , meta ) {
12
14
const options = loaderUtils . getOptions ( this ) || { } ;
13
15
14
- // Todo validate options
16
+ validate ( { name : "CSS Loader" , schema , target : options } ) ;
15
17
16
18
const cb = this . async ( ) ;
17
- const sourceMap = options . sourceMap || false ;
18
- const url = typeof options . url === "undefined" ? true : options . url ;
19
- const importOpt = typeof options . import === "undefined" ? true : options . import ;
20
- const importLoaders = options . importLoaders || 0 ;
19
+ const { url, import : importOpt , sourceMap, importLoaders } = Object . assign (
20
+ { } ,
21
+ { url : true , import : true , sourceMap : false , importLoaders : 0 } ,
22
+ loaderUtils . getOptions ( this ) || { }
23
+ ) ;
21
24
22
25
if ( sourceMap && map ) {
23
26
if ( typeof map === "string" ) {
@@ -115,11 +118,8 @@ module.exports = function(content, map, meta) {
115
118
116
119
if ( result . messages && result . messages . length > 0 ) {
117
120
result . messages
118
- . filter (
119
- message =>
120
- message . type === "modify-code" ? message : false
121
- )
122
- . forEach ( ( message ) => {
121
+ . filter ( message => ( message . type === "modify-code" ? message : false ) )
122
+ . forEach ( message => {
123
123
try {
124
124
newContentObj = message . modifyCode ( this , newContentObj ) ;
125
125
} catch ( err ) {
0 commit comments