1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var url = require("url");
|
4 | var webpack = require("webpack");
|
5 | var utilities_1 = require("../utilities");
|
6 | var client_1 = require("./client");
|
7 | ;
|
8 | var HotDevelopment = (function () {
|
9 | function HotDevelopment(clientConfig, options) {
|
10 | if (options === void 0) { options = {}; }
|
11 | this.clientConfig = options.hot ? addHMRConfig(clientConfig, options) : clientConfig;
|
12 | this.options = options;
|
13 | }
|
14 | HotDevelopment.prototype.prepHotClient = function () {
|
15 | this.clientCompiler = webpack(this.clientConfig);
|
16 | this.clientBundle = new client_1.default(this.clientCompiler, this.options);
|
17 | };
|
18 | HotDevelopment.prototype.dispose = function () {
|
19 | return safeDisposeBundle(this.clientBundle);
|
20 | };
|
21 | return HotDevelopment;
|
22 | }());
|
23 | exports.default = HotDevelopment;
|
24 | function safeDisposeBundle(bundle) {
|
25 | return bundle == null ? Promise.resolve({}) : bundle.dispose();
|
26 | }
|
27 | function addHMRConfig(config, options) {
|
28 | var paths = new utilities_1.Paths();
|
29 | var project = new utilities_1.Project(paths);
|
30 | var hotPath = config.output.publicPath + "__webpack_hmr";
|
31 | if (options.hotHost) {
|
32 | hotPath = url.resolve(options.hotHost, hotPath);
|
33 | }
|
34 | config.entry = addEntryModule(config.entry, "webpack-hot-middleware/client?path=" + hotPath + "&reload=true&overlay=false");
|
35 | if (project.hasDependency('react-hot-loader')) {
|
36 | config.entry = addEntryModule(config.entry, 'react-hot-loader/patch');
|
37 | }
|
38 | config.plugins.push(new webpack.HotModuleReplacementPlugin());
|
39 | return config;
|
40 | }
|
41 | function addEntryModule(entry, entryModule) {
|
42 | if (entry == null) {
|
43 | return [];
|
44 | }
|
45 | else if (typeof entry === 'string') {
|
46 | return [entryModule, entry];
|
47 | }
|
48 | else if (Array.isArray(entry)) {
|
49 | return entry.indexOf(entryModule) < 0
|
50 | ? [entryModule].concat(entry) : entry;
|
51 | }
|
52 | else {
|
53 | return Object.keys(entry).reduce(function (newEntry, key) {
|
54 | newEntry[key] = addEntryModule(entry[key], entryModule);
|
55 | return newEntry;
|
56 | }, {});
|
57 | }
|
58 | }
|