-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dep): use internal copy of bundle-loader
closes #167
- Loading branch information
Showing
2 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
MIT License http://www.opensource.org/licenses/mit-license.php | ||
Author Tobias Koppers @sokra | ||
*/ | ||
var loaderUtils = require("loader-utils"); | ||
|
||
function loader() { } | ||
|
||
export default loader; | ||
|
||
loader.pitch = function (this: import('webpack').WebpackPluginInstance, remainingRequest: any) { | ||
this.cacheable && this.cacheable(); | ||
var query = loaderUtils.getOptions(this) || {}; | ||
if (query.name) { | ||
var options = { | ||
context: query.context || this.rootContext || this.options && this.options.context, | ||
regExp: query.regExp | ||
}; | ||
var chunkName = loaderUtils.interpolateName(this, query.name, options); | ||
var chunkNameParam = ", " + JSON.stringify(chunkName); | ||
} else { | ||
var chunkNameParam = ''; | ||
} | ||
|
||
var result; | ||
if (query.lazy) { | ||
result = [ | ||
"module.exports = function(cb) {\n", | ||
" require.ensure([], function(require) {\n", | ||
" cb(require(", loaderUtils.stringifyRequest(this, "!!" + remainingRequest), "));\n", | ||
" }" + chunkNameParam + ");\n", | ||
"}"]; | ||
} else { | ||
result = [ | ||
"var cbs = [], \n", | ||
" data;\n", | ||
"module.exports = function(cb) {\n", | ||
" if(cbs) cbs.push(cb);\n", | ||
" else cb(data);\n", | ||
"}\n", | ||
"require.ensure([], function(require) {\n", | ||
" data = require(", loaderUtils.stringifyRequest(this, "!!" + remainingRequest), ");\n", | ||
" var callbacks = cbs;\n", | ||
" cbs = null;\n", | ||
" for(var i = 0, l = callbacks.length; i < l; i++) {\n", | ||
" callbacks[i](data);\n", | ||
" }\n", | ||
"}" + chunkNameParam + ");"]; | ||
} | ||
return result.join(""); | ||
} | ||
|
||
/* | ||
Output format: | ||
var cbs = [], | ||
data; | ||
module.exports = function(cb) { | ||
if(cbs) cbs.push(cb); | ||
else cb(data); | ||
} | ||
require.ensure([], function(require) { | ||
data = require("xxx"); | ||
var callbacks = cbs; | ||
cbs = null; | ||
for(var i = 0, l = callbacks.length; i < l; i++) { | ||
callbacks[i](data); | ||
} | ||
}); | ||
*/ |