File tree Expand file tree Collapse file tree 3 files changed +29
-6
lines changed Expand file tree Collapse file tree 3 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -42,11 +42,27 @@ module.exports = function loader(content, sourceMap) {
4242 }
4343
4444 // process
45- return rework ( content )
46- . use ( reworkPlugin )
47- . toString ( {
48- sourcemap : this . sourceMap || options . sourceMap
49- } ) ;
45+ // rework will throw on css syntax errors
46+ var FILENAME_PLACEHOLDER = '<filename>' ;
47+ try {
48+ return rework ( content , { source : FILENAME_PLACEHOLDER } )
49+ . use ( reworkPlugin )
50+ . toString ( {
51+ sourcemap : this . sourceMap || options . sourceMap
52+ } ) ;
53+ }
54+ // fail gracefully
55+ catch ( exception ) {
56+ var message = ( 'CSS syntax error (resolve-url-loader did not operate)' + exception . message )
57+ . replace ( FILENAME_PLACEHOLDER , '' ) ;
58+ if ( options . fail ) {
59+ this . emitError ( message ) ;
60+ }
61+ else if ( ! options . silent ) {
62+ this . emitWarning ( message ) ;
63+ }
64+ return content ; // original content unchanged
65+ }
5066
5167 /**
5268 * Convert each relative file in the given array to absolute path.
Original file line number Diff line number Diff line change 11{
22 "name" : " resolve-url-loader" ,
3- "version" : " 1.0.3 " ,
3+ "version" : " 1.1.0 " ,
44 "description" : " Webpack loader that resolves relative paths in url() statements based on the original source file" ,
55 "main" : " index.js" ,
66 "scripts" : {
Original file line number Diff line number Diff line change @@ -40,6 +40,9 @@ require('!style!css!resolve-url!sass?sourceMap!./file.scss');
4040
4141Note that ** source maps** must be enabled on any preceding loader. In the above example we use ` sass?sourceMap ` .
4242
43+ In some use cases (no preceding transpiler) there will be no incoming source map. Therefore we do not warn if the
44+ source-map is missing.
45+
4346### Apply via webpack config
4447
4548It is preferable to adjust your ` webpack.config ` so to avoid having to prefix every ` require() ` statement:
@@ -68,6 +71,10 @@ if you know what you are doing.
6871
6972* ` sourceMap ` Generate a source-map.
7073
74+ * ` silent ` Do not display warnings on CSS syntax error.
75+
76+ * ` fail ` Syntax errors will result in an error.
77+
7178## How it works
7279
7380The incoming source-map is used to resolve the original file. This is necessary where there was some preceding transpile
You can’t perform that action at this time.
0 commit comments