mirror of https://github.com/webpack/webpack.git
Merge branch 'master' into webpack-2
Conflicts: bin/webpack.js package.json
This commit is contained in:
commit
ff7848369a
|
@ -5,7 +5,7 @@
|
|||
"rules": {
|
||||
"strict": 0,
|
||||
"curly": 0,
|
||||
"eol-last": 0,
|
||||
"eol-last": 1,
|
||||
"no-shadow": 0,
|
||||
"no-redeclare": 1,
|
||||
"no-extra-bind": 1,
|
||||
|
|
|
@ -49,6 +49,10 @@ module.exports = function(optimist) {
|
|||
|
||||
.boolean("watch").alias("watch", "w").describe("watch")
|
||||
|
||||
.describe("watch-aggregate-timeout")
|
||||
|
||||
.describe("watch-poll")
|
||||
|
||||
.boolean("hot").alias("hot", "h").describe("hot")
|
||||
|
||||
.boolean("debug").describe("debug")
|
||||
|
|
|
@ -2,7 +2,7 @@ var path = require("path");
|
|||
var fs = require("fs");
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
var resolve = require("enhanced-resolve");
|
||||
var interpret = require('interpret');
|
||||
var interpret = require("interpret");
|
||||
|
||||
module.exports = function(optimist, argv, convertOptions) {
|
||||
|
||||
|
@ -73,18 +73,37 @@ module.exports = function(optimist, argv, convertOptions) {
|
|||
}
|
||||
|
||||
if(argv.context) {
|
||||
options.context = path.resolve(argv.context)
|
||||
options.context = path.resolve(argv.context);
|
||||
}
|
||||
if(!options.context) {
|
||||
options.context = process.cwd();
|
||||
}
|
||||
|
||||
if(argv["watch"]) {
|
||||
options.watch = true;
|
||||
if(options.watchDelay) {
|
||||
console.warn("watchDelay is deprecated: Use 'watch.aggregateTimeout' instead.");
|
||||
options.watch = options.watch || {};
|
||||
options.watch.aggregateTimeout = options.watchDelay;
|
||||
}
|
||||
options.doWatch = true;
|
||||
}
|
||||
|
||||
if(argv["watch-delay"]) {
|
||||
options.watchDelay = +argv["watch-delay"];
|
||||
options.watch = options.watch || {};
|
||||
options.watch.aggregateTimeout = +argv["watch-delay"];
|
||||
}
|
||||
|
||||
if(argv["watch-aggregate-timeout"]) {
|
||||
options.watch = options.watch || {};
|
||||
options.watch.aggregateTimeout = +argv["watch-aggregate-timeout"];
|
||||
}
|
||||
|
||||
if(argv["watch-poll"]) {
|
||||
options.watch = options.watch || {};
|
||||
if(typeof argv["watch-poll"] !== "boolean")
|
||||
options.watch.poll = +argv["watch-poll"];
|
||||
else
|
||||
options.watch.poll = true;
|
||||
}
|
||||
|
||||
function processOptions(options) {
|
||||
|
@ -97,7 +116,7 @@ module.exports = function(optimist, argv, convertOptions) {
|
|||
if(finalize) {
|
||||
finalize();
|
||||
}
|
||||
} else if(typeof argv[name] != "undefined") {
|
||||
} else if(typeof argv[name] !== "undefined") {
|
||||
if(init) {
|
||||
init();
|
||||
}
|
||||
|
@ -114,7 +133,7 @@ module.exports = function(optimist, argv, convertOptions) {
|
|||
if(i < 0) {
|
||||
return fn(null, content, idx);
|
||||
} else {
|
||||
return fn(content.substr(0, i), content.substr(i+1), idx);
|
||||
return fn(content.substr(0, i), content.substr(i + 1), idx);
|
||||
}
|
||||
}, init, finalize);
|
||||
}
|
||||
|
@ -283,11 +302,6 @@ module.exports = function(optimist, argv, convertOptions) {
|
|||
});
|
||||
|
||||
mapArgToBooleanInverse("cache");
|
||||
mapArgToBoolean("watch");
|
||||
|
||||
ifArg("watch-delay", function(value) {
|
||||
options.watchDelay = value;
|
||||
});
|
||||
|
||||
ifBooleanArg("hot", function() {
|
||||
ensureArray(options, "plugins");
|
||||
|
@ -464,7 +478,7 @@ module.exports = function(optimist, argv, convertOptions) {
|
|||
addTo("main", content);
|
||||
}
|
||||
} else {
|
||||
addTo(content.substr(0, i), content.substr(i+1));
|
||||
addTo(content.substr(0, i), content.substr(i + 1));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -8,15 +8,13 @@ var path = require("path");
|
|||
// Local version replace global one
|
||||
try {
|
||||
var localWebpack = require.resolve(path.join(process.cwd(), "node_modules", "webpack", "bin", "webpack.js"));
|
||||
if(__filename != localWebpack) {
|
||||
if(__filename !== localWebpack) {
|
||||
return require(localWebpack);
|
||||
}
|
||||
} catch(e) {}
|
||||
var fs = require("fs");
|
||||
var util = require("util");
|
||||
var optimist = require("optimist")
|
||||
.usage("webpack " + require("../package.json").version + "\n" +
|
||||
"Usage: http://webpack.github.io/docs/cli.html")
|
||||
"Usage: http://webpack.github.io/docs/cli.html");
|
||||
|
||||
require("./config-optimist")(optimist);
|
||||
|
||||
|
@ -59,7 +57,7 @@ function ifArg(name, fn, init) {
|
|||
if(Array.isArray(argv[name])) {
|
||||
if(init) init();
|
||||
argv[name].forEach(fn);
|
||||
} else if(typeof argv[name] != "undefined") {
|
||||
} else if(typeof argv[name] !== "undefined") {
|
||||
if(init) init();
|
||||
fn(argv[name], -1);
|
||||
}
|
||||
|
@ -145,8 +143,9 @@ var webpack = require("../lib/webpack.js");
|
|||
|
||||
Error.stackTrackLimit = 30;
|
||||
var lastHash = null;
|
||||
var compiler = webpack(options, function(err, stats) {
|
||||
if(!options.watch) {
|
||||
var compiler = webpack(options);
|
||||
function compilerCallback(err, stats) {
|
||||
if(!options.doWatch) {
|
||||
// Do not keep cache anymore
|
||||
compiler.purgeInputFileSystem();
|
||||
}
|
||||
|
@ -154,7 +153,7 @@ var compiler = webpack(options, function(err, stats) {
|
|||
lastHash = null;
|
||||
console.error(err.stack || err);
|
||||
if(err.details) console.error(err.details);
|
||||
if(!options.watch) {
|
||||
if(!options.doWatch) {
|
||||
process.on("exit", function() {
|
||||
process.exit(1);
|
||||
});
|
||||
|
@ -167,9 +166,13 @@ var compiler = webpack(options, function(err, stats) {
|
|||
lastHash = stats.hash;
|
||||
process.stdout.write(stats.toString(outputOptions) + "\n");
|
||||
}
|
||||
if(!options.watch && stats.hasErrors()) {
|
||||
if(!options.doWatch && stats.hasErrors()) {
|
||||
process.on("exit", function() {
|
||||
process.exit(2);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
if(options.doWatch)
|
||||
compiler.watch(options.watch, compilerCallback);
|
||||
else
|
||||
compiler.run(compilerCallback);
|
||||
|
|
|
@ -2,42 +2,28 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var cp = require('child_process');
|
||||
var cp = require("child_process");
|
||||
var tc = require("./template-common");
|
||||
var Stats = require("../lib/Stats");
|
||||
// var webpackGraph = require("webpack-graph");
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
|
||||
var extraArgs = "";
|
||||
|
||||
var targetArgs = global.NO_TARGET_ARGS?"":" ./example.js js/output.js";
|
||||
var displayReasons = global.NO_REASONS?"":" --display-reasons";
|
||||
cp.exec("node ../../bin/webpack.js"+displayReasons+" --display-chunks --display-modules --display-origins --output-public-path \"js/\" -p "+extraArgs+targetArgs, function (error, stdout, stderr) {
|
||||
var targetArgs = global.NO_TARGET_ARGS ? "" : " ./example.js js/output.js";
|
||||
var displayReasons = global.NO_REASONS ? "" : " --display-reasons";
|
||||
cp.exec("node ../../bin/webpack.js" + displayReasons + " --display-chunks --display-modules --display-origins --output-public-path \"js/\" -p " + extraArgs + targetArgs, function (error, stdout, stderr) {
|
||||
if(stderr)
|
||||
console.log(stderr);
|
||||
if (error !== null)
|
||||
console.log(error);
|
||||
var readme = tc(fs.readFileSync(require("path").join(process.cwd(), "template.md"), "utf-8"), process.cwd(), stdout.replace(/[\r\n]*$/, ""), "min");
|
||||
cp.exec("node ../../bin/webpack.js"+displayReasons+" --display-chunks --display-modules --display-origins --output-public-path \"js/\" --optimize-occurence-order --output-pathinfo "+extraArgs+targetArgs, function (error, stdout, stderr) {
|
||||
cp.exec("node ../../bin/webpack.js" + displayReasons + " --display-chunks --display-modules --display-origins --output-public-path \"js/\" --output-pathinfo " + extraArgs + targetArgs, function (error, stdout, stderr) {
|
||||
console.log(stdout);
|
||||
if(stderr)
|
||||
console.log(stderr);
|
||||
if (error !== null)
|
||||
console.log(error);
|
||||
// var stats = JSON.parse(stdout);
|
||||
// var formatedStats = Stats.jsonToString(stats, {
|
||||
// context: process.cwd(),
|
||||
// verbose: true
|
||||
// });
|
||||
// var filenameShortener = createFilenameShortener(process.cwd());
|
||||
readme = tc(readme, process.cwd(), stdout.replace(/[\r\n]*$/, ""));
|
||||
readme = readme.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
||||
fs.writeFile("README.md", readme, "utf-8", function() {});
|
||||
// fs.writeFile("graph.svg", webpackGraph(stats, {
|
||||
// nameShortener: filenameShortener,
|
||||
// width: 500,
|
||||
// height: 300
|
||||
// }), "utf-8", function() {});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,218 @@
|
|||
# webpack.config.js
|
||||
|
||||
``` javascript
|
||||
var path = require("path");
|
||||
var CommonsChunkPlugin = require("../../lib/optimize/CommonsChunkPlugin");
|
||||
module.exports = {
|
||||
entry: {
|
||||
vendor: ["./vendor"],
|
||||
pageA: "./pageA",
|
||||
pageB: "./pageB",
|
||||
pageC: "./pageC"
|
||||
},
|
||||
output: {
|
||||
path: path.join(__dirname, "js"),
|
||||
filename: "[name].js"
|
||||
},
|
||||
plugins: [
|
||||
new CommonsChunkPlugin({
|
||||
name: "vendor",
|
||||
minChunks: Infinity
|
||||
})
|
||||
]
|
||||
};
|
||||
```
|
||||
|
||||
# js/vendor.js
|
||||
|
||||
``` javascript
|
||||
/******/ (function(modules) { // webpackBootstrap
|
||||
/******/ // install a JSONP callback for chunk loading
|
||||
/******/ var parentJsonpFunction = window["webpackJsonp"];
|
||||
/******/ window["webpackJsonp"] = function webpackJsonpCallback(chunkIds, moreModules) {
|
||||
/******/ // add "moreModules" to the modules object,
|
||||
/******/ // then flag all "chunkIds" as loaded and fire callback
|
||||
/******/ var moduleId, chunkId, i = 0, callbacks = [];
|
||||
/******/ for(;i < chunkIds.length; i++) {
|
||||
/******/ chunkId = chunkIds[i];
|
||||
/******/ if(installedChunks[chunkId])
|
||||
/******/ callbacks.push.apply(callbacks, installedChunks[chunkId]);
|
||||
/******/ installedChunks[chunkId] = 0;
|
||||
/******/ }
|
||||
/******/ for(moduleId in moreModules) {
|
||||
/******/ modules[moduleId] = moreModules[moduleId];
|
||||
/******/ }
|
||||
/******/ if(parentJsonpFunction) parentJsonpFunction(chunkIds, moreModules);
|
||||
/******/ while(callbacks.length)
|
||||
/******/ callbacks.shift().call(null, __webpack_require__);
|
||||
/******/ if(moreModules[0]) {
|
||||
/******/ installedModules[0] = 0;
|
||||
/******/ return __webpack_require__(0);
|
||||
/******/ }
|
||||
/******/ };
|
||||
|
||||
/******/ // The module cache
|
||||
/******/ var installedModules = {};
|
||||
|
||||
/******/ // object to store loaded and loading chunks
|
||||
/******/ // "0" means "already loaded"
|
||||
/******/ // Array means "loading", array contains callbacks
|
||||
/******/ var installedChunks = {
|
||||
/******/ 0:0
|
||||
/******/ };
|
||||
|
||||
/******/ // The require function
|
||||
/******/ function __webpack_require__(moduleId) {
|
||||
|
||||
/******/ // Check if module is in cache
|
||||
/******/ if(installedModules[moduleId])
|
||||
/******/ return installedModules[moduleId].exports;
|
||||
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = installedModules[moduleId] = {
|
||||
/******/ exports: {},
|
||||
/******/ id: moduleId,
|
||||
/******/ loaded: false
|
||||
/******/ };
|
||||
|
||||
/******/ // Execute the module function
|
||||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||
|
||||
/******/ // Flag the module as loaded
|
||||
/******/ module.loaded = true;
|
||||
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/ }
|
||||
|
||||
/******/ // This file contains only the entry chunk.
|
||||
/******/ // The chunk loading function for additional chunks
|
||||
/******/ __webpack_require__.e = function requireEnsure(chunkId, callback) {
|
||||
/******/ // "0" is the signal for "already loaded"
|
||||
/******/ if(installedChunks[chunkId] === 0)
|
||||
/******/ return callback.call(null, __webpack_require__);
|
||||
|
||||
/******/ // an array means "currently loading".
|
||||
/******/ if(installedChunks[chunkId] !== undefined) {
|
||||
/******/ installedChunks[chunkId].push(callback);
|
||||
/******/ } else {
|
||||
/******/ // start chunk loading
|
||||
/******/ installedChunks[chunkId] = [callback];
|
||||
/******/ var head = document.getElementsByTagName('head')[0];
|
||||
/******/ var script = document.createElement('script');
|
||||
/******/ script.type = 'text/javascript';
|
||||
/******/ script.charset = 'utf-8';
|
||||
/******/ script.async = true;
|
||||
|
||||
/******/ script.src = __webpack_require__.p + "" + chunkId + "." + ({"1":"pageC","2":"pageB","3":"pageA"}[chunkId]||chunkId) + ".js";
|
||||
/******/ head.appendChild(script);
|
||||
/******/ }
|
||||
/******/ };
|
||||
|
||||
/******/ // expose the modules object (__webpack_modules__)
|
||||
/******/ __webpack_require__.m = modules;
|
||||
|
||||
/******/ // expose the module cache
|
||||
/******/ __webpack_require__.c = installedModules;
|
||||
|
||||
/******/ // __webpack_public_path__
|
||||
/******/ __webpack_require__.p = "js/";
|
||||
|
||||
/******/ // Load entry module and return exports
|
||||
/******/ return __webpack_require__(0);
|
||||
/******/ })
|
||||
/************************************************************************/
|
||||
/******/ ([
|
||||
/* 0 */
|
||||
/*!********************!*\
|
||||
!*** multi vendor ***!
|
||||
\********************/
|
||||
/***/ function(module, exports, __webpack_require__) {
|
||||
|
||||
module.exports = __webpack_require__(/*! ./vendor */1);
|
||||
|
||||
|
||||
/***/ },
|
||||
/* 1 */
|
||||
/*!*******************!*\
|
||||
!*** ./vendor.js ***!
|
||||
\*******************/
|
||||
/***/ function(module, exports, __webpack_require__) {
|
||||
|
||||
module.exports = "Vendor";
|
||||
|
||||
/***/ }
|
||||
/******/ ]);
|
||||
```
|
||||
|
||||
# js/pageA.js
|
||||
|
||||
``` javascript
|
||||
webpackJsonp([3],[
|
||||
/* 0 */
|
||||
/*!******************!*\
|
||||
!*** ./pageA.js ***!
|
||||
\******************/
|
||||
/***/ function(module, exports, __webpack_require__) {
|
||||
|
||||
module.exports = "pageA";
|
||||
|
||||
/***/ }
|
||||
]);
|
||||
```
|
||||
|
||||
# Info
|
||||
|
||||
## Uncompressed
|
||||
|
||||
```
|
||||
Hash: 7ba2182676e9cab55532
|
||||
Version: webpack 1.8.11
|
||||
Time: 68ms
|
||||
Asset Size Chunks Chunk Names
|
||||
vendor.js 4.06 kB 0 [emitted] vendor
|
||||
pageC.js 193 bytes 1 [emitted] pageC
|
||||
pageB.js 193 bytes 2 [emitted] pageB
|
||||
pageA.js 193 bytes 3 [emitted] pageA
|
||||
chunk {0} vendor.js (vendor) 54 bytes [rendered]
|
||||
> vendor [0] multi vendor
|
||||
[0] multi vendor 28 bytes {0} [built]
|
||||
[1] ./vendor.js 26 bytes {0} [built]
|
||||
single entry ./vendor [0] multi vendor
|
||||
chunk {1} pageC.js (pageC) 25 bytes {0} [rendered]
|
||||
> pageC [0] ./pageC.js
|
||||
[0] ./pageC.js 25 bytes {1} [built]
|
||||
chunk {2} pageB.js (pageB) 25 bytes {0} [rendered]
|
||||
> pageB [0] ./pageB.js
|
||||
[0] ./pageB.js 25 bytes {2} [built]
|
||||
chunk {3} pageA.js (pageA) 25 bytes {0} [rendered]
|
||||
> pageA [0] ./pageA.js
|
||||
[0] ./pageA.js 25 bytes {3} [built]
|
||||
```
|
||||
|
||||
## Minimized (uglify-js, no zip)
|
||||
|
||||
```
|
||||
Hash: 7ba2182676e9cab55532
|
||||
Version: webpack 1.8.11
|
||||
Time: 194ms
|
||||
Asset Size Chunks Chunk Names
|
||||
vendor.js 836 bytes 0 [emitted] vendor
|
||||
pageC.js 55 bytes 1 [emitted] pageC
|
||||
pageB.js 55 bytes 2 [emitted] pageB
|
||||
pageA.js 55 bytes 3 [emitted] pageA
|
||||
chunk {0} vendor.js (vendor) 54 bytes [rendered]
|
||||
> vendor [0] multi vendor
|
||||
[0] multi vendor 28 bytes {0} [built]
|
||||
[1] ./vendor.js 26 bytes {0} [built]
|
||||
single entry ./vendor [0] multi vendor
|
||||
chunk {1} pageC.js (pageC) 25 bytes {0} [rendered]
|
||||
> pageC [0] ./pageC.js
|
||||
[0] ./pageC.js 25 bytes {1} [built]
|
||||
chunk {2} pageB.js (pageB) 25 bytes {0} [rendered]
|
||||
> pageB [0] ./pageB.js
|
||||
[0] ./pageB.js 25 bytes {2} [built]
|
||||
chunk {3} pageA.js (pageA) 25 bytes {0} [rendered]
|
||||
> pageA [0] ./pageA.js
|
||||
[0] ./pageA.js 25 bytes {3} [built]
|
||||
```
|
|
@ -0,0 +1,2 @@
|
|||
global.NO_TARGET_ARGS = true;
|
||||
require("../build-common");
|
|
@ -0,0 +1,7 @@
|
|||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
<script src="js/vendor.js" charset="utf-8"></script>
|
||||
<script src="js/pageA.js" charset="utf-8"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1 @@
|
|||
module.exports = "pageA";
|
|
@ -0,0 +1 @@
|
|||
module.exports = "pageB";
|
|
@ -0,0 +1 @@
|
|||
module.exports = "pageC";
|
|
@ -0,0 +1,31 @@
|
|||
# webpack.config.js
|
||||
|
||||
``` javascript
|
||||
{{webpack.config.js}}
|
||||
```
|
||||
|
||||
# js/vendor.js
|
||||
|
||||
``` javascript
|
||||
{{js/vendor.js}}
|
||||
```
|
||||
|
||||
# js/pageA.js
|
||||
|
||||
``` javascript
|
||||
{{js/pageA.js}}
|
||||
```
|
||||
|
||||
# Info
|
||||
|
||||
## Uncompressed
|
||||
|
||||
```
|
||||
{{stdout}}
|
||||
```
|
||||
|
||||
## Minimized (uglify-js, no zip)
|
||||
|
||||
```
|
||||
{{min:stdout}}
|
||||
```
|
|
@ -0,0 +1 @@
|
|||
module.exports = "Vendor";
|
|
@ -0,0 +1,20 @@
|
|||
var path = require("path");
|
||||
var CommonsChunkPlugin = require("../../lib/optimize/CommonsChunkPlugin");
|
||||
module.exports = {
|
||||
entry: {
|
||||
vendor: ["./vendor"],
|
||||
pageA: "./pageA",
|
||||
pageB: "./pageB",
|
||||
pageC: "./pageC"
|
||||
},
|
||||
output: {
|
||||
path: path.join(__dirname, "js"),
|
||||
filename: "[name].js"
|
||||
},
|
||||
plugins: [
|
||||
new CommonsChunkPlugin({
|
||||
name: "vendor",
|
||||
minChunks: Infinity
|
||||
})
|
||||
]
|
||||
};
|
|
@ -0,0 +1,269 @@
|
|||
# webpack.config.js
|
||||
|
||||
``` javascript
|
||||
var path = require("path");
|
||||
var CommonsChunkPlugin = require("../../lib/optimize/CommonsChunkPlugin");
|
||||
module.exports = {
|
||||
entry: {
|
||||
vendor1: ["./vendor1"],
|
||||
vendor2: ["./vendor2"],
|
||||
pageA: "./pageA",
|
||||
pageB: "./pageB",
|
||||
pageC: "./pageC"
|
||||
},
|
||||
output: {
|
||||
path: path.join(__dirname, "js"),
|
||||
filename: "[name].js"
|
||||
},
|
||||
plugins: [
|
||||
new CommonsChunkPlugin({
|
||||
names: ["vendor2", "vendor1"],
|
||||
minChunks: Infinity
|
||||
})
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
# js/vendor1.js
|
||||
|
||||
``` javascript
|
||||
/******/ (function(modules) { // webpackBootstrap
|
||||
/******/ // install a JSONP callback for chunk loading
|
||||
/******/ var parentJsonpFunction = window["webpackJsonp"];
|
||||
/******/ window["webpackJsonp"] = function webpackJsonpCallback(chunkIds, moreModules) {
|
||||
/******/ // add "moreModules" to the modules object,
|
||||
/******/ // then flag all "chunkIds" as loaded and fire callback
|
||||
/******/ var moduleId, chunkId, i = 0, callbacks = [];
|
||||
/******/ for(;i < chunkIds.length; i++) {
|
||||
/******/ chunkId = chunkIds[i];
|
||||
/******/ if(installedChunks[chunkId])
|
||||
/******/ callbacks.push.apply(callbacks, installedChunks[chunkId]);
|
||||
/******/ installedChunks[chunkId] = 0;
|
||||
/******/ }
|
||||
/******/ for(moduleId in moreModules) {
|
||||
/******/ modules[moduleId] = moreModules[moduleId];
|
||||
/******/ }
|
||||
/******/ if(parentJsonpFunction) parentJsonpFunction(chunkIds, moreModules);
|
||||
/******/ while(callbacks.length)
|
||||
/******/ callbacks.shift().call(null, __webpack_require__);
|
||||
/******/ if(moreModules[0]) {
|
||||
/******/ installedModules[0] = 0;
|
||||
/******/ return __webpack_require__(0);
|
||||
/******/ }
|
||||
/******/ };
|
||||
|
||||
/******/ // The module cache
|
||||
/******/ var installedModules = {};
|
||||
|
||||
/******/ // object to store loaded and loading chunks
|
||||
/******/ // "0" means "already loaded"
|
||||
/******/ // Array means "loading", array contains callbacks
|
||||
/******/ var installedChunks = {
|
||||
/******/ 0:0
|
||||
/******/ };
|
||||
|
||||
/******/ // The require function
|
||||
/******/ function __webpack_require__(moduleId) {
|
||||
|
||||
/******/ // Check if module is in cache
|
||||
/******/ if(installedModules[moduleId])
|
||||
/******/ return installedModules[moduleId].exports;
|
||||
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = installedModules[moduleId] = {
|
||||
/******/ exports: {},
|
||||
/******/ id: moduleId,
|
||||
/******/ loaded: false
|
||||
/******/ };
|
||||
|
||||
/******/ // Execute the module function
|
||||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||
|
||||
/******/ // Flag the module as loaded
|
||||
/******/ module.loaded = true;
|
||||
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/ }
|
||||
|
||||
/******/ // This file contains only the entry chunk.
|
||||
/******/ // The chunk loading function for additional chunks
|
||||
/******/ __webpack_require__.e = function requireEnsure(chunkId, callback) {
|
||||
/******/ // "0" is the signal for "already loaded"
|
||||
/******/ if(installedChunks[chunkId] === 0)
|
||||
/******/ return callback.call(null, __webpack_require__);
|
||||
|
||||
/******/ // an array means "currently loading".
|
||||
/******/ if(installedChunks[chunkId] !== undefined) {
|
||||
/******/ installedChunks[chunkId].push(callback);
|
||||
/******/ } else {
|
||||
/******/ // start chunk loading
|
||||
/******/ installedChunks[chunkId] = [callback];
|
||||
/******/ var head = document.getElementsByTagName('head')[0];
|
||||
/******/ var script = document.createElement('script');
|
||||
/******/ script.type = 'text/javascript';
|
||||
/******/ script.charset = 'utf-8';
|
||||
/******/ script.async = true;
|
||||
|
||||
/******/ script.src = __webpack_require__.p + "" + chunkId + "." + ({"1":"vendor2","2":"pageC","3":"pageB","4":"pageA"}[chunkId]||chunkId) + ".js";
|
||||
/******/ head.appendChild(script);
|
||||
/******/ }
|
||||
/******/ };
|
||||
|
||||
/******/ // expose the modules object (__webpack_modules__)
|
||||
/******/ __webpack_require__.m = modules;
|
||||
|
||||
/******/ // expose the module cache
|
||||
/******/ __webpack_require__.c = installedModules;
|
||||
|
||||
/******/ // __webpack_public_path__
|
||||
/******/ __webpack_require__.p = "js/";
|
||||
|
||||
/******/ // Load entry module and return exports
|
||||
/******/ return __webpack_require__(0);
|
||||
/******/ })
|
||||
/************************************************************************/
|
||||
/******/ ([
|
||||
/* 0 */
|
||||
/*!*********************!*\
|
||||
!*** multi vendor1 ***!
|
||||
\*********************/
|
||||
/***/ function(module, exports, __webpack_require__) {
|
||||
|
||||
module.exports = __webpack_require__(/*! ./vendor1 */1);
|
||||
|
||||
|
||||
/***/ },
|
||||
/* 1 */
|
||||
/*!********************!*\
|
||||
!*** ./vendor1.js ***!
|
||||
\********************/
|
||||
/***/ function(module, exports, __webpack_require__) {
|
||||
|
||||
module.exports = "Vendor1";
|
||||
|
||||
/***/ }
|
||||
/******/ ]);
|
||||
```
|
||||
|
||||
# js/vendor2.js
|
||||
|
||||
``` javascript
|
||||
webpackJsonp([1],[
|
||||
/* 0 */
|
||||
/*!*********************!*\
|
||||
!*** multi vendor2 ***!
|
||||
\*********************/
|
||||
/***/ function(module, exports, __webpack_require__) {
|
||||
|
||||
module.exports = __webpack_require__(/*! ./vendor2 */2);
|
||||
|
||||
|
||||
/***/ },
|
||||
/* 1 */,
|
||||
/* 2 */
|
||||
/*!********************!*\
|
||||
!*** ./vendor2.js ***!
|
||||
\********************/
|
||||
/***/ function(module, exports, __webpack_require__) {
|
||||
|
||||
module.exports = "Vendor2";
|
||||
__webpack_require__(/*! ./vendor1 */ 1);
|
||||
|
||||
|
||||
/***/ }
|
||||
]);
|
||||
```
|
||||
|
||||
# js/pageA.js
|
||||
|
||||
``` javascript
|
||||
webpackJsonp([4],[
|
||||
/* 0 */
|
||||
/*!******************!*\
|
||||
!*** ./pageA.js ***!
|
||||
\******************/
|
||||
/***/ function(module, exports, __webpack_require__) {
|
||||
|
||||
module.exports = "pageA";
|
||||
__webpack_require__(/*! ./vendor1 */ 1);
|
||||
__webpack_require__(/*! ./vendor2 */ 2);
|
||||
|
||||
|
||||
/***/ }
|
||||
]);
|
||||
```
|
||||
|
||||
# Info
|
||||
|
||||
## Uncompressed
|
||||
|
||||
```
|
||||
Hash: 1faf7c0010d184985c19
|
||||
Version: webpack 1.8.11
|
||||
Time: 77ms
|
||||
Asset Size Chunks Chunk Names
|
||||
vendor1.js 4.08 kB 0 [emitted] vendor1
|
||||
vendor2.js 468 bytes 1 [emitted] vendor2
|
||||
pageC.js 193 bytes 2 [emitted] pageC
|
||||
pageB.js 193 bytes 3 [emitted] pageB
|
||||
pageA.js 281 bytes 4 [emitted] pageA
|
||||
chunk {0} vendor1.js (vendor1) 55 bytes [rendered]
|
||||
> vendor1 [0] multi vendor1
|
||||
[0] multi vendor1 28 bytes {0} [built]
|
||||
[1] ./vendor1.js 27 bytes {0} [built]
|
||||
single entry ./vendor1 [0] multi vendor1
|
||||
cjs require ./vendor1 [0] ./pageA.js 2:0-20
|
||||
cjs require ./vendor1 [2] ./vendor2.js 2:0-20
|
||||
chunk {1} vendor2.js (vendor2) 80 bytes {0} [rendered]
|
||||
> vendor2 [0] multi vendor2
|
||||
[0] multi vendor2 28 bytes {1} [built]
|
||||
[2] ./vendor2.js 52 bytes {1} [built]
|
||||
single entry ./vendor2 [0] multi vendor2
|
||||
cjs require ./vendor2 [0] ./pageA.js 3:0-20
|
||||
chunk {2} pageC.js (pageC) 25 bytes {1} [rendered]
|
||||
> pageC [0] ./pageC.js
|
||||
[0] ./pageC.js 25 bytes {2} [built]
|
||||
chunk {3} pageB.js (pageB) 25 bytes {1} [rendered]
|
||||
> pageB [0] ./pageB.js
|
||||
[0] ./pageB.js 25 bytes {3} [built]
|
||||
chunk {4} pageA.js (pageA) 73 bytes {1} [rendered]
|
||||
> pageA [0] ./pageA.js
|
||||
[0] ./pageA.js 73 bytes {4} [built]
|
||||
```
|
||||
|
||||
## Minimized (uglify-js, no zip)
|
||||
|
||||
```
|
||||
Hash: 1faf7c0010d184985c19
|
||||
Version: webpack 1.8.11
|
||||
Time: 208ms
|
||||
Asset Size Chunks Chunk Names
|
||||
vendor1.js 849 bytes 0 [emitted] vendor1
|
||||
vendor2.js 95 bytes 1 [emitted] vendor2
|
||||
pageC.js 55 bytes 2 [emitted] pageC
|
||||
pageB.js 55 bytes 3 [emitted] pageB
|
||||
pageA.js 65 bytes 4 [emitted] pageA
|
||||
chunk {0} vendor1.js (vendor1) 55 bytes [rendered]
|
||||
> vendor1 [0] multi vendor1
|
||||
[0] multi vendor1 28 bytes {0} [built]
|
||||
[1] ./vendor1.js 27 bytes {0} [built]
|
||||
single entry ./vendor1 [0] multi vendor1
|
||||
cjs require ./vendor1 [0] ./pageA.js 2:0-20
|
||||
cjs require ./vendor1 [2] ./vendor2.js 2:0-20
|
||||
chunk {1} vendor2.js (vendor2) 80 bytes {0} [rendered]
|
||||
> vendor2 [0] multi vendor2
|
||||
[0] multi vendor2 28 bytes {1} [built]
|
||||
[2] ./vendor2.js 52 bytes {1} [built]
|
||||
single entry ./vendor2 [0] multi vendor2
|
||||
cjs require ./vendor2 [0] ./pageA.js 3:0-20
|
||||
chunk {2} pageC.js (pageC) 25 bytes {1} [rendered]
|
||||
> pageC [0] ./pageC.js
|
||||
[0] ./pageC.js 25 bytes {2} [built]
|
||||
chunk {3} pageB.js (pageB) 25 bytes {1} [rendered]
|
||||
> pageB [0] ./pageB.js
|
||||
[0] ./pageB.js 25 bytes {3} [built]
|
||||
chunk {4} pageA.js (pageA) 73 bytes {1} [rendered]
|
||||
> pageA [0] ./pageA.js
|
||||
[0] ./pageA.js 73 bytes {4} [built]
|
||||
```
|
|
@ -0,0 +1,2 @@
|
|||
global.NO_TARGET_ARGS = true;
|
||||
require("../build-common");
|
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
<script src="js/vendor1.js" charset="utf-8"></script>
|
||||
<script src="js/vendor2.js" charset="utf-8"></script>
|
||||
<script src="js/pageA.js" charset="utf-8"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = "pageA";
|
||||
require("./vendor1");
|
||||
require("./vendor2");
|
|
@ -0,0 +1 @@
|
|||
module.exports = "pageB";
|
|
@ -0,0 +1 @@
|
|||
module.exports = "pageC";
|
|
@ -0,0 +1,37 @@
|
|||
# webpack.config.js
|
||||
|
||||
``` javascript
|
||||
{{webpack.config.js}}
|
||||
```
|
||||
|
||||
# js/vendor1.js
|
||||
|
||||
``` javascript
|
||||
{{js/vendor1.js}}
|
||||
```
|
||||
|
||||
# js/vendor2.js
|
||||
|
||||
``` javascript
|
||||
{{js/vendor2.js}}
|
||||
```
|
||||
|
||||
# js/pageA.js
|
||||
|
||||
``` javascript
|
||||
{{js/pageA.js}}
|
||||
```
|
||||
|
||||
# Info
|
||||
|
||||
## Uncompressed
|
||||
|
||||
```
|
||||
{{stdout}}
|
||||
```
|
||||
|
||||
## Minimized (uglify-js, no zip)
|
||||
|
||||
```
|
||||
{{min:stdout}}
|
||||
```
|
|
@ -0,0 +1 @@
|
|||
module.exports = "Vendor1";
|
|
@ -0,0 +1,2 @@
|
|||
module.exports = "Vendor2";
|
||||
require("./vendor1");
|
|
@ -0,0 +1,21 @@
|
|||
var path = require("path");
|
||||
var CommonsChunkPlugin = require("../../lib/optimize/CommonsChunkPlugin");
|
||||
module.exports = {
|
||||
entry: {
|
||||
vendor1: ["./vendor1"],
|
||||
vendor2: ["./vendor2"],
|
||||
pageA: "./pageA",
|
||||
pageB: "./pageB",
|
||||
pageC: "./pageC"
|
||||
},
|
||||
output: {
|
||||
path: path.join(__dirname, "js"),
|
||||
filename: "[name].js"
|
||||
},
|
||||
plugins: [
|
||||
new CommonsChunkPlugin({
|
||||
names: ["vendor2", "vendor1"],
|
||||
minChunks: Infinity
|
||||
})
|
||||
]
|
||||
}
|
|
@ -16,6 +16,7 @@ var MainTemplate = require("./MainTemplate");
|
|||
var ChunkTemplate = require("./ChunkTemplate");
|
||||
var HotUpdateChunkTemplate = require("./HotUpdateChunkTemplate");
|
||||
var ModuleTemplate = require("./ModuleTemplate");
|
||||
var Dependency = require("./Dependency");
|
||||
var CachedSource = require("webpack-core/lib/CachedSource");
|
||||
|
||||
function Compilation(compiler) {
|
||||
|
@ -44,6 +45,8 @@ function Compilation(compiler) {
|
|||
this.records = null;
|
||||
this.nextFreeModuleId = 1;
|
||||
this.nextFreeChunkId = 0;
|
||||
this.nextFreeModuleIndex = 0;
|
||||
this.nextFreeModuleIndex2 = 0;
|
||||
this.additionalChunkAssets = [];
|
||||
this.assets = {};
|
||||
this.errors = [];
|
||||
|
@ -123,6 +126,7 @@ Compilation.prototype.buildModule = function(module, thisCallback) {
|
|||
module.warnings.forEach(function(err) {
|
||||
this.warnings.push(err);
|
||||
}, this);
|
||||
module.dependencies.sort(Dependency.compare);
|
||||
if(err) {
|
||||
module.error = err;
|
||||
this.applyPlugins("failed-module", module);
|
||||
|
@ -374,26 +378,27 @@ Compilation.prototype._addModuleChain = function process(context, dependency, on
|
|||
}
|
||||
|
||||
module = result;
|
||||
|
||||
onModule(module);
|
||||
|
||||
moduleReady.call(this);
|
||||
return;
|
||||
}
|
||||
|
||||
onModule(module);
|
||||
|
||||
if(result instanceof Module) {
|
||||
this.buildModule(module, function(err) {
|
||||
if(err) {
|
||||
return errorAndCallback(err);
|
||||
}
|
||||
|
||||
if(this.profile) {
|
||||
var afterBuilding = +new Date();
|
||||
module.profile.building = afterBuilding - afterFactory;
|
||||
}
|
||||
|
||||
moduleReady.call(this);
|
||||
} else {
|
||||
this.buildModule(module, function(err) {
|
||||
if(err) {
|
||||
return errorAndCallback(err);
|
||||
}
|
||||
|
||||
if(this.profile) {
|
||||
var afterBuilding = +new Date();
|
||||
module.profile.building = afterBuilding - afterFactory;
|
||||
}
|
||||
|
||||
moduleReady.call(this);
|
||||
}.bind(this));
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
function moduleReady() {
|
||||
this.processModuleDependencies(module, function(err) {
|
||||
|
@ -488,6 +493,7 @@ Compilation.prototype.seal = function seal(callback) {
|
|||
module.addChunk(chunk);
|
||||
this.processDependenciesBlockForChunk(module, chunk);
|
||||
}, this);
|
||||
this.sortModules(this.modules);
|
||||
this.applyPlugins("optimize");
|
||||
|
||||
this.applyPlugins("optimize-modules", this.modules);
|
||||
|
@ -557,6 +563,14 @@ Compilation.prototype.seal = function seal(callback) {
|
|||
}.bind(this));
|
||||
};
|
||||
|
||||
Compilation.prototype.sortModules = function sortModules(modules) {
|
||||
modules.sort(function(a, b) {
|
||||
if(a.index < b.index) return -1;
|
||||
if(a.index > b.index) return 1;
|
||||
return 0;
|
||||
});
|
||||
};
|
||||
|
||||
Compilation.prototype.addChunk = function addChunk(name, module, loc) {
|
||||
var chunk;
|
||||
if(name) {
|
||||
|
@ -577,6 +591,14 @@ Compilation.prototype.addChunk = function addChunk(name, module, loc) {
|
|||
};
|
||||
|
||||
Compilation.prototype.processDependenciesBlockForChunk = function processDependenciesBlockForChunk(block, chunk) {
|
||||
if(block.variables) {
|
||||
block.variables.forEach(function(v) {
|
||||
v.dependencies.forEach(iteratorDependency, this);
|
||||
}, this);
|
||||
}
|
||||
if(block.dependencies) {
|
||||
block.dependencies.forEach(iteratorDependency, this);
|
||||
}
|
||||
if(block.blocks) {
|
||||
block.blocks.forEach(function(b) {
|
||||
var c;
|
||||
|
@ -592,16 +614,14 @@ Compilation.prototype.processDependenciesBlockForChunk = function processDepende
|
|||
this.processDependenciesBlockForChunk(b, c);
|
||||
}, this);
|
||||
}
|
||||
if(block.dependencies) {
|
||||
block.dependencies.forEach(iteratorDependency, this);
|
||||
}
|
||||
if(block.variables) {
|
||||
block.variables.forEach(function(v) {
|
||||
v.dependencies.forEach(iteratorDependency, this);
|
||||
}, this);
|
||||
}
|
||||
function iteratorDependency(d) {
|
||||
if(!d.module || d.weak) {
|
||||
if(!d.module) {
|
||||
return;
|
||||
}
|
||||
if(typeof d.module.index !== "number") {
|
||||
d.module.index = this.nextFreeModuleIndex++;
|
||||
}
|
||||
if(d.weak) {
|
||||
return;
|
||||
}
|
||||
if(d.module.error) {
|
||||
|
@ -612,6 +632,9 @@ Compilation.prototype.processDependenciesBlockForChunk = function processDepende
|
|||
d.module.addChunk(chunk);
|
||||
this.processDependenciesBlockForChunk(d.module, chunk);
|
||||
}
|
||||
if(typeof d.module.index2 !== "number") {
|
||||
d.module.index2 = this.nextFreeModuleIndex2++;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -12,13 +12,22 @@ var Resolver = require("enhanced-resolve/lib/Resolver");
|
|||
var NormalModuleFactory = require("./NormalModuleFactory");
|
||||
var ContextModuleFactory = require("./ContextModuleFactory");
|
||||
|
||||
function Watching(compiler, handler, watchDelay) {
|
||||
function Watching(compiler, watchOptions, handler) {
|
||||
this.startTime = null;
|
||||
this.invalid = false;
|
||||
this.error = null;
|
||||
this.stats = null;
|
||||
this.handler = handler;
|
||||
this.watchDelay = watchDelay;
|
||||
if(typeof watchOptions === "number") {
|
||||
this.watchOptions = {
|
||||
aggregateTimeout: watchOptions
|
||||
};
|
||||
} else if(watchOptions && typeof watchOptions === "object") {
|
||||
this.watchOptions = Object.create(watchOptions);
|
||||
} else {
|
||||
this.watchOptions = {};
|
||||
}
|
||||
this.watchOptions.aggregateTimeout = this.watchOptions.aggregateTimeout || 200;
|
||||
this.compiler = compiler;
|
||||
this.running = true;
|
||||
this.compiler.readRecords(function(err) {
|
||||
|
@ -89,7 +98,7 @@ Watching.prototype._done = function(err, compilation) {
|
|||
};
|
||||
|
||||
Watching.prototype.watch = function(files, dirs, missing) {
|
||||
this.watcher = this.compiler.watchFileSystem.watch(files, dirs, missing, this.startTime, this.watchDelay, function(err, filesModified, contextModified, missingModified, fileTimestamps, contextTimestamps) {
|
||||
this.watcher = this.compiler.watchFileSystem.watch(files, dirs, missing, this.startTime, this.watchOptions, function(err, filesModified, contextModified, missingModified, fileTimestamps, contextTimestamps) {
|
||||
this.watcher = null;
|
||||
if(err) return this.handler(err);
|
||||
|
||||
|
@ -159,10 +168,10 @@ module.exports = Compiler;
|
|||
Compiler.prototype = Object.create(Tapable.prototype);
|
||||
|
||||
Compiler.Watching = Watching;
|
||||
Compiler.prototype.watch = function(watchDelay, handler) {
|
||||
Compiler.prototype.watch = function(watchOptions, handler) {
|
||||
this.fileTimestamps = {};
|
||||
this.contextTimestamps = {};
|
||||
var watching = new Watching(this, handler, watchDelay || 0);
|
||||
var watching = new Watching(this, watchOptions, handler);
|
||||
return watching;
|
||||
};
|
||||
|
||||
|
|
|
@ -20,8 +20,11 @@ ConstPlugin.prototype.apply = function(compiler) {
|
|||
var param = this.evaluateExpression(statement.test);
|
||||
var bool = param.asBool();
|
||||
if(typeof bool === "boolean") {
|
||||
if(statement.test.type !== "Literal")
|
||||
this.state.current.addDependency(new ConstDependency(bool + "", param.range));
|
||||
if(statement.test.type !== "Literal") {
|
||||
var dep = new ConstDependency(bool + "", param.range);
|
||||
dep.loc = statement.loc;
|
||||
this.state.current.addDependency(dep);
|
||||
}
|
||||
return bool;
|
||||
}
|
||||
});
|
||||
|
@ -29,8 +32,11 @@ ConstPlugin.prototype.apply = function(compiler) {
|
|||
var param = this.evaluateExpression(expression.test);
|
||||
var bool = param.asBool();
|
||||
if(typeof bool === "boolean") {
|
||||
if(expression.test.type !== "Literal")
|
||||
this.state.current.addDependency(new ConstDependency(bool + "", param.range));
|
||||
if(expression.test.type !== "Literal") {
|
||||
var dep = new ConstDependency(bool + "", param.range);
|
||||
dep.loc = expression.loc;
|
||||
this.state.current.addDependency(dep);
|
||||
}
|
||||
return bool;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -68,6 +68,7 @@ ContextModule.prototype.build = function(options, compilation, resolver, fs, cal
|
|||
if(err) return callback(err);
|
||||
if(dependencies) {
|
||||
dependencies.forEach(function(dep) {
|
||||
dep.loc = dep.userRequest;
|
||||
dep.userRequest = dep.request;
|
||||
dep.request = addon + dep.userRequest;
|
||||
});
|
||||
|
|
|
@ -19,3 +19,35 @@ Dependency.prototype.updateHash = function(hash) {
|
|||
Dependency.prototype.disconnect = function() {
|
||||
this.module = null;
|
||||
};
|
||||
|
||||
Dependency.compare = function(a, b) {
|
||||
return Dependency.compareLocations(a.loc, b.loc);
|
||||
};
|
||||
|
||||
Dependency.compareLocations = function(a, b) {
|
||||
if(typeof a === "string") {
|
||||
if(typeof b === "string") {
|
||||
if(a < b) return -1;
|
||||
if(a > b) return 1;
|
||||
return 0;
|
||||
} else if(typeof b === "object") {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else if(typeof a === "object") {
|
||||
if(typeof b === "string") {
|
||||
return -1;
|
||||
} else if(typeof b === "object") {
|
||||
if(a.line < b.line) return -1;
|
||||
if(a.line > b.line) return 1;
|
||||
if(a.column < b.column) return -1;
|
||||
if(a.column > b.column) return 1;
|
||||
if(a.index < b.index) return -1;
|
||||
if(a.index > b.index) return 1;
|
||||
return 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -0,0 +1,435 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
/*global $hash$ installedModules $require$ hotDownloadManifest hotDownloadUpdateChunk modules */
|
||||
module.exports = function() {
|
||||
|
||||
var hotApplyOnUpdate = true;
|
||||
var hotCurrentHash = $hash$; // eslint-disable-line no-unused-vars
|
||||
var hotCurrentModuleData = {};
|
||||
var hotCurrentParents = []; // eslint-disable-line no-unused-vars
|
||||
|
||||
function hotCreateRequire(moduleId) { // eslint-disable-line no-unused-vars
|
||||
var me = installedModules[moduleId];
|
||||
if(!me) return $require$;
|
||||
var fn = function(request) {
|
||||
if(me.hot.active) {
|
||||
if(installedModules[request]) {
|
||||
if(installedModules[request].parents.indexOf(moduleId) < 0)
|
||||
installedModules[request].parents.push(moduleId);
|
||||
if(me.children.indexOf(request) < 0)
|
||||
me.children.push(request);
|
||||
} else hotCurrentParents = [moduleId];
|
||||
} else {
|
||||
console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId);
|
||||
hotCurrentParents = [];
|
||||
}
|
||||
return $require$(request);
|
||||
};
|
||||
for(var name in $require$) {
|
||||
if(Object.prototype.hasOwnProperty.call($require$, name)) {
|
||||
fn[name] = $require$[name];
|
||||
}
|
||||
}
|
||||
fn.e = function(chunkId, callback) {
|
||||
if(hotStatus === "ready")
|
||||
hotSetStatus("prepare");
|
||||
hotChunksLoading++;
|
||||
$require$.e(chunkId, function() {
|
||||
try {
|
||||
callback.call(null, fn);
|
||||
} finally {
|
||||
finishChunkLoading();
|
||||
}
|
||||
function finishChunkLoading() {
|
||||
hotChunksLoading--;
|
||||
if(hotStatus === "prepare") {
|
||||
if(!hotWaitingFilesMap[chunkId]) {
|
||||
hotEnsureUpdateChunk(chunkId);
|
||||
}
|
||||
if(hotChunksLoading === 0 && hotWaitingFiles === 0) {
|
||||
hotUpdateDownloaded();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
return fn;
|
||||
}
|
||||
|
||||
function hotCreateModule(moduleId) { // eslint-disable-line no-unused-vars
|
||||
var hot = {
|
||||
// private stuff
|
||||
_acceptedDependencies: {},
|
||||
_declinedDependencies: {},
|
||||
_selfAccepted: false,
|
||||
_selfDeclined: false,
|
||||
_disposeHandlers: [],
|
||||
|
||||
// Module API
|
||||
active: true,
|
||||
accept: function(dep, callback) {
|
||||
if(typeof dep === "undefined")
|
||||
hot._selfAccepted = true;
|
||||
else if(typeof dep === "function")
|
||||
hot._selfAccepted = dep;
|
||||
else if(typeof dep === "number")
|
||||
hot._acceptedDependencies[dep] = callback;
|
||||
else for(var i = 0; i < dep.length; i++)
|
||||
hot._acceptedDependencies[dep[i]] = callback;
|
||||
},
|
||||
decline: function(dep) {
|
||||
if(typeof dep === "undefined")
|
||||
hot._selfDeclined = true;
|
||||
else if(typeof dep === "number")
|
||||
hot._declinedDependencies[dep] = true;
|
||||
else for(var i = 0; i < dep.length; i++)
|
||||
hot._declinedDependencies[dep[i]] = true;
|
||||
},
|
||||
dispose: function(callback) {
|
||||
hot._disposeHandlers.push(callback);
|
||||
},
|
||||
addDisposeHandler: function(callback) {
|
||||
hot._disposeHandlers.push(callback);
|
||||
},
|
||||
removeDisposeHandler: function(callback) {
|
||||
var idx = hot._disposeHandlers.indexOf(callback);
|
||||
if(idx >= 0) hot._disposeHandlers.splice(idx, 1);
|
||||
},
|
||||
|
||||
// Management API
|
||||
check: hotCheck,
|
||||
apply: hotApply,
|
||||
status: function(l) {
|
||||
if(!l) return hotStatus;
|
||||
hotStatusHandlers.push(l);
|
||||
},
|
||||
addStatusHandler: function(l) {
|
||||
hotStatusHandlers.push(l);
|
||||
},
|
||||
removeStatusHandler: function(l) {
|
||||
var idx = hotStatusHandlers.indexOf(l);
|
||||
if(idx >= 0) hotStatusHandlers.splice(idx, 1);
|
||||
},
|
||||
|
||||
//inherit from previous dispose call
|
||||
data: hotCurrentModuleData[moduleId]
|
||||
};
|
||||
return hot;
|
||||
}
|
||||
|
||||
var hotStatusHandlers = [];
|
||||
var hotStatus = "idle";
|
||||
|
||||
function hotSetStatus(newStatus) {
|
||||
hotStatus = newStatus;
|
||||
for(var i = 0; i < hotStatusHandlers.length; i++)
|
||||
hotStatusHandlers[i].call(null, newStatus);
|
||||
}
|
||||
|
||||
// while downloading
|
||||
var hotWaitingFiles = 0;
|
||||
var hotChunksLoading = 0;
|
||||
var hotWaitingFilesMap = {};
|
||||
var hotRequestedFilesMap = {};
|
||||
var hotAvailibleFilesMap = {};
|
||||
var hotCallback;
|
||||
|
||||
// The update info
|
||||
var hotUpdate, hotUpdateNewHash;
|
||||
|
||||
function hotCheck(apply, callback) {
|
||||
if(hotStatus !== "idle") throw new Error("check() is only allowed in idle status");
|
||||
if(typeof apply === "function") {
|
||||
hotApplyOnUpdate = false;
|
||||
callback = apply;
|
||||
} else {
|
||||
hotApplyOnUpdate = apply;
|
||||
callback = callback || function(err) { if(err) throw err; };
|
||||
}
|
||||
hotSetStatus("check");
|
||||
hotDownloadManifest(function(err, update) {
|
||||
if(err) return callback(err);
|
||||
if(!update) {
|
||||
hotSetStatus("idle");
|
||||
callback(null, null);
|
||||
return;
|
||||
}
|
||||
|
||||
hotRequestedFilesMap = {};
|
||||
hotAvailibleFilesMap = {};
|
||||
hotWaitingFilesMap = {};
|
||||
for(var i = 0; i < update.c.length; i++)
|
||||
hotAvailibleFilesMap[update.c[i]] = true;
|
||||
hotUpdateNewHash = update.h;
|
||||
|
||||
hotSetStatus("prepare");
|
||||
hotCallback = callback;
|
||||
hotUpdate = {};
|
||||
/*foreachInstalledChunks*/ { // eslint-disable-line no-lone-blocks
|
||||
/*globals chunkId */
|
||||
hotEnsureUpdateChunk(chunkId);
|
||||
}
|
||||
if(hotStatus === "prepare" && hotChunksLoading === 0 && hotWaitingFiles === 0) {
|
||||
hotUpdateDownloaded();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function hotAddUpdateChunk(chunkId, moreModules) { // eslint-disable-line no-unused-vars
|
||||
if(!hotAvailibleFilesMap[chunkId] || !hotRequestedFilesMap[chunkId])
|
||||
return;
|
||||
hotRequestedFilesMap[chunkId] = false;
|
||||
for(var moduleId in moreModules) {
|
||||
if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {
|
||||
hotUpdate[moduleId] = moreModules[moduleId];
|
||||
}
|
||||
}
|
||||
if(--hotWaitingFiles === 0 && hotChunksLoading === 0) {
|
||||
hotUpdateDownloaded();
|
||||
}
|
||||
}
|
||||
|
||||
function hotEnsureUpdateChunk(chunkId) {
|
||||
if(!hotAvailibleFilesMap[chunkId]) {
|
||||
hotWaitingFilesMap[chunkId] = true;
|
||||
} else {
|
||||
hotRequestedFilesMap[chunkId] = true;
|
||||
hotWaitingFiles++;
|
||||
hotDownloadUpdateChunk(chunkId);
|
||||
}
|
||||
}
|
||||
|
||||
function hotUpdateDownloaded() {
|
||||
hotSetStatus("ready");
|
||||
var callback = hotCallback;
|
||||
hotCallback = null;
|
||||
if(!callback) return;
|
||||
if(hotApplyOnUpdate) {
|
||||
hotApply(hotApplyOnUpdate, callback);
|
||||
} else {
|
||||
var outdatedModules = [];
|
||||
for(var id in hotUpdate) {
|
||||
if(Object.prototype.hasOwnProperty.call(hotUpdate, id)) {
|
||||
outdatedModules.push(+id);
|
||||
}
|
||||
}
|
||||
callback(null, outdatedModules);
|
||||
}
|
||||
}
|
||||
|
||||
function hotApply(options, callback) {
|
||||
if(hotStatus !== "ready") throw new Error("apply() is only allowed in ready status");
|
||||
if(typeof options === "function") {
|
||||
callback = options;
|
||||
options = {};
|
||||
} else if(options && typeof options === "object") {
|
||||
callback = callback || function(err) { if(err) throw err; };
|
||||
} else {
|
||||
options = {};
|
||||
callback = callback || function(err) { if(err) throw err; };
|
||||
}
|
||||
|
||||
function getAffectedStuff(module) {
|
||||
var outdatedModules = [module];
|
||||
var outdatedDependencies = {};
|
||||
|
||||
var queue = outdatedModules.slice();
|
||||
while(queue.length > 0) {
|
||||
var moduleId = queue.pop();
|
||||
var module = installedModules[moduleId];
|
||||
if(!module || module.hot._selfAccepted)
|
||||
continue;
|
||||
if(module.hot._selfDeclined) {
|
||||
return new Error("Aborted because of self decline: " + moduleId);
|
||||
}
|
||||
if(moduleId === 0) {
|
||||
return;
|
||||
}
|
||||
for(var i = 0; i < module.parents.length; i++) {
|
||||
var parentId = module.parents[i];
|
||||
var parent = installedModules[parentId];
|
||||
if(parent.hot._declinedDependencies[moduleId]) {
|
||||
return new Error("Aborted because of declined dependency: " + moduleId + " in " + parentId);
|
||||
}
|
||||
if(outdatedModules.indexOf(parentId) >= 0) continue;
|
||||
if(parent.hot._acceptedDependencies[moduleId]) {
|
||||
if(!outdatedDependencies[parentId])
|
||||
outdatedDependencies[parentId] = [];
|
||||
addAllToSet(outdatedDependencies[parentId], [moduleId]);
|
||||
continue;
|
||||
}
|
||||
delete outdatedDependencies[parentId];
|
||||
outdatedModules.push(parentId);
|
||||
queue.push(parentId);
|
||||
}
|
||||
}
|
||||
|
||||
return [outdatedModules, outdatedDependencies];
|
||||
}
|
||||
function addAllToSet(a, b) {
|
||||
for(var i = 0; i < b.length; i++) {
|
||||
var item = b[i];
|
||||
if(a.indexOf(item) < 0)
|
||||
a.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
// at begin all updates modules are outdated
|
||||
// the "outdated" status can propagate to parents if they don't accept the children
|
||||
var outdatedDependencies = {};
|
||||
var outdatedModules = [];
|
||||
var appliedUpdate = {};
|
||||
for(var id in hotUpdate) {
|
||||
if(Object.prototype.hasOwnProperty.call(hotUpdate, id)) {
|
||||
var moduleId = +id;
|
||||
var result = getAffectedStuff(moduleId);
|
||||
if(!result) {
|
||||
if(options.ignoreUnaccepted)
|
||||
continue;
|
||||
hotSetStatus("abort");
|
||||
return callback(new Error("Aborted because " + moduleId + " is not accepted"));
|
||||
}
|
||||
if(result instanceof Error) {
|
||||
hotSetStatus("abort");
|
||||
return callback(result);
|
||||
}
|
||||
appliedUpdate[moduleId] = hotUpdate[moduleId];
|
||||
addAllToSet(outdatedModules, result[0]);
|
||||
for(var moduleId in result[1]) {
|
||||
if(Object.prototype.hasOwnProperty.call(result[1], moduleId)) {
|
||||
if(!outdatedDependencies[moduleId])
|
||||
outdatedDependencies[moduleId] = [];
|
||||
addAllToSet(outdatedDependencies[moduleId], result[1][moduleId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Store self accepted outdated modules to require them later by the module system
|
||||
var outdatedSelfAcceptedModules = [];
|
||||
for(var i = 0; i < outdatedModules.length; i++) {
|
||||
var moduleId = outdatedModules[i];
|
||||
if(installedModules[moduleId] && installedModules[moduleId].hot._selfAccepted)
|
||||
outdatedSelfAcceptedModules.push({
|
||||
module: moduleId,
|
||||
errorHandler: installedModules[moduleId].hot._selfAccepted
|
||||
});
|
||||
}
|
||||
|
||||
// Now in "dispose" phase
|
||||
hotSetStatus("dispose");
|
||||
var queue = outdatedModules.slice();
|
||||
while(queue.length > 0) {
|
||||
var moduleId = queue.pop();
|
||||
var module = installedModules[moduleId];
|
||||
if(!module) continue;
|
||||
|
||||
var data = {};
|
||||
|
||||
// Call dispose handlers
|
||||
var disposeHandlers = module.hot._disposeHandlers;
|
||||
for(var j = 0; j < disposeHandlers.length; j++) {
|
||||
var cb = disposeHandlers[j];
|
||||
cb(data);
|
||||
}
|
||||
hotCurrentModuleData[moduleId] = data;
|
||||
|
||||
// disable module (this disables requires from this module)
|
||||
module.hot.active = false;
|
||||
|
||||
// remove module from cache
|
||||
delete installedModules[moduleId];
|
||||
|
||||
// remove "parents" references from all children
|
||||
for(var j = 0; j < module.children.length; j++) {
|
||||
var child = installedModules[module.children[j]];
|
||||
if(!child) continue;
|
||||
var idx = child.parents.indexOf(moduleId);
|
||||
if(idx >= 0) {
|
||||
child.parents.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// remove outdated dependency from module children
|
||||
for(var moduleId in outdatedDependencies) {
|
||||
if(Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)) {
|
||||
var module = installedModules[moduleId];
|
||||
var moduleOutdatedDependencies = outdatedDependencies[moduleId];
|
||||
for(var j = 0; j < moduleOutdatedDependencies.length; j++) {
|
||||
var dependency = moduleOutdatedDependencies[j];
|
||||
var idx = module.children.indexOf(dependency);
|
||||
if(idx >= 0) module.children.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Not in "apply" phase
|
||||
hotSetStatus("apply");
|
||||
|
||||
hotCurrentHash = hotUpdateNewHash;
|
||||
|
||||
// insert new code
|
||||
for(var moduleId in appliedUpdate) {
|
||||
if(Object.prototype.hasOwnProperty.call(appliedUpdate, moduleId)) {
|
||||
modules[moduleId] = appliedUpdate[moduleId];
|
||||
}
|
||||
}
|
||||
|
||||
// call accept handlers
|
||||
var error = null;
|
||||
for(var moduleId in outdatedDependencies) {
|
||||
if(Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)) {
|
||||
var module = installedModules[moduleId];
|
||||
var moduleOutdatedDependencies = outdatedDependencies[moduleId];
|
||||
var callbacks = [];
|
||||
for(var i = 0; i < moduleOutdatedDependencies.length; i++) {
|
||||
var dependency = moduleOutdatedDependencies[i];
|
||||
var cb = module.hot._acceptedDependencies[dependency];
|
||||
if(callbacks.indexOf(cb) >= 0) continue;
|
||||
callbacks.push(cb);
|
||||
}
|
||||
for(var i = 0; i < callbacks.length; i++) {
|
||||
var cb = callbacks[i];
|
||||
try {
|
||||
cb(outdatedDependencies);
|
||||
} catch(err) {
|
||||
if(!error)
|
||||
error = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load self accepted modules
|
||||
for(var i = 0; i < outdatedSelfAcceptedModules.length; i++) {
|
||||
var item = outdatedSelfAcceptedModules[i];
|
||||
var moduleId = item.module;
|
||||
hotCurrentParents = [moduleId];
|
||||
try {
|
||||
$require$(moduleId);
|
||||
} catch(err) {
|
||||
if(typeof item.errorHandler === "function") {
|
||||
try {
|
||||
item.errorHandler(err);
|
||||
} catch(err) {
|
||||
if(!error)
|
||||
error = err;
|
||||
}
|
||||
} else if(!error)
|
||||
error = err;
|
||||
}
|
||||
}
|
||||
|
||||
// handle errors in accept handlers and self accepted module load
|
||||
if(error) {
|
||||
hotSetStatus("fail");
|
||||
return callback(error);
|
||||
}
|
||||
|
||||
hotSetStatus("idle");
|
||||
callback(null, outdatedModules);
|
||||
}
|
||||
};
|
|
@ -204,9 +204,11 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
|
|||
return param.isString();
|
||||
});
|
||||
}
|
||||
params.forEach(function(param){
|
||||
params.forEach(function(param, idx) {
|
||||
var dep = new ModuleHotAcceptDependency(param.string, param.range);
|
||||
dep.optional = true;
|
||||
dep.loc = Object.create(expr.loc);
|
||||
dep.loc.index = idx;
|
||||
this.state.module.addDependency(dep);
|
||||
}.bind(this));
|
||||
}
|
||||
|
@ -218,6 +220,7 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
|
|||
if(param.isString()) {
|
||||
var dep = new ModuleHotDeclineDependency(param.string, param.range);
|
||||
dep.optional = true;
|
||||
dep.loc = param.loc;
|
||||
this.state.module.addDependency(dep);
|
||||
}
|
||||
}
|
||||
|
@ -227,434 +230,4 @@ HotModuleReplacementPlugin.prototype.apply = function(compiler) {
|
|||
});
|
||||
};
|
||||
|
||||
var hotInitCode = Template.getFunctionContent(function() {
|
||||
/*global $hash$ installedModules $require$ hotDownloadManifest hotDownloadUpdateChunk modules */
|
||||
|
||||
var hotApplyOnUpdate = true;
|
||||
var hotCurrentHash = $hash$; // eslint-disable-line no-unused-vars
|
||||
var hotCurrentModuleData = {};
|
||||
var hotCurrentParents = []; // eslint-disable-line no-unused-vars
|
||||
|
||||
function hotCreateRequire(moduleId) { // eslint-disable-line no-unused-vars
|
||||
var me = installedModules[moduleId];
|
||||
if(!me) return $require$;
|
||||
var fn = function(request) {
|
||||
if(me.hot.active) {
|
||||
if(installedModules[request]) {
|
||||
if(installedModules[request].parents.indexOf(moduleId) < 0)
|
||||
installedModules[request].parents.push(moduleId);
|
||||
if(me.children.indexOf(request) < 0)
|
||||
me.children.push(request);
|
||||
} else hotCurrentParents = [moduleId];
|
||||
} else {
|
||||
console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId);
|
||||
hotCurrentParents = [];
|
||||
}
|
||||
return $require$(request);
|
||||
};
|
||||
for(var name in $require$) {
|
||||
if(Object.prototype.hasOwnProperty.call($require$, name)) {
|
||||
fn[name] = $require$[name];
|
||||
}
|
||||
}
|
||||
fn.e = function(chunkId, callback) {
|
||||
if(hotStatus === "ready")
|
||||
hotSetStatus("prepare");
|
||||
hotChunksLoading++;
|
||||
$require$.e(chunkId, function() {
|
||||
try {
|
||||
callback.call(null, fn);
|
||||
} finally {
|
||||
finishChunkLoading();
|
||||
}
|
||||
function finishChunkLoading() {
|
||||
hotChunksLoading--;
|
||||
if(hotStatus === "prepare") {
|
||||
if(!hotWaitingFilesMap[chunkId]) {
|
||||
hotEnsureUpdateChunk(chunkId);
|
||||
}
|
||||
if(hotChunksLoading === 0 && hotWaitingFiles === 0) {
|
||||
hotUpdateDownloaded();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
return fn;
|
||||
}
|
||||
|
||||
function hotCreateModule(moduleId) { // eslint-disable-line no-unused-vars
|
||||
var hot = {
|
||||
// private stuff
|
||||
_acceptedDependencies: {},
|
||||
_declinedDependencies: {},
|
||||
_selfAccepted: false,
|
||||
_selfDeclined: false,
|
||||
_disposeHandlers: [],
|
||||
|
||||
// Module API
|
||||
active: true,
|
||||
accept: function(dep, callback) {
|
||||
if(typeof dep === "undefined")
|
||||
hot._selfAccepted = true;
|
||||
else if(typeof dep === "function")
|
||||
hot._selfAccepted = dep;
|
||||
else if(typeof dep === "number")
|
||||
hot._acceptedDependencies[dep] = callback;
|
||||
else for(var i = 0; i < dep.length; i++)
|
||||
hot._acceptedDependencies[dep[i]] = callback;
|
||||
},
|
||||
decline: function(dep) {
|
||||
if(typeof dep === "undefined")
|
||||
hot._selfDeclined = true;
|
||||
else if(typeof dep === "number")
|
||||
hot._declinedDependencies[dep] = true;
|
||||
else for(var i = 0; i < dep.length; i++)
|
||||
hot._declinedDependencies[dep[i]] = true;
|
||||
},
|
||||
dispose: function(callback) {
|
||||
hot._disposeHandlers.push(callback);
|
||||
},
|
||||
addDisposeHandler: function(callback) {
|
||||
hot._disposeHandlers.push(callback);
|
||||
},
|
||||
removeDisposeHandler: function(callback) {
|
||||
var idx = hot._disposeHandlers.indexOf(callback);
|
||||
if(idx >= 0) hot._disposeHandlers.splice(idx, 1);
|
||||
},
|
||||
|
||||
// Management API
|
||||
check: hotCheck,
|
||||
apply: hotApply,
|
||||
status: function(l) {
|
||||
if(!l) return hotStatus;
|
||||
hotStatusHandlers.push(l);
|
||||
},
|
||||
addStatusHandler: function(l) {
|
||||
hotStatusHandlers.push(l);
|
||||
},
|
||||
removeStatusHandler: function(l) {
|
||||
var idx = hotStatusHandlers.indexOf(l);
|
||||
if(idx >= 0) hotStatusHandlers.splice(idx, 1);
|
||||
},
|
||||
|
||||
//inherit from previous dispose call
|
||||
data: hotCurrentModuleData[moduleId]
|
||||
};
|
||||
return hot;
|
||||
}
|
||||
|
||||
var hotStatusHandlers = [];
|
||||
var hotStatus = "idle";
|
||||
|
||||
function hotSetStatus(newStatus) {
|
||||
hotStatus = newStatus;
|
||||
for(var i = 0; i < hotStatusHandlers.length; i++)
|
||||
hotStatusHandlers[i].call(null, newStatus);
|
||||
}
|
||||
|
||||
// while downloading
|
||||
var hotWaitingFiles = 0;
|
||||
var hotChunksLoading = 0;
|
||||
var hotWaitingFilesMap = {};
|
||||
var hotRequestedFilesMap = {};
|
||||
var hotAvailibleFilesMap = {};
|
||||
var hotCallback;
|
||||
|
||||
// The update info
|
||||
var hotUpdate, hotUpdateNewHash;
|
||||
|
||||
function hotCheck(apply, callback) {
|
||||
if(hotStatus !== "idle") throw new Error("check() is only allowed in idle status");
|
||||
if(typeof apply === "function") {
|
||||
hotApplyOnUpdate = false;
|
||||
callback = apply;
|
||||
} else {
|
||||
hotApplyOnUpdate = apply;
|
||||
callback = callback || function(err) { if(err) throw err; };
|
||||
}
|
||||
hotSetStatus("check");
|
||||
hotDownloadManifest(function(err, update) {
|
||||
if(err) return callback(err);
|
||||
if(!update) {
|
||||
hotSetStatus("idle");
|
||||
callback(null, null);
|
||||
return;
|
||||
}
|
||||
|
||||
hotRequestedFilesMap = {};
|
||||
hotAvailibleFilesMap = {};
|
||||
hotWaitingFilesMap = {};
|
||||
for(var i = 0; i < update.c.length; i++)
|
||||
hotAvailibleFilesMap[update.c[i]] = true;
|
||||
hotUpdateNewHash = update.h;
|
||||
|
||||
hotSetStatus("prepare");
|
||||
hotCallback = callback;
|
||||
hotUpdate = {};
|
||||
/*foreachInstalledChunks*/ { // eslint-disable-line no-lone-blocks
|
||||
/*globals chunkId */
|
||||
hotEnsureUpdateChunk(chunkId);
|
||||
}
|
||||
if(hotStatus === "prepare" && hotChunksLoading === 0 && hotWaitingFiles === 0) {
|
||||
hotUpdateDownloaded();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function hotAddUpdateChunk(chunkId, moreModules) { // eslint-disable-line no-unused-vars
|
||||
if(!hotAvailibleFilesMap[chunkId] || !hotRequestedFilesMap[chunkId])
|
||||
return;
|
||||
hotRequestedFilesMap[chunkId] = false;
|
||||
for(var moduleId in moreModules) {
|
||||
if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {
|
||||
hotUpdate[moduleId] = moreModules[moduleId];
|
||||
}
|
||||
}
|
||||
if(--hotWaitingFiles === 0 && hotChunksLoading === 0) {
|
||||
hotUpdateDownloaded();
|
||||
}
|
||||
}
|
||||
|
||||
function hotEnsureUpdateChunk(chunkId) {
|
||||
if(!hotAvailibleFilesMap[chunkId]) {
|
||||
hotWaitingFilesMap[chunkId] = true;
|
||||
} else {
|
||||
hotRequestedFilesMap[chunkId] = true;
|
||||
hotWaitingFiles++;
|
||||
hotDownloadUpdateChunk(chunkId);
|
||||
}
|
||||
}
|
||||
|
||||
function hotUpdateDownloaded() {
|
||||
hotSetStatus("ready");
|
||||
var callback = hotCallback;
|
||||
hotCallback = null;
|
||||
if(!callback) return;
|
||||
if(hotApplyOnUpdate) {
|
||||
hotApply(hotApplyOnUpdate, callback);
|
||||
} else {
|
||||
var outdatedModules = [];
|
||||
for(var id in hotUpdate) {
|
||||
if(Object.prototype.hasOwnProperty.call(hotUpdate, id)) {
|
||||
outdatedModules.push(+id);
|
||||
}
|
||||
}
|
||||
callback(null, outdatedModules);
|
||||
}
|
||||
}
|
||||
|
||||
function hotApply(options, callback) {
|
||||
if(hotStatus !== "ready") throw new Error("apply() is only allowed in ready status");
|
||||
if(typeof options === "function") {
|
||||
callback = options;
|
||||
options = {};
|
||||
} else if(options && typeof options === "object") {
|
||||
callback = callback || function(err) { if(err) throw err; };
|
||||
} else {
|
||||
options = {};
|
||||
callback = callback || function(err) { if(err) throw err; };
|
||||
}
|
||||
|
||||
function getAffectedStuff(module) {
|
||||
var outdatedModules = [module];
|
||||
var outdatedDependencies = {};
|
||||
|
||||
var queue = outdatedModules.slice();
|
||||
while(queue.length > 0) {
|
||||
var moduleId = queue.pop();
|
||||
var module = installedModules[moduleId];
|
||||
if(!module || module.hot._selfAccepted)
|
||||
continue;
|
||||
if(module.hot._selfDeclined) {
|
||||
return new Error("Aborted because of self decline: " + moduleId);
|
||||
}
|
||||
if(moduleId === 0) {
|
||||
return;
|
||||
}
|
||||
for(var i = 0; i < module.parents.length; i++) {
|
||||
var parentId = module.parents[i];
|
||||
var parent = installedModules[parentId];
|
||||
if(parent.hot._declinedDependencies[moduleId]) {
|
||||
return new Error("Aborted because of declined dependency: " + moduleId + " in " + parentId);
|
||||
}
|
||||
if(outdatedModules.indexOf(parentId) >= 0) continue;
|
||||
if(parent.hot._acceptedDependencies[moduleId]) {
|
||||
if(!outdatedDependencies[parentId])
|
||||
outdatedDependencies[parentId] = [];
|
||||
addAllToSet(outdatedDependencies[parentId], [moduleId]);
|
||||
continue;
|
||||
}
|
||||
delete outdatedDependencies[parentId];
|
||||
outdatedModules.push(parentId);
|
||||
queue.push(parentId);
|
||||
}
|
||||
}
|
||||
|
||||
return [outdatedModules, outdatedDependencies];
|
||||
}
|
||||
function addAllToSet(a, b) {
|
||||
for(var i = 0; i < b.length; i++) {
|
||||
var item = b[i];
|
||||
if(a.indexOf(item) < 0)
|
||||
a.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
// at begin all updates modules are outdated
|
||||
// the "outdated" status can propagate to parents if they don't accept the children
|
||||
var outdatedDependencies = {};
|
||||
var outdatedModules = [];
|
||||
var appliedUpdate = {};
|
||||
for(var id in hotUpdate) {
|
||||
if(Object.prototype.hasOwnProperty.call(hotUpdate, id)) {
|
||||
var moduleId = +id;
|
||||
var result = getAffectedStuff(moduleId);
|
||||
if(!result) {
|
||||
if(options.ignoreUnaccepted)
|
||||
continue;
|
||||
hotSetStatus("abort");
|
||||
return callback(new Error("Aborted because " + moduleId + " is not accepted"));
|
||||
}
|
||||
if(result instanceof Error) {
|
||||
hotSetStatus("abort");
|
||||
return callback(result);
|
||||
}
|
||||
appliedUpdate[moduleId] = hotUpdate[moduleId];
|
||||
addAllToSet(outdatedModules, result[0]);
|
||||
for(var moduleId in result[1]) {
|
||||
if(Object.prototype.hasOwnProperty.call(result[1], moduleId)) {
|
||||
if(!outdatedDependencies[moduleId])
|
||||
outdatedDependencies[moduleId] = [];
|
||||
addAllToSet(outdatedDependencies[moduleId], result[1][moduleId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Store self accepted outdated modules to require them later by the module system
|
||||
var outdatedSelfAcceptedModules = [];
|
||||
for(var i = 0; i < outdatedModules.length; i++) {
|
||||
var moduleId = outdatedModules[i];
|
||||
if(installedModules[moduleId] && installedModules[moduleId].hot._selfAccepted)
|
||||
outdatedSelfAcceptedModules.push({
|
||||
module: moduleId,
|
||||
errorHandler: installedModules[moduleId].hot._selfAccepted
|
||||
});
|
||||
}
|
||||
|
||||
// Now in "dispose" phase
|
||||
hotSetStatus("dispose");
|
||||
var queue = outdatedModules.slice();
|
||||
while(queue.length > 0) {
|
||||
var moduleId = queue.pop();
|
||||
var module = installedModules[moduleId];
|
||||
if(!module) continue;
|
||||
|
||||
var data = {};
|
||||
|
||||
// Call dispose handlers
|
||||
var disposeHandlers = module.hot._disposeHandlers;
|
||||
for(var j = 0; j < disposeHandlers.length; j++) {
|
||||
var cb = disposeHandlers[j];
|
||||
cb(data);
|
||||
}
|
||||
hotCurrentModuleData[moduleId] = data;
|
||||
|
||||
// disable module (this disables requires from this module)
|
||||
module.hot.active = false;
|
||||
|
||||
// remove module from cache
|
||||
delete installedModules[moduleId];
|
||||
|
||||
// remove "parents" references from all children
|
||||
for(var j = 0; j < module.children.length; j++) {
|
||||
var child = installedModules[module.children[j]];
|
||||
if(!child) continue;
|
||||
var idx = child.parents.indexOf(moduleId);
|
||||
if(idx >= 0) {
|
||||
child.parents.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// remove outdated dependency from module children
|
||||
for(var moduleId in outdatedDependencies) {
|
||||
if(Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)) {
|
||||
var module = installedModules[moduleId];
|
||||
var moduleOutdatedDependencies = outdatedDependencies[moduleId];
|
||||
for(var j = 0; j < moduleOutdatedDependencies.length; j++) {
|
||||
var dependency = moduleOutdatedDependencies[j];
|
||||
var idx = module.children.indexOf(dependency);
|
||||
if(idx >= 0) module.children.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Not in "apply" phase
|
||||
hotSetStatus("apply");
|
||||
|
||||
hotCurrentHash = hotUpdateNewHash;
|
||||
|
||||
// insert new code
|
||||
for(var moduleId in appliedUpdate) {
|
||||
if(Object.prototype.hasOwnProperty.call(appliedUpdate, moduleId)) {
|
||||
modules[moduleId] = appliedUpdate[moduleId];
|
||||
}
|
||||
}
|
||||
|
||||
// call accept handlers
|
||||
var error = null;
|
||||
for(var moduleId in outdatedDependencies) {
|
||||
if(Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)) {
|
||||
var module = installedModules[moduleId];
|
||||
var moduleOutdatedDependencies = outdatedDependencies[moduleId];
|
||||
var callbacks = [];
|
||||
for(var i = 0; i < moduleOutdatedDependencies.length; i++) {
|
||||
var dependency = moduleOutdatedDependencies[i];
|
||||
var cb = module.hot._acceptedDependencies[dependency];
|
||||
if(callbacks.indexOf(cb) >= 0) continue;
|
||||
callbacks.push(cb);
|
||||
}
|
||||
for(var i = 0; i < callbacks.length; i++) {
|
||||
var cb = callbacks[i];
|
||||
try {
|
||||
cb(outdatedDependencies);
|
||||
} catch(err) {
|
||||
if(!error)
|
||||
error = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load self accepted modules
|
||||
for(var i = 0; i < outdatedSelfAcceptedModules.length; i++) {
|
||||
var item = outdatedSelfAcceptedModules[i];
|
||||
var moduleId = item.module;
|
||||
hotCurrentParents = [moduleId];
|
||||
try {
|
||||
$require$(moduleId);
|
||||
} catch(err) {
|
||||
if(typeof item.errorHandler === "function") {
|
||||
try {
|
||||
item.errorHandler(err);
|
||||
} catch(err) {
|
||||
if(!error)
|
||||
error = err;
|
||||
}
|
||||
} else if(!error)
|
||||
error = err;
|
||||
}
|
||||
}
|
||||
|
||||
// handle errors in accept handlers and self accepted module load
|
||||
if(error) {
|
||||
hotSetStatus("fail");
|
||||
return callback(error);
|
||||
}
|
||||
|
||||
hotSetStatus("idle");
|
||||
callback(null, outdatedModules);
|
||||
}
|
||||
});
|
||||
var hotInitCode = Template.getFunctionContent(require("./HotModuleReplacement.runtime.js"));
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
/*globals hotAddUpdateChunk parentHotUpdateCallback document XMLHttpRequest $require$ $hotChunkFilename$ $hotMainFilename$ */
|
||||
module.exports = function() {
|
||||
function webpackHotUpdateCallback(chunkId, moreModules) { // eslint-disable-line no-unused-vars
|
||||
hotAddUpdateChunk(chunkId, moreModules);
|
||||
if(parentHotUpdateCallback) parentHotUpdateCallback(chunkId, moreModules);
|
||||
}
|
||||
|
||||
function hotDownloadUpdateChunk(chunkId) { // eslint-disable-line no-unused-vars
|
||||
var head = document.getElementsByTagName("head")[0];
|
||||
var script = document.createElement("script");
|
||||
script.type = "text/javascript";
|
||||
script.charset = "utf-8";
|
||||
script.src = $require$.p + $hotChunkFilename$;
|
||||
head.appendChild(script);
|
||||
}
|
||||
|
||||
function hotDownloadManifest(callback) { // eslint-disable-line no-unused-vars
|
||||
if(typeof XMLHttpRequest === "undefined")
|
||||
return callback(new Error("No browser support"));
|
||||
try {
|
||||
var request = new XMLHttpRequest();
|
||||
var requestPath = $require$.p + $hotMainFilename$;
|
||||
request.open("GET", requestPath, true);
|
||||
request.timeout = 10000;
|
||||
request.send(null);
|
||||
} catch(err) {
|
||||
return callback(err);
|
||||
}
|
||||
request.onreadystatechange = function() {
|
||||
if(request.readyState !== 4) return;
|
||||
if(request.status === 0) {
|
||||
// timeout
|
||||
callback(new Error("Manifest request to " + requestPath + " timed out."));
|
||||
} else if(request.status === 404) {
|
||||
// no update available
|
||||
callback();
|
||||
} else if(request.status !== 200 && request.status !== 304) {
|
||||
// other failure
|
||||
callback(new Error("Manifest request to " + requestPath + " failed."));
|
||||
} else {
|
||||
// success
|
||||
try {
|
||||
var update = JSON.parse(request.responseText);
|
||||
} catch(e) {
|
||||
callback(e);
|
||||
return;
|
||||
}
|
||||
callback(null, update);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
|
@ -140,58 +140,7 @@ JsonpMainTemplatePlugin.prototype.apply = function(mainTemplate) {
|
|||
|
||||
return source + "\n" +
|
||||
"var parentHotUpdateCallback = this[" + JSON.stringify(hotUpdateFunction) + "];\n" +
|
||||
"this[" + JSON.stringify(hotUpdateFunction) + "] = " + Template.getFunctionContent(function() {
|
||||
/*globals hotAddUpdateChunk parentHotUpdateCallback document XMLHttpRequest $require$ $hotChunkFilename$ $hotMainFilename$ */
|
||||
function webpackHotUpdateCallback(chunkId, moreModules) { // eslint-disable-line no-unused-vars
|
||||
hotAddUpdateChunk(chunkId, moreModules);
|
||||
if(parentHotUpdateCallback) parentHotUpdateCallback(chunkId, moreModules);
|
||||
}
|
||||
|
||||
function hotDownloadUpdateChunk(chunkId) { // eslint-disable-line no-unused-vars
|
||||
var head = document.getElementsByTagName("head")[0];
|
||||
var script = document.createElement("script");
|
||||
script.type = "text/javascript";
|
||||
script.charset = "utf-8";
|
||||
script.src = $require$.p + $hotChunkFilename$;
|
||||
head.appendChild(script);
|
||||
}
|
||||
|
||||
function hotDownloadManifest(callback) { // eslint-disable-line no-unused-vars
|
||||
if(typeof XMLHttpRequest === "undefined")
|
||||
return callback(new Error("No browser support"));
|
||||
try {
|
||||
var request = new XMLHttpRequest();
|
||||
var requestPath = $require$.p + $hotMainFilename$;
|
||||
request.open("GET", requestPath, true);
|
||||
request.timeout = 10000;
|
||||
request.send(null);
|
||||
} catch(err) {
|
||||
return callback(err);
|
||||
}
|
||||
request.onreadystatechange = function() {
|
||||
if(request.readyState !== 4) return;
|
||||
if(request.status === 0) {
|
||||
// timeout
|
||||
callback(new Error("Manifest request to " + requestPath + " timed out."));
|
||||
} else if(request.status === 404) {
|
||||
// no update available
|
||||
callback();
|
||||
} else if(request.status !== 200 && request.status !== 304) {
|
||||
// other failure
|
||||
callback(new Error("Manifest request to " + requestPath + " failed."));
|
||||
} else {
|
||||
// success
|
||||
try {
|
||||
var update = JSON.parse(request.responseText);
|
||||
} catch(e) {
|
||||
callback(e);
|
||||
return;
|
||||
}
|
||||
callback(null, update);
|
||||
}
|
||||
};
|
||||
}
|
||||
})
|
||||
"this[" + JSON.stringify(hotUpdateFunction) + "] = " + Template.getFunctionContent(require("./JsonpMainTemplate.runtime.js"))
|
||||
.replace(/\$require\$/g, this.requireFn)
|
||||
.replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename)
|
||||
.replace(/\$hotChunkFilename\$/g, currentHotUpdateChunkFilename)
|
||||
|
|
|
@ -22,8 +22,10 @@ MultiEntryPlugin.prototype.apply = function(compiler) {
|
|||
compilation.dependencyFactories.set(SingleEntryDependency, normalModuleFactory);
|
||||
});
|
||||
compiler.plugin("make", function(compilation, callback) {
|
||||
compilation.addEntry(this.context, new MultiEntryDependency(this.entries.map(function(e) {
|
||||
return new SingleEntryDependency(e);
|
||||
}), this.name), this.name, callback);
|
||||
compilation.addEntry(this.context, new MultiEntryDependency(this.entries.map(function(e, idx) {
|
||||
var dep = new SingleEntryDependency(e);
|
||||
dep.loc = this.name + ":" + idx;
|
||||
return dep;
|
||||
}, this), this.name), this.name, callback);
|
||||
}.bind(this));
|
||||
};
|
|
@ -17,6 +17,8 @@ SingleEntryPlugin.prototype.apply = function(compiler) {
|
|||
compilation.dependencyFactories.set(SingleEntryDependency, normalModuleFactory);
|
||||
});
|
||||
compiler.plugin("make", function(compilation, callback) {
|
||||
compilation.addEntry(this.context, new SingleEntryDependency(this.entry), this.name, callback);
|
||||
var dep = new SingleEntryDependency(this.entry);
|
||||
dep.loc = this.name;
|
||||
compilation.addEntry(this.context, dep, this.name, callback);
|
||||
}.bind(this));
|
||||
};
|
|
@ -88,6 +88,7 @@ Stats.prototype.toJson = function toJson(options, forToString) {
|
|||
text += "\n @ " + e.origin.readableIdentifier(requestShortener);
|
||||
e.dependencies.forEach(function(dep) {
|
||||
if(!dep.loc) return;
|
||||
if(typeof dep.loc === "string") return;
|
||||
if(!dep.loc.start) return;
|
||||
if(!dep.loc.end) return;
|
||||
text += " " + dep.loc.start.line + ":" + dep.loc.start.column + "-" +
|
||||
|
@ -185,7 +186,7 @@ Stats.prototype.toJson = function toJson(options, forToString) {
|
|||
};
|
||||
var dep = reason.dependency;
|
||||
if(dep.templateModules) obj.templateModules = dep.templateModules.map(function(module) { return module.id; });
|
||||
if(dep.loc) obj.loc = dep.loc.start.line + ":" + dep.loc.start.column + "-" +
|
||||
if(typeof dep.loc === "object") obj.loc = dep.loc.start.line + ":" + dep.loc.start.column + "-" +
|
||||
(dep.loc.start.line !== dep.loc.end.line ? dep.loc.end.line + ":" : "") + dep.loc.end.column;
|
||||
return obj;
|
||||
}).sort(function(a, b) {
|
||||
|
@ -225,7 +226,7 @@ Stats.prototype.toJson = function toJson(options, forToString) {
|
|||
module: origin.module ? origin.module.identifier() : "",
|
||||
moduleIdentifier: origin.module ? origin.module.identifier() : "",
|
||||
moduleName: origin.module ? origin.module.readableIdentifier(requestShortener) : "",
|
||||
loc: origin.loc ? obj.loc = origin.loc.start.line + ":" + origin.loc.start.column + "-" +
|
||||
loc: typeof origin.loc === "object" ? obj.loc = origin.loc.start.line + ":" + origin.loc.start.column + "-" +
|
||||
(origin.loc.start.line !== origin.loc.end.line ? origin.loc.end.line + ":" : "") + origin.loc.end.column : "",
|
||||
name: origin.name,
|
||||
reasons: origin.reasons || []
|
||||
|
|
|
@ -15,6 +15,7 @@ function AMDDefineDependency(range, arrayRange, functionRange, objectRange) {
|
|||
module.exports = AMDDefineDependency;
|
||||
|
||||
AMDDefineDependency.prototype = Object.create(NullDependency.prototype);
|
||||
AMDDefineDependency.prototype.constructor = AMDDefineDependency;
|
||||
AMDDefineDependency.prototype.type = "amd define";
|
||||
|
||||
AMDDefineDependency.Template = function AMDRequireDependencyTemplate() {};
|
||||
|
|
|
@ -42,6 +42,7 @@ AMDPlugin.prototype.apply = function(compiler) {
|
|||
compiler.parser.plugin("expression " + expr, function(expr) {
|
||||
var dep = new AMDRequireItemDependency(module, expr.range);
|
||||
dep.userRequest = expr;
|
||||
dep.loc = expr.loc;
|
||||
this.state.current.addDependency(dep);
|
||||
return true;
|
||||
});
|
||||
|
@ -98,6 +99,7 @@ AMDPlugin.prototype.apply = function(compiler) {
|
|||
compiler.parser.plugin("rename define", function(expr) {
|
||||
var dep = new AMDRequireItemDependency("!!webpack amd define", expr.range);
|
||||
dep.userRequest = "define";
|
||||
dep.loc = expr.loc;
|
||||
this.state.current.addDependency(dep);
|
||||
return false;
|
||||
});
|
||||
|
|
|
@ -13,6 +13,7 @@ function AMDRequireArrayDependency(depsArray, range) {
|
|||
module.exports = AMDRequireArrayDependency;
|
||||
|
||||
AMDRequireArrayDependency.prototype = Object.create(Dependency.prototype);
|
||||
AMDRequireArrayDependency.prototype.constructor = AMDRequireArrayDependency;
|
||||
AMDRequireArrayDependency.prototype.type = "amd require array";
|
||||
|
||||
AMDRequireArrayDependency.Template = function AMDRequireArrayDependencyTemplate() {};
|
||||
|
|
|
@ -13,6 +13,7 @@ function AMDRequireContextDependency(request, recursive, regExp, range, valueRan
|
|||
module.exports = AMDRequireContextDependency;
|
||||
|
||||
AMDRequireContextDependency.prototype = Object.create(ContextDependency.prototype);
|
||||
AMDRequireContextDependency.prototype.constructor = AMDRequireContextDependency;
|
||||
AMDRequireContextDependency.prototype.type = "amd require context";
|
||||
|
||||
AMDRequireContextDependency.Template = require("./ContextDependencyTemplateAsRequireCall");
|
||||
|
|
|
@ -15,7 +15,9 @@ function AMDRequireDependenciesBlock(expr, arrayRange, functionRange, module, lo
|
|||
arrayRange ? arrayRange :
|
||||
functionRange ? functionRange :
|
||||
expr.range;
|
||||
this.addDependency(new AMDRequireDependency(this));
|
||||
var dep = new AMDRequireDependency(this);
|
||||
dep.loc = loc;
|
||||
this.addDependency(dep);
|
||||
}
|
||||
module.exports = AMDRequireDependenciesBlock;
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ function AMDRequireDependency(block) {
|
|||
module.exports = AMDRequireDependency;
|
||||
|
||||
AMDRequireDependency.prototype = Object.create(NullDependency.prototype);
|
||||
AMDRequireDependency.prototype.constructor = AMDRequireDependency;
|
||||
|
||||
AMDRequireDependency.Template = function AMDRequireDependencyTemplate() {};
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ function AMDRequireItemDependency(request, range) {
|
|||
module.exports = AMDRequireItemDependency;
|
||||
|
||||
AMDRequireItemDependency.prototype = Object.create(ModuleDependency.prototype);
|
||||
AMDRequireItemDependency.prototype.constructor = AMDRequireItemDependency;
|
||||
AMDRequireItemDependency.prototype.type = "amd require";
|
||||
|
||||
AMDRequireItemDependency.Template = require("./ModuleDependencyTemplateAsRequireId");
|
||||
|
|
|
@ -13,6 +13,7 @@ function CommonJsRequireContextDependency(request, recursive, regExp, range, val
|
|||
module.exports = CommonJsRequireContextDependency;
|
||||
|
||||
CommonJsRequireContextDependency.prototype = Object.create(ContextDependency.prototype);
|
||||
CommonJsRequireContextDependency.prototype.constructor = CommonJsRequireContextDependency;
|
||||
CommonJsRequireContextDependency.prototype.type = "cjs require context";
|
||||
|
||||
CommonJsRequireContextDependency.Template = require("./ContextDependencyTemplateAsRequireCall");
|
||||
|
|
|
@ -12,6 +12,7 @@ function CommonJsRequireDependency(request, range) {
|
|||
module.exports = CommonJsRequireDependency;
|
||||
|
||||
CommonJsRequireDependency.prototype = Object.create(ModuleDependency.prototype);
|
||||
CommonJsRequireDependency.prototype.constructor = CommonJsRequireDependency;
|
||||
CommonJsRequireDependency.prototype.type = "cjs require";
|
||||
|
||||
CommonJsRequireDependency.Template = require("./ModuleDependencyTemplateAsId");
|
||||
|
|
|
@ -34,19 +34,28 @@ CommonJsRequireDependencyParserPlugin.prototype.apply = function(parser) {
|
|||
});
|
||||
parser.plugin("call require", function(expr) {
|
||||
if(expr.arguments.length !== 1) return;
|
||||
var localModule;
|
||||
var localModule, dep;
|
||||
var param = this.evaluateExpression(expr.arguments[0]);
|
||||
if(param.isConditional()) {
|
||||
this.state.current.addDependency(new RequireHeaderDependency(expr.callee.range));
|
||||
var isExpression = false;
|
||||
var prevLength = this.state.current.dependencies.length;
|
||||
dep = new RequireHeaderDependency(expr.callee.range);
|
||||
dep.loc = expr.loc;
|
||||
this.state.current.addDependency(dep);
|
||||
param.options.forEach(function(param) {
|
||||
var result = this.applyPluginsBailResult("call require:commonjs:item", expr, param);
|
||||
if(result === undefined) {
|
||||
throw new Error("Cannot convert options with mixed known and unknown stuff");
|
||||
isExpression = true;
|
||||
}
|
||||
}, this);
|
||||
return true;
|
||||
} else if(param.isString() && (localModule = LocalModulesHelpers.getLocalModule(this.state, param.string))) {
|
||||
var dep = new LocalModuleDependency(localModule, expr.range);
|
||||
if(isExpression) {
|
||||
this.state.current.dependencies.length = prevLength;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(param.isString() && (localModule = LocalModulesHelpers.getLocalModule(this.state, param.string))) {
|
||||
dep = new LocalModuleDependency(localModule, expr.range);
|
||||
dep.loc = expr.loc;
|
||||
this.state.current.addDependency(dep);
|
||||
return true;
|
||||
|
@ -55,7 +64,9 @@ CommonJsRequireDependencyParserPlugin.prototype.apply = function(parser) {
|
|||
if(result === undefined) {
|
||||
this.applyPluginsBailResult("call require:commonjs:context", expr, param);
|
||||
} else {
|
||||
this.state.current.addDependency(new RequireHeaderDependency(expr.callee.range));
|
||||
dep = new RequireHeaderDependency(expr.callee.range);
|
||||
dep.loc = expr.loc;
|
||||
this.state.current.addDependency(dep);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ function ConstDependency(expression, range) {
|
|||
module.exports = ConstDependency;
|
||||
|
||||
ConstDependency.prototype = Object.create(NullDependency.prototype);
|
||||
ConstDependency.prototype.constructor = ConstDependency;
|
||||
|
||||
ConstDependency.Template = function ConstDependencyTemplate() {};
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ function ContextDependency(request, recursive, regExp) {
|
|||
module.exports = ContextDependency;
|
||||
|
||||
ContextDependency.prototype = Object.create(Dependency.prototype);
|
||||
ContextDependency.prototype.constructor = ContextDependency;
|
||||
ContextDependency.prototype.isEqualResource = function(other) {
|
||||
if(!(other instanceof ContextDependency))
|
||||
return false;
|
||||
|
|
|
@ -11,4 +11,5 @@ function ContextElementDependency(request) {
|
|||
module.exports = ContextElementDependency;
|
||||
|
||||
ContextElementDependency.prototype = Object.create(ModuleDependency.prototype);
|
||||
ContextElementDependency.prototype.constructor = ContextElementDependency;
|
||||
ContextElementDependency.prototype.type = "context element";
|
||||
|
|
|
@ -13,6 +13,7 @@ function LabeledExportsDependency(name, pos) {
|
|||
module.exports = LabeledExportsDependency;
|
||||
|
||||
LabeledExportsDependency.prototype = Object.create(NullDependency.prototype);
|
||||
LabeledExportsDependency.prototype.constructor = LabeledExportsDependency;
|
||||
|
||||
LabeledExportsDependency.Template = function LabeledExportsDependencyTemplate() {};
|
||||
|
||||
|
|
|
@ -12,23 +12,24 @@ function LabeledModuleDependency(request, range) {
|
|||
module.exports = LabeledModuleDependency;
|
||||
|
||||
LabeledModuleDependency.prototype = Object.create(ModuleDependency.prototype);
|
||||
LabeledModuleDependency.prototype.constructor = LabeledModuleDependency;
|
||||
LabeledModuleDependency.prototype.type = "labeled require";
|
||||
|
||||
LabeledModuleDependency.Template = function LabeledModuleDependencyTemplate() {};
|
||||
|
||||
LabeledModuleDependency.Template.prototype.apply = function(dep, source, outputOptions, requestShortener) {
|
||||
var comment = "";
|
||||
var comment = "", content;
|
||||
if(outputOptions.pathinfo) comment = "/*! " + requestShortener.shorten(dep.request) + " */ ";
|
||||
if(dep.module && dep.module.meta && dep.module.meta.exports) {
|
||||
var content = "var __WEBPACK_LABELED_MODULE__" + dep.module.id + " = __webpack_require__(" + comment + dep.module.id + ")";
|
||||
content = "var __WEBPACK_LABELED_MODULE__" + dep.module.id + " = __webpack_require__(" + comment + dep.module.id + ")";
|
||||
dep.module.meta.exports.forEach(function(e) {
|
||||
content += ", " + e + " = __WEBPACK_LABELED_MODULE__" + dep.module.id + "." + e;
|
||||
});
|
||||
content += ";";
|
||||
} else if(dep.module) {
|
||||
var content = require("./WebpackMissingModule").moduleMetaInfo(dep.request);
|
||||
content = require("./WebpackMissingModule").moduleMetaInfo(dep.request);
|
||||
} else {
|
||||
var content = require("./WebpackMissingModule").module(dep.request);
|
||||
content = require("./WebpackMissingModule").module(dep.request);
|
||||
}
|
||||
source.replace(dep.range[0], dep.range[1] - 1, content);
|
||||
};
|
|
@ -11,4 +11,5 @@ function LoaderDependency(request) {
|
|||
module.exports = LoaderDependency;
|
||||
|
||||
LoaderDependency.prototype = Object.create(ModuleDependency.prototype);
|
||||
LoaderDependency.prototype.constructor = LoaderDependency;
|
||||
LoaderDependency.prototype.type = "loader";
|
||||
|
|
|
@ -18,6 +18,7 @@ LoaderPlugin.prototype.apply = function(compiler) {
|
|||
compilation.plugin("normal-module-loader", function(loaderContext, module) {
|
||||
loaderContext.loadModule = function loadModule(request, callback) {
|
||||
var dep = new LoaderDependency(request);
|
||||
dep.loc = request;
|
||||
compilation.addModuleDependencies(module, [[dep]], true, "lm", false, function(err) {
|
||||
if(err) return callback(err);
|
||||
|
||||
|
@ -31,14 +32,15 @@ LoaderPlugin.prototype.apply = function(compiler) {
|
|||
|
||||
if(dep.module.error) return callback(dep.module.error);
|
||||
if(!dep.module._source) throw new Error("The module created for a LoaderDependency must have a property _source");
|
||||
var source, map;
|
||||
var moduleSource = dep.module._source;
|
||||
if(moduleSource.sourceAndMap) {
|
||||
var sourceAndMap = moduleSource.sourceAndMap();
|
||||
var map = sourceAndMap.map;
|
||||
var source = sourceAndMap.source;
|
||||
map = sourceAndMap.map;
|
||||
source = sourceAndMap.source;
|
||||
} else {
|
||||
var map = moduleSource.map();
|
||||
var source = moduleSource.source();
|
||||
map = moduleSource.map();
|
||||
source = moduleSource.source();
|
||||
}
|
||||
if(dep.module.fileDependencies) {
|
||||
dep.module.fileDependencies.forEach(function(dep) {
|
||||
|
|
|
@ -14,6 +14,7 @@ function LocalModuleDependency(localModule, range) {
|
|||
module.exports = LocalModuleDependency;
|
||||
|
||||
LocalModuleDependency.prototype = Object.create(NullDependency.prototype);
|
||||
LocalModuleDependency.prototype.constructor = LocalModuleDependency;
|
||||
|
||||
LocalModuleDependency.Template = function LocalModuleDependencyTemplate() {};
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ function ModuleDependency(request) {
|
|||
module.exports = ModuleDependency;
|
||||
|
||||
ModuleDependency.prototype = Object.create(Dependency.prototype);
|
||||
ModuleDependency.prototype.constructor = ModuleDependency;
|
||||
ModuleDependency.prototype.isEqualResource = function isEqualResource(other) {
|
||||
if(!(other instanceof ModuleDependency))
|
||||
return false;
|
||||
|
|
|
@ -13,6 +13,7 @@ function ModuleHotAcceptDependency(request, range) {
|
|||
module.exports = ModuleHotAcceptDependency;
|
||||
|
||||
ModuleHotAcceptDependency.prototype = Object.create(ModuleDependency.prototype);
|
||||
ModuleHotAcceptDependency.prototype.constructor = ModuleHotAcceptDependency;
|
||||
ModuleHotAcceptDependency.prototype.type = "module.hot.accept";
|
||||
|
||||
ModuleHotAcceptDependency.Template = require("./ModuleDependencyTemplateAsId");
|
||||
|
|
|
@ -13,6 +13,7 @@ function ModuleHotDeclineDependency(request, range) {
|
|||
module.exports = ModuleHotDeclineDependency;
|
||||
|
||||
ModuleHotDeclineDependency.prototype = Object.create(ModuleDependency.prototype);
|
||||
ModuleHotDeclineDependency.prototype.constructor = ModuleHotDeclineDependency;
|
||||
ModuleHotDeclineDependency.prototype.type = "module.hot.decline";
|
||||
|
||||
ModuleHotDeclineDependency.Template = require("./ModuleDependencyTemplateAsId");
|
||||
|
|
|
@ -13,4 +13,5 @@ function MultiEntryDependency(dependencies, name) {
|
|||
module.exports = MultiEntryDependency;
|
||||
|
||||
MultiEntryDependency.prototype = Object.create(Dependency.prototype);
|
||||
MultiEntryDependency.prototype.constructor = MultiEntryDependency;
|
||||
MultiEntryDependency.prototype.type = "multi entry";
|
||||
|
|
|
@ -11,6 +11,7 @@ function NullDependency() {
|
|||
module.exports = NullDependency;
|
||||
|
||||
NullDependency.prototype = Object.create(Dependency.prototype);
|
||||
NullDependency.prototype.constructor = NullDependency;
|
||||
NullDependency.prototype.type = "null";
|
||||
NullDependency.prototype.isEqualResource = function() {
|
||||
return false;
|
||||
|
|
|
@ -11,4 +11,5 @@ function PrefetchDependency(request) {
|
|||
module.exports = PrefetchDependency;
|
||||
|
||||
PrefetchDependency.prototype = Object.create(ModuleDependency.prototype);
|
||||
PrefetchDependency.prototype.constructor = PrefetchDependency;
|
||||
PrefetchDependency.prototype.type = "prefetch";
|
||||
|
|
|
@ -12,6 +12,7 @@ function RequireContextDependency(request, recursive, regExp, range) {
|
|||
module.exports = RequireContextDependency;
|
||||
|
||||
RequireContextDependency.prototype = Object.create(ContextDependency.prototype);
|
||||
RequireContextDependency.prototype.constructor = RequireContextDependency;
|
||||
RequireContextDependency.prototype.type = "require.context";
|
||||
|
||||
RequireContextDependency.Template = require("./ModuleDependencyTemplateAsRequireId");
|
||||
|
|
|
@ -11,7 +11,9 @@ function RequireEnsureDependenciesBlock(expr, fnExpression, chunkName, chunkName
|
|||
var bodyRange = fnExpression && fnExpression.body && fnExpression.body.range;
|
||||
this.range = bodyRange && [bodyRange[0] + 1, bodyRange[1] - 1] || null;
|
||||
this.chunkNameRange = chunkNameRange;
|
||||
this.addDependency(new RequireEnsureDependency(this));
|
||||
var dep = new RequireEnsureDependency(this);
|
||||
dep.loc = loc;
|
||||
this.addDependency(dep);
|
||||
}
|
||||
module.exports = RequireEnsureDependenciesBlock;
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ function RequireEnsureDependency(block) {
|
|||
module.exports = RequireEnsureDependency;
|
||||
|
||||
RequireEnsureDependency.prototype = Object.create(NullDependency.prototype);
|
||||
RequireEnsureDependency.prototype.constructor = RequireEnsureDependency;
|
||||
RequireEnsureDependency.prototype.type = "require.ensure";
|
||||
|
||||
RequireEnsureDependency.Template = function RequireEnsureDependencyTemplate() {};
|
||||
|
|
|
@ -11,6 +11,7 @@ function RequireEnsureItemDependency(request) {
|
|||
module.exports = RequireEnsureItemDependency;
|
||||
|
||||
RequireEnsureItemDependency.prototype = Object.create(ModuleDependency.prototype);
|
||||
RequireEnsureItemDependency.prototype.constructor = RequireEnsureItemDependency;
|
||||
RequireEnsureItemDependency.prototype.type = "require.ensure item";
|
||||
|
||||
RequireEnsureItemDependency.Template = require("./NullDependencyTemplate");
|
||||
|
|
|
@ -13,6 +13,7 @@ function RequireHeaderDependency(range) {
|
|||
module.exports = RequireHeaderDependency;
|
||||
|
||||
RequireHeaderDependency.prototype = Object.create(NullDependency.prototype);
|
||||
RequireHeaderDependency.prototype.constructor = RequireHeaderDependency;
|
||||
|
||||
RequireHeaderDependency.Template = function RequireHeaderDependencyTemplate() {};
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ function RequireIncludeDependency(request, range) {
|
|||
module.exports = RequireIncludeDependency;
|
||||
|
||||
RequireIncludeDependency.prototype = Object.create(ModuleDependency.prototype);
|
||||
RequireIncludeDependency.prototype.constructor = RequireIncludeDependency;
|
||||
RequireIncludeDependency.prototype.type = "require.include";
|
||||
|
||||
RequireIncludeDependency.Template = function RequireIncludeDependencyTemplate() {};
|
||||
|
|
|
@ -13,6 +13,7 @@ function RequireResolveContextDependency(request, recursive, regExp, range, valu
|
|||
module.exports = RequireResolveContextDependency;
|
||||
|
||||
RequireResolveContextDependency.prototype = Object.create(ContextDependency.prototype);
|
||||
RequireResolveContextDependency.prototype.constructor = RequireResolveContextDependency;
|
||||
RequireResolveContextDependency.prototype.type = "amd require context";
|
||||
|
||||
RequireResolveContextDependency.Template = require("./ContextDependencyTemplateAsId");
|
||||
|
|
|
@ -12,6 +12,7 @@ function RequireResolveDependency(request, range) {
|
|||
module.exports = RequireResolveDependency;
|
||||
|
||||
RequireResolveDependency.prototype = Object.create(ModuleDependency.prototype);
|
||||
RequireResolveDependency.prototype.constructor = RequireResolveDependency;
|
||||
RequireResolveDependency.prototype.type = "require.resolve";
|
||||
|
||||
RequireResolveDependency.Template = require("./ModuleDependencyTemplateAsId");
|
||||
|
|
|
@ -24,6 +24,7 @@ RequireResolveDependencyParserPlugin.prototype.apply = function(parser) {
|
|||
parser.plugin("call require.resolve(Weak)", function(expr, weak) {
|
||||
if(expr.arguments.length !== 1) return;
|
||||
var param = this.evaluateExpression(expr.arguments[0]);
|
||||
var dep;
|
||||
if(param.isConditional()) {
|
||||
param.options.forEach(function(option) {
|
||||
var result = this.applyPluginsBailResult("call require.resolve(Weak):item", expr, option, weak);
|
||||
|
@ -31,14 +32,18 @@ RequireResolveDependencyParserPlugin.prototype.apply = function(parser) {
|
|||
this.applyPluginsBailResult("call require.resolve(Weak):context", expr, option, weak);
|
||||
}
|
||||
}, this);
|
||||
this.state.current.addDependency(new RequireResolveHeaderDependency(expr.callee.range));
|
||||
dep = new RequireResolveHeaderDependency(expr.callee.range);
|
||||
dep.loc = expr.loc;
|
||||
this.state.current.addDependency(dep);
|
||||
return true;
|
||||
} else {
|
||||
var result = this.applyPluginsBailResult("call require.resolve(Weak):item", expr, param, weak);
|
||||
if(result === undefined) {
|
||||
this.applyPluginsBailResult("call require.resolve(Weak):context", expr, param, weak);
|
||||
}
|
||||
this.state.current.addDependency(new RequireResolveHeaderDependency(expr.callee.range));
|
||||
dep = new RequireResolveHeaderDependency(expr.callee.range);
|
||||
dep.loc = expr.loc;
|
||||
this.state.current.addDependency(dep);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -13,6 +13,7 @@ function RequireResolveHeaderDependency(range) {
|
|||
module.exports = RequireResolveHeaderDependency;
|
||||
|
||||
RequireResolveHeaderDependency.prototype = Object.create(NullDependency.prototype);
|
||||
RequireResolveHeaderDependency.prototype.constructor = RequireResolveHeaderDependency;
|
||||
|
||||
RequireResolveHeaderDependency.Template = function RequireResolveHeaderDependencyTemplate() {};
|
||||
|
||||
|
|
|
@ -11,4 +11,5 @@ function SingleEntryDependency(request) {
|
|||
module.exports = SingleEntryDependency;
|
||||
|
||||
SingleEntryDependency.prototype = Object.create(ModuleDependency.prototype);
|
||||
SingleEntryDependency.prototype.constructor = SingleEntryDependency;
|
||||
SingleEntryDependency.prototype.type = "single entry";
|
||||
|
|
|
@ -9,6 +9,7 @@ function TemplateArgumentDependency(name, dep) {
|
|||
}
|
||||
module.exports = TemplateArgumentDependency;
|
||||
|
||||
TemplateArgumentDependency.prototype.constructor = TemplateArgumentDependency;
|
||||
TemplateArgumentDependency.prototype.type = "template argument";
|
||||
|
||||
TemplateArgumentDependency.prototype.updateHash = function(hash) {
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
/*global $hotChunkFilename$ hotAddUpdateChunk $hotMainFilename$ */
|
||||
module.exports = function() {
|
||||
function hotDownloadUpdateChunk(chunkId) { // eslint-disable-line no-unused-vars
|
||||
var chunk = require("./" + $hotChunkFilename$);
|
||||
hotAddUpdateChunk(chunk.id, chunk.modules);
|
||||
}
|
||||
|
||||
function hotDownloadManifest(callback) { // eslint-disable-line no-unused-vars
|
||||
try {
|
||||
var update = require("./" + $hotMainFilename$);
|
||||
} catch(e) {
|
||||
return callback();
|
||||
}
|
||||
callback(null, update);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
/*global $hotChunkFilename$ $require$ hotAddUpdateChunk $hotMainFilename$ */
|
||||
module.exports = function() {
|
||||
function hotDownloadUpdateChunk(chunkId) { // eslint-disable-line no-unused-vars
|
||||
var filename = require("path").join(__dirname, $hotChunkFilename$);
|
||||
require("fs").readFile(filename, "utf-8", function(err, content) {
|
||||
if(err) {
|
||||
if($require$.onError)
|
||||
return $require$.onError(err);
|
||||
else
|
||||
throw err;
|
||||
}
|
||||
var chunk = {};
|
||||
require("vm").runInThisContext("(function(exports) {" + content + "\n})", filename)(chunk);
|
||||
hotAddUpdateChunk(chunk.id, chunk.modules);
|
||||
});
|
||||
}
|
||||
|
||||
function hotDownloadManifest(callback) { // eslint-disable-line no-unused-vars
|
||||
var filename = require("path").join(__dirname, $hotMainFilename$);
|
||||
require("fs").readFile(filename, "utf-8", function(err, content) {
|
||||
if(err) return callback();
|
||||
try {
|
||||
var update = JSON.parse(content);
|
||||
} catch(e) {
|
||||
return callback(e);
|
||||
}
|
||||
callback(null, update);
|
||||
});
|
||||
}
|
||||
};
|
|
@ -150,51 +150,7 @@ NodeMainTemplatePlugin.prototype.apply = function(mainTemplate) {
|
|||
return "\" + " + this.renderCurrentHashCode(hash, length) + " + \"";
|
||||
}.bind(this)
|
||||
});
|
||||
return Template.getFunctionContent(self.asyncChunkLoading ? function() {
|
||||
/*global $hotChunkFilename$ $require$ hotAddUpdateChunk $hotMainFilename$ */
|
||||
function hotDownloadUpdateChunk(chunkId) { // eslint-disable-line no-unused-vars
|
||||
var filename = require("path").join(__dirname, $hotChunkFilename$);
|
||||
require("fs").readFile(filename, "utf-8", function(err, content) {
|
||||
if(err) {
|
||||
if($require$.onError)
|
||||
return $require$.onError(err);
|
||||
else
|
||||
throw err;
|
||||
}
|
||||
var chunk = {};
|
||||
require("vm").runInThisContext("(function(exports) {" + content + "\n})", filename)(chunk);
|
||||
hotAddUpdateChunk(chunk.id, chunk.modules);
|
||||
});
|
||||
}
|
||||
|
||||
function hotDownloadManifest(callback) { // eslint-disable-line no-unused-vars
|
||||
var filename = require("path").join(__dirname, $hotMainFilename$);
|
||||
require("fs").readFile(filename, "utf-8", function(err, content) {
|
||||
if(err) return callback();
|
||||
try {
|
||||
var update = JSON.parse(content);
|
||||
} catch(e) {
|
||||
return callback(e);
|
||||
}
|
||||
callback(null, update);
|
||||
});
|
||||
}
|
||||
} : function() {
|
||||
/*global $hotChunkFilename$ $require$ hotAddUpdateChunk $hotMainFilename$ */
|
||||
function hotDownloadUpdateChunk(chunkId) { // eslint-disable-line no-unused-vars
|
||||
var chunk = require("./" + $hotChunkFilename$);
|
||||
hotAddUpdateChunk(chunk.id, chunk.modules);
|
||||
}
|
||||
|
||||
function hotDownloadManifest(callback) { // eslint-disable-line no-unused-vars
|
||||
try {
|
||||
var update = require("./" + $hotMainFilename$);
|
||||
} catch(e) {
|
||||
return callback();
|
||||
}
|
||||
callback(null, update);
|
||||
}
|
||||
})
|
||||
return Template.getFunctionContent(self.asyncChunkLoading ? require("./NodeMainTemplateAsync.runtime.js") : require("./NodeMainTemplate.runtime.js"))
|
||||
.replace(/\$require\$/g, this.requireFn)
|
||||
.replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename)
|
||||
.replace(/\$hotChunkFilename\$/g, currentHotUpdateChunkFilename);
|
||||
|
|
|
@ -14,7 +14,7 @@ function NodeWatchFileSystem(inputFileSystem) {
|
|||
|
||||
module.exports = NodeWatchFileSystem;
|
||||
|
||||
NodeWatchFileSystem.prototype.watch = function watch(files, dirs, missing, startTime, delay, callback, callbackUndelayed) {
|
||||
NodeWatchFileSystem.prototype.watch = function watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) {
|
||||
if(!Array.isArray(files))
|
||||
throw new Error("Invalid arguments: 'files'");
|
||||
if(!Array.isArray(dirs))
|
||||
|
@ -25,14 +25,12 @@ NodeWatchFileSystem.prototype.watch = function watch(files, dirs, missing, start
|
|||
throw new Error("Invalid arguments: 'callback'");
|
||||
if(typeof startTime !== "number" && startTime)
|
||||
throw new Error("Invalid arguments: 'startTime'");
|
||||
if(typeof delay !== "number")
|
||||
throw new Error("Invalid arguments: 'delay'");
|
||||
if(typeof options !== "object")
|
||||
throw new Error("Invalid arguments: 'options'");
|
||||
if(typeof callbackUndelayed !== "function" && callbackUndelayed)
|
||||
throw new Error("Invalid arguments: 'callbackUndelayed'");
|
||||
var oldWatcher = this.watcher;
|
||||
this.watcher = new Watchpack({
|
||||
aggregateTimeout: delay
|
||||
});
|
||||
this.watcher = new Watchpack(options);
|
||||
|
||||
if(callbackUndelayed)
|
||||
this.watcher.once("change", callbackUndelayed);
|
||||
|
|
|
@ -42,8 +42,10 @@ CommonsChunkPlugin.prototype.apply = function(compiler) {
|
|||
if(!chunkNames && (selectedChunks === false || async)) {
|
||||
commonChunks = chunks;
|
||||
} else if(Array.isArray(chunkNames)) {
|
||||
commonChunks = chunks.filter(function(chunk) {
|
||||
return chunkNames.indexOf(chunk.name) >= 0;
|
||||
commonChunks = chunkNames.map(function(chunkName) {
|
||||
return chunks.filter(function(chunk) {
|
||||
return chunk.name === chunkName;
|
||||
})[0];
|
||||
});
|
||||
} else {
|
||||
commonChunks = chunks.filter(function(chunk) {
|
||||
|
@ -71,7 +73,7 @@ CommonsChunkPlugin.prototype.apply = function(compiler) {
|
|||
});
|
||||
} else {
|
||||
if(!commonChunk.entry) {
|
||||
compilation.errors.push(new Error("CommonsChunkPlugin: While running in normal mode it's not allowed to use a non-entry chunk"));
|
||||
compilation.errors.push(new Error("CommonsChunkPlugin: While running in normal mode it's not allowed to use a non-entry chunk (" + commonChunk.name + ")"));
|
||||
return;
|
||||
}
|
||||
usedChunks = chunks.filter(function(chunk) {
|
||||
|
|
|
@ -28,12 +28,15 @@ function webpack(options, callback) {
|
|||
}
|
||||
if(callback) {
|
||||
if(typeof callback !== "function") throw new Error("Invalid argument: callback");
|
||||
var watchOptions = options.watch || !Array.isArray(options) ? options : options[0];
|
||||
if(watchOptions.watch) {
|
||||
return compiler.watch(watchOptions.watchDelay, callback);
|
||||
} else {
|
||||
compiler.run(callback);
|
||||
if(options.watch === true) {
|
||||
console.warn("options.watch and options.watchDelay is deprecated: use webpack(options).watch instead");
|
||||
var watchOptions = options.watch || !Array.isArray(options) ? options : options[0];
|
||||
watchOptions = {
|
||||
aggregateTimeout: watchOptions.watchDelay
|
||||
};
|
||||
return compiler.watch(watchOptions, callback);
|
||||
}
|
||||
compiler.run(callback);
|
||||
}
|
||||
return compiler;
|
||||
}
|
||||
|
|
22
package.json
22
package.json
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "webpack",
|
||||
"version": "1.8.10",
|
||||
"version": "1.9.4",
|
||||
"author": "Tobias Koppers @sokra",
|
||||
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jade, coffee, css, less, ... and your custom stuff.",
|
||||
"dependencies": {
|
||||
|
@ -11,7 +11,6 @@
|
|||
"interpret": "^0.5.2",
|
||||
"memory-fs": "~0.2.0",
|
||||
"mkdirp": "~0.5.0",
|
||||
"node-libs-browser": "~0.4.0",
|
||||
"optimist": "~0.6.0",
|
||||
"supports-color": "^1.2.0",
|
||||
"tapable": "~0.1.8",
|
||||
|
@ -19,6 +18,9 @@
|
|||
"watchpack": "^0.2.1",
|
||||
"webpack-core": "~0.6.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"node-libs-browser": ">= 0.4.0 <=0.5.0"
|
||||
},
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
|
@ -31,10 +33,10 @@
|
|||
"coffee-loader": "~0.7.1",
|
||||
"component-webpack-plugin": "~0.2.0",
|
||||
"coveralls": "^2.11.2",
|
||||
"css-loader": "~0.10.1",
|
||||
"eslint": "^0.19.0",
|
||||
"css-loader": "~0.12.0",
|
||||
"eslint": "^0.21.0",
|
||||
"express": "~3.4.8",
|
||||
"extract-text-webpack-plugin": "~0.5.0",
|
||||
"extract-text-webpack-plugin": "~0.7.0",
|
||||
"file-loader": "~0.8.0",
|
||||
"i18n-webpack-plugin": "~0.2.0",
|
||||
"istanbul": "^0.3.13",
|
||||
|
@ -42,17 +44,17 @@
|
|||
"json-loader": "~0.5.1",
|
||||
"less-loader": "^2.0.0",
|
||||
"microtime": "^1.2.0",
|
||||
"mocha": "^2.1.0",
|
||||
"mocha": "~2.2.0",
|
||||
"mocha-lcov-reporter": "0.0.2",
|
||||
"raw-loader": "~0.5.0",
|
||||
"script-loader": "~0.6.0",
|
||||
"should": "^5.2.0",
|
||||
"style-loader": "~0.10.1",
|
||||
"should": "^6.0.1",
|
||||
"style-loader": "~0.12.0",
|
||||
"url-loader": "~0.5.0",
|
||||
"val-loader": "~0.5.0",
|
||||
"vm-browserify": "~0.0.0",
|
||||
"webpack-dev-middleware": "^1.0.0",
|
||||
"worker-loader": "~0.5.0"
|
||||
"worker-loader": "~0.6.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.6"
|
||||
|
@ -78,7 +80,7 @@
|
|||
"travis": "npm run cover -- --report lcovonly",
|
||||
"lint": "eslint lib",
|
||||
"precover": "npm run lint",
|
||||
"cover": "istanbul cover -x HotModuleReplacementPlugin.js -x JsonpMainTemplatePlugin.js -x NodeMainTemplatePlugin.js node_modules/mocha/bin/_mocha",
|
||||
"cover": "istanbul cover -x *.runtime.js node_modules/mocha/bin/_mocha",
|
||||
"publish-patch": "mocha && npm version patch && git push && git push --tags && npm publish"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var should = require("should");
|
||||
/* globals describe it */
|
||||
require("should");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
var webpack = require("../");
|
||||
|
@ -25,7 +26,6 @@ describe("Examples", function() {
|
|||
options.context = examplePath;
|
||||
options.optimize = options.optimize || {};
|
||||
options.output = options.output || {};
|
||||
options.optimize.occurenceOrder = true;
|
||||
options.output.pathInfo = true;
|
||||
options.output.path = path.join(examplePath, "js");
|
||||
options.output.publicPath = "js/";
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* globals describe it */
|
||||
|
||||
if(process.env.NO_WATCH_TESTS) {
|
||||
describe("NodeWatchFileSystem", function() {
|
||||
it("tests excluded");
|
||||
|
@ -5,7 +7,7 @@ if(process.env.NO_WATCH_TESTS) {
|
|||
return;
|
||||
}
|
||||
|
||||
var should = require("should");
|
||||
require("should");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
|
||||
|
@ -15,18 +17,12 @@ var fixtures = path.join(__dirname, "fixtures");
|
|||
var fileDirect = path.join(fixtures, "watched-file.txt");
|
||||
var fileSubdir = path.join(fixtures, "subdir", "watched-file.txt");
|
||||
|
||||
function simpleObject(key, value) {
|
||||
var obj = {};
|
||||
obj[key] = value;
|
||||
return obj;
|
||||
}
|
||||
|
||||
describe("NodeWatchFileSystem", function() {
|
||||
this.timeout(10000);
|
||||
it("should register a file change (change delayed)", function(done) {
|
||||
var startTime = new Date().getTime();
|
||||
var wfs = new NodeWatchFileSystem();
|
||||
var watcher = wfs.watch([fileDirect], [], [], startTime, 1000, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
|
||||
var watcher = wfs.watch([fileDirect], [], [], startTime, { aggregateTimeout: 1000 }, function(err, filesModified, dirsModified, missingCreated, fileTimestamps /*, dirTimestamps */) {
|
||||
if(err) throw err;
|
||||
filesModified.should.be.eql([fileDirect]);
|
||||
dirsModified.should.be.eql([]);
|
||||
|
@ -43,7 +39,7 @@ describe("NodeWatchFileSystem", function() {
|
|||
var startTime = new Date().getTime();
|
||||
setTimeout(function() {
|
||||
var wfs = new NodeWatchFileSystem();
|
||||
var watcher = wfs.watch([fileDirect], [], [], startTime, 1000, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
|
||||
var watcher = wfs.watch([fileDirect], [], [], startTime, { aggregateTimeout: 1000 }, function(err, filesModified, dirsModified, missingCreated, fileTimestamps /*, dirTimestamps */) {
|
||||
if(err) throw err;
|
||||
filesModified.should.be.eql([fileDirect]);
|
||||
dirsModified.should.be.eql([]);
|
||||
|
@ -58,7 +54,7 @@ describe("NodeWatchFileSystem", function() {
|
|||
it("should register a context change (change delayed)", function(done) {
|
||||
var startTime = new Date().getTime();
|
||||
var wfs = new NodeWatchFileSystem();
|
||||
var watcher = wfs.watch([], [fixtures], [], startTime, 1000, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
|
||||
var watcher = wfs.watch([], [fixtures], [], startTime, { aggregateTimeout: 1000 }, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
|
||||
if(err) throw err;
|
||||
filesModified.should.be.eql([]);
|
||||
dirsModified.should.be.eql([fixtures]);
|
||||
|
@ -75,7 +71,7 @@ describe("NodeWatchFileSystem", function() {
|
|||
var startTime = new Date().getTime();
|
||||
setTimeout(function() {
|
||||
var wfs = new NodeWatchFileSystem();
|
||||
var watcher = wfs.watch([], [fixtures], [], startTime, 1000, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
|
||||
var watcher = wfs.watch([], [fixtures], [], startTime, { aggregateTimeout: 1000 }, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
|
||||
if(err) throw err;
|
||||
filesModified.should.be.eql([]);
|
||||
dirsModified.should.be.eql([fixtures]);
|
||||
|
@ -90,7 +86,7 @@ describe("NodeWatchFileSystem", function() {
|
|||
it("should register a context change (change delayed, subdirectory)", function(done) {
|
||||
var startTime = new Date().getTime();
|
||||
var wfs = new NodeWatchFileSystem();
|
||||
var watcher = wfs.watch([], [fixtures], [], startTime, 1000, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
|
||||
var watcher = wfs.watch([], [fixtures], [], startTime, { aggregateTimeout: 1000 }, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
|
||||
if(err) throw err;
|
||||
filesModified.should.be.eql([]);
|
||||
dirsModified.should.be.eql([fixtures]);
|
||||
|
@ -107,7 +103,7 @@ describe("NodeWatchFileSystem", function() {
|
|||
var startTime = new Date().getTime();
|
||||
setTimeout(function() {
|
||||
var wfs = new NodeWatchFileSystem();
|
||||
var watcher = wfs.watch([], [fixtures], [], startTime, 1000, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
|
||||
var watcher = wfs.watch([], [fixtures], [], startTime, { aggregateTimeout: 1000 }, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
|
||||
if(err) throw err;
|
||||
filesModified.should.be.eql([]);
|
||||
dirsModified.should.be.eql([fixtures]);
|
||||
|
@ -123,7 +119,7 @@ describe("NodeWatchFileSystem", function() {
|
|||
var startTime = new Date().getTime();
|
||||
setTimeout(function() {
|
||||
var wfs = new NodeWatchFileSystem();
|
||||
var watcher = wfs.watch([fileDirect, fileSubdir], [fixtures], [], startTime, 1000, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
|
||||
var watcher = wfs.watch([fileDirect, fileSubdir], [fixtures], [], startTime, { aggregateTimeout: 1000 }, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
|
||||
if(err) throw err;
|
||||
filesModified.should.be.eql([fileSubdir, fileDirect]);
|
||||
dirsModified.should.be.eql([fixtures]);
|
||||
|
@ -141,7 +137,7 @@ describe("NodeWatchFileSystem", function() {
|
|||
it("should sum up multiple changes", function(done) {
|
||||
var startTime = new Date().getTime();
|
||||
var wfs = new NodeWatchFileSystem();
|
||||
var watcher = wfs.watch([fileDirect, fileSubdir], [fixtures], [], startTime, 1000, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
|
||||
var watcher = wfs.watch([fileDirect, fileSubdir], [fixtures], [], startTime, { aggregateTimeout: 1000 }, function(err, filesModified, dirsModified, missingCreated, fileTimestamps, dirTimestamps) {
|
||||
if(err) throw err;
|
||||
filesModified.should.be.eql([fileSubdir, fileDirect]);
|
||||
dirsModified.should.be.eql([fixtures]);
|
||||
|
|
|
@ -5,7 +5,7 @@ var fs = require("fs");
|
|||
|
||||
var webpack = require("../lib/webpack");
|
||||
|
||||
var base = path.join(__dirname, "fixtures", "stats");
|
||||
var base = path.join(__dirname, "statsCases");
|
||||
var tests = fs.readdirSync(base);
|
||||
|
||||
describe("Stats", function() {
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
module.exports = "a";
|
|
@ -0,0 +1 @@
|
|||
module.exports = "b";
|
|
@ -0,0 +1,14 @@
|
|||
if(module.hot) {
|
||||
it("should run module.hot.accept(...)", function() {
|
||||
module.hot.accept("./a", function() {});
|
||||
});
|
||||
it("should run module.hot.accept()", function() {
|
||||
module.hot.accept();
|
||||
});
|
||||
it("should run module.hot.decline", function() {
|
||||
module.hot.decline("./b");
|
||||
});
|
||||
} else {
|
||||
it("should run module.hot.* (disabled)", function() {
|
||||
});
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
(function() {
|
||||
var expr1 = "a", expr2 = "b";
|
||||
require(Math.random() < 0.5 ? expr1 : expr2);
|
||||
}).should.throw();
|
|
@ -0,0 +1,3 @@
|
|||
it("should compile expr in ?: operator", function() {
|
||||
require("./dir/test");
|
||||
});
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = [
|
||||
[/Critical dependencies/]
|
||||
];
|
|
@ -0,0 +1,8 @@
|
|||
it("should include test.js in SourceMap", function() {
|
||||
var fs = require("fs");
|
||||
var source = fs.readFileSync(__filename + ".map", "utf-8");
|
||||
var map = JSON.parse(source);
|
||||
map.sources.should.containEql("webpack:///./test.js");
|
||||
});
|
||||
|
||||
require.include("./test.js");
|
|
@ -0,0 +1,3 @@
|
|||
var foo = {};
|
||||
|
||||
module.exports = foo;
|
|
@ -0,0 +1,10 @@
|
|||
module.exports = {
|
||||
output: {
|
||||
lineToLine: true
|
||||
},
|
||||
node: {
|
||||
__dirname: false,
|
||||
__filename: false
|
||||
},
|
||||
devtool: "cheap-source-map"
|
||||
};
|
|
@ -6,18 +6,18 @@ Time: Xms
|
|||
2.bundle.js 122 bytes 2 [emitted]
|
||||
3.bundle.js 222 bytes 3 [emitted]
|
||||
chunk {0} bundle.js (main) 73 bytes [rendered]
|
||||
[0] (webpack)/test/fixtures/stats/chunks/index.js 51 bytes {0} [built]
|
||||
[0] (webpack)/test/statsCases/chunks/index.js 51 bytes {0} [built]
|
||||
factory:Xms building:Xms = Xms
|
||||
[1] (webpack)/test/fixtures/stats/chunks/a.js 22 bytes {0} [built]
|
||||
[1] (webpack)/test/statsCases/chunks/a.js 22 bytes {0} [built]
|
||||
[0] Xms -> factory:Xms building:Xms = Xms
|
||||
chunk {1} 1.bundle.js 54 bytes {0} [rendered]
|
||||
[3] (webpack)/test/fixtures/stats/chunks/c.js 54 bytes {1} [built]
|
||||
[3] (webpack)/test/statsCases/chunks/c.js 54 bytes {1} [built]
|
||||
[0] Xms -> factory:Xms building:Xms = Xms
|
||||
chunk {2} 2.bundle.js 22 bytes {0} [rendered]
|
||||
[2] (webpack)/test/fixtures/stats/chunks/b.js 22 bytes {2} [built]
|
||||
[2] (webpack)/test/statsCases/chunks/b.js 22 bytes {2} [built]
|
||||
[0] Xms -> factory:Xms building:Xms = Xms
|
||||
chunk {3} 3.bundle.js 44 bytes {1} [rendered]
|
||||
[4] (webpack)/test/fixtures/stats/chunks/d.js 22 bytes {3} [built]
|
||||
[4] (webpack)/test/statsCases/chunks/d.js 22 bytes {3} [built]
|
||||
[0] Xms -> [3] Xms -> factory:Xms building:Xms = Xms
|
||||
[5] (webpack)/test/fixtures/stats/chunks/e.js 22 bytes {3} [built]
|
||||
[5] (webpack)/test/statsCases/chunks/e.js 22 bytes {3} [built]
|
||||
[0] Xms -> [3] Xms -> factory:Xms building:Xms = Xms
|
|
@ -10,6 +10,9 @@ module.exports = {
|
|||
cachedAssets: true,
|
||||
source: true,
|
||||
errorDetails: true,
|
||||
publicPath: true
|
||||
publicPath: true,
|
||||
excludeModules: [
|
||||
/e\.js/
|
||||
]
|
||||
}
|
||||
};
|
|
@ -3,5 +3,5 @@ Time: Xms
|
|||
Asset Size Chunks Chunk Names
|
||||
bundle.js 1.41 kB 0 [emitted] main
|
||||
chunk {0} bundle.js (main) 0 bytes [rendered]
|
||||
[0] (webpack)/test/fixtures/stats/simple-more-info/index.js 0 bytes {0} [built]
|
||||
[0] (webpack)/test/statsCases/simple-more-info/index.js 0 bytes {0} [built]
|
||||
factory:Xms building:Xms = Xms
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue