@@ -5,26 +5,24 @@ const _ = require('lodash');
5
5
const loaderUtils = require ( 'loader-utils' ) ;
6
6
7
7
module . exports = function ( source ) {
8
- if ( this . cacheable ) {
9
- this . cacheable ( ) ;
10
- }
8
+ // Get templating options
9
+ const options = this . query !== '' ? loaderUtils . getOptions ( this ) : { } ;
10
+ const force = options . force || false ;
11
+
11
12
const allLoadersButThisOne = this . loaders . filter ( function ( loader ) {
12
- // Loader API changed from `loader.module` to `loader.normal` in Webpack 2.
13
- return ( loader . module || loader . normal ) !== module . exports ;
13
+ return loader . normal !== module . exports ;
14
14
} ) ;
15
- // This loader shouldn't kick in if there is any other loader
16
- if ( allLoadersButThisOne . length > 0 ) {
15
+ // This loader shouldn't kick in if there is any other loader (unless it's explicitly enforced)
16
+ if ( allLoadersButThisOne . length > 0 && ! force ) {
17
17
return source ;
18
18
}
19
- // Skip .js files
20
- if ( / \. j s $ / . test ( this . resourcePath ) ) {
19
+ // Skip .js files (unless it's explicitly enforced)
20
+ if ( / \. j s $ / . test ( this . resourcePath ) && ! force ) {
21
21
return source ;
22
22
}
23
23
24
24
// The following part renders the template with lodash as aminimalistic loader
25
25
//
26
- // Get templating options
27
- const options = this . query !== '' ? loaderUtils . getOptions ( this ) : { } ;
28
26
const template = _ . template ( source , _ . defaults ( options , { interpolate : / < % = ( [ \s \S ] + ?) % > / g, variable : 'data' } ) ) ;
29
27
// Require !!lodash - using !! will disable all loaders (e.g. babel)
30
28
return 'var _ = require(' + loaderUtils . stringifyRequest ( this , '!!' + require . resolve ( 'lodash' ) ) + ');' +
0 commit comments