1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
8 |
|
9 | var _cluster = require("cluster");
|
10 |
|
11 | var _cluster2 = _interopRequireDefault(_cluster);
|
12 |
|
13 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
14 |
|
15 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
16 |
|
17 | var StartServerPlugin = function () {
|
18 | function StartServerPlugin(entry) {
|
19 | _classCallCheck(this, StartServerPlugin);
|
20 |
|
21 | this.entry = entry;
|
22 | this.afterEmit = this.afterEmit.bind(this);
|
23 | this.apply = this.apply.bind(this);
|
24 | this.startServer = this.startServer.bind(this);
|
25 |
|
26 | this.worker = null;
|
27 | }
|
28 |
|
29 | _createClass(StartServerPlugin, [{
|
30 | key: "afterEmit",
|
31 | value: function afterEmit(compilation, callback) {
|
32 | if (this.worker && this.worker.isConnected()) {
|
33 | return callback();
|
34 | }
|
35 |
|
36 | this.startServer(compilation, callback);
|
37 | }
|
38 | }, {
|
39 | key: "apply",
|
40 | value: function apply(compiler) {
|
41 | compiler.plugin("after-emit", this.afterEmit);
|
42 | }
|
43 | }, {
|
44 | key: "startServer",
|
45 | value: function startServer(compilation, callback) {
|
46 | var _this = this;
|
47 |
|
48 | var entry = void 0;
|
49 | var entries = Object.keys(compilation.assets);
|
50 | if (this.entry) {
|
51 | entry = this.entry;
|
52 | if (!compilation.assets[entry]) {
|
53 | console.error("Entry " + entry + " not found. Try one of: " + entries.join(" "));
|
54 | }
|
55 | } else {
|
56 | entry = entries[0];
|
57 | if (entries.length > 1) {
|
58 | console.log("More than one entry built, selected " + entry + ". All entries: " + entries.join(" "));
|
59 | }
|
60 | }
|
61 | var existsAt = compilation.assets[entry].existsAt;
|
62 |
|
63 |
|
64 | _cluster2.default.setupMaster({ exec: existsAt });
|
65 |
|
66 | _cluster2.default.on("online", function (worker) {
|
67 | _this.worker = worker;
|
68 | callback();
|
69 | });
|
70 |
|
71 | _cluster2.default.fork();
|
72 | }
|
73 | }]);
|
74 |
|
75 | return StartServerPlugin;
|
76 | }();
|
77 |
|
78 | exports.default = StartServerPlugin; |
\ | No newline at end of file |