Skip to content

Commit

Permalink
fix(dep): use internal copy of bundle-loader
Browse files Browse the repository at this point in the history
closes #167
  • Loading branch information
bigopon committed Jan 31, 2023
1 parent c1cc84b commit b40d014
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/AureliaPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class AureliaPlugin {
let alias = resolveLoader.alias || (resolveLoader.alias = {});
alias["aurelia-webpack-plugin"] = "aurelia-webpack-plugin/dist";
// Our async! loader is in fact just bundle-loader!.
alias["async"] = "bundle-loader";
alias["async"] = "aurelia-webpack-plugin/dist/bundle-loader";

// For my own sanity when working on this plugin with `yarn link`,
// make sure neither webpack nor Node resolve symlinks.
Expand Down
71 changes: 71 additions & 0 deletions src/bundle-loader.ts
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);
}
});
*/

0 comments on commit b40d014

Please sign in to comment.