2
2
MIT License http://www.opensource.org/licenses/mit-license.php
3
3
Author Tobias Koppers @sokra
4
4
*/
5
+ var fs = require ( "fs" ) ;
5
6
var loaderUtils = require ( "loader-utils" ) ;
6
7
var NodeTemplatePlugin = require ( "webpack/lib/node/NodeTemplatePlugin" ) ;
7
8
var NodeTargetPlugin = require ( "webpack/lib/node/NodeTargetPlugin" ) ;
8
9
var LibraryTemplatePlugin = require ( "webpack/lib/LibraryTemplatePlugin" ) ;
9
10
var SingleEntryPlugin = require ( "webpack/lib/SingleEntryPlugin" ) ;
10
11
var LimitChunkCountPlugin = require ( "webpack/lib/optimize/LimitChunkCountPlugin" ) ;
12
+
13
+ var NS = fs . realpathSync ( __dirname ) ;
14
+
11
15
module . exports = function ( source ) {
12
16
if ( this . cacheable ) this . cacheable ( ) ;
13
17
return source ;
14
18
} ;
19
+
15
20
module . exports . pitch = function ( request ) {
16
21
if ( this . cacheable ) this . cacheable ( ) ;
17
22
var query = loaderUtils . parseQuery ( this . query ) ;
18
23
this . addDependency ( this . resourcePath ) ;
19
24
// We already in child compiler, return empty bundle
20
- if ( this [ fs . realpathSync ( __dirname ) ] === undefined ) {
25
+ if ( this [ NS ] === undefined ) {
21
26
throw new Error (
22
27
'"extract-text-webpack-plugin" loader is used without the corresponding plugin, ' +
23
28
'refer to https://github.com/webpack/extract-text-webpack-plugin for the usage example'
24
29
) ;
25
- } else if ( this [ fs . realpathSync ( __dirname ) ] === false ) {
30
+ } else if ( this [ NS ] === false ) {
26
31
return "" ;
27
- } else if ( this [ fs . realpathSync ( __dirname ) ] ( null , query ) ) {
32
+ } else if ( this [ NS ] ( null , query ) ) {
28
33
if ( query . omit ) {
29
34
this . loaderIndex += + query . omit + 1 ;
30
35
request = request . split ( "!" ) . slice ( + query . omit ) . join ( "!" ) ;
@@ -48,19 +53,19 @@ module.exports.pitch = function(request) {
48
53
childCompiler . apply ( new NodeTargetPlugin ( ) ) ;
49
54
childCompiler . apply ( new SingleEntryPlugin ( this . context , "!!" + request ) ) ;
50
55
childCompiler . apply ( new LimitChunkCountPlugin ( { maxChunks : 1 } ) ) ;
51
- var subCache = "subcache " + fs . realpathSync ( __dirname ) + " " + request ; // eslint-disable-line no-path-concat
56
+ var subCache = "subcache " + NS + " " + request ; // eslint-disable-line no-path-concat
52
57
childCompiler . plugin ( "compilation" , function ( compilation ) {
53
58
if ( compilation . cache ) {
54
59
if ( ! compilation . cache [ subCache ] )
55
60
compilation . cache [ subCache ] = { } ;
56
61
compilation . cache = compilation . cache [ subCache ] ;
57
62
}
58
63
} ) ;
59
- // We set loaderContext[fs.realpathSync(__dirname) ] = false to indicate we already in
64
+ // We set loaderContext[NS ] = false to indicate we already in
60
65
// a child compiler so we don't spawn another child compilers from there.
61
66
childCompiler . plugin ( "this-compilation" , function ( compilation ) {
62
67
compilation . plugin ( "normal-module-loader" , function ( loaderContext ) {
63
- loaderContext [ fs . realpathSync ( __dirname ) ] = false ;
68
+ loaderContext [ NS ] = false ;
64
69
} ) ;
65
70
} ) ;
66
71
var source ;
@@ -103,7 +108,7 @@ module.exports.pitch = function(request) {
103
108
item [ 0 ] = module . identifier ( ) ;
104
109
} ) ;
105
110
} ) ;
106
- this [ fs . realpathSync ( __dirname ) ] ( text , query ) ;
111
+ this [ NS ] ( text , query ) ;
107
112
if ( text . locals && typeof resultSource !== "undefined" ) {
108
113
resultSource += "\nmodule.exports = " + JSON . stringify ( text . locals ) + ";" ;
109
114
}
0 commit comments