保誠-保戶業務員媒合平台
Tomas
2022-05-19 957a1f10a06fdbb76f1a0ba94fe44126c613fee3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
"use strict";
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = setupHooks;
 
var _webpack = _interopRequireDefault(require("webpack"));
 
var _colorette = _interopRequireDefault(require("colorette"));
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
function setupHooks(context) {
  function invalid() {
    if (context.state) {
      context.logger.log("Compilation starting...");
    } // We are now in invalid state
    // eslint-disable-next-line no-param-reassign
 
 
    context.state = false; // eslint-disable-next-line no-param-reassign, no-undefined
 
    context.stats = undefined;
  }
 
  const statsForWebpack4 = _webpack.default.Stats && _webpack.default.Stats.presetToOptions;
 
  function normalizeStatsOptions(statsOptions) {
    if (statsForWebpack4) {
      if (typeof statsOptions === "undefined") {
        // eslint-disable-next-line no-param-reassign
        statsOptions = {};
      } else if (typeof statsOptions === "boolean" || typeof statsOptions === "string") {
        // eslint-disable-next-line no-param-reassign
        statsOptions = _webpack.default.Stats.presetToOptions(statsOptions);
      }
 
      return statsOptions;
    }
 
    if (typeof statsOptions === "undefined") {
      // eslint-disable-next-line no-param-reassign
      statsOptions = {
        preset: "normal"
      };
    } else if (typeof statsOptions === "boolean") {
      // eslint-disable-next-line no-param-reassign
      statsOptions = statsOptions ? {
        preset: "normal"
      } : {
        preset: "none"
      };
    } else if (typeof statsOptions === "string") {
      // eslint-disable-next-line no-param-reassign
      statsOptions = {
        preset: statsOptions
      };
    }
 
    return statsOptions;
  }
 
  function done(stats) {
    // We are now on valid state
    // eslint-disable-next-line no-param-reassign
    context.state = true; // eslint-disable-next-line no-param-reassign
 
    context.stats = stats; // Do the stuff in nextTick, because bundle may be invalidated if a change happened while compiling
 
    process.nextTick(() => {
      const {
        compiler,
        logger,
        options,
        state,
        callbacks
      } = context; // Check if still in valid state
 
      if (!state) {
        return;
      }
 
      logger.log("Compilation finished");
      const isMultiCompilerMode = Boolean(compiler.compilers);
      let statsOptions;
 
      if (typeof options.stats !== "undefined") {
        statsOptions = isMultiCompilerMode ? {
          children: compiler.compilers.map(() => options.stats)
        } : options.stats;
      } else {
        statsOptions = isMultiCompilerMode ? {
          children: compiler.compilers.map(child => child.options.stats)
        } : compiler.options.stats;
      }
 
      if (isMultiCompilerMode) {
        statsOptions.children = statsOptions.children.map(childStatsOptions => {
          // eslint-disable-next-line no-param-reassign
          childStatsOptions = normalizeStatsOptions(childStatsOptions);
 
          if (typeof childStatsOptions.colors === "undefined") {
            // eslint-disable-next-line no-param-reassign
            childStatsOptions.colors = Boolean(_colorette.default.options.enabled);
          }
 
          return childStatsOptions;
        });
      } else {
        statsOptions = normalizeStatsOptions(statsOptions);
 
        if (typeof statsOptions.colors === "undefined") {
          statsOptions.colors = Boolean(_colorette.default.options.enabled);
        }
      } // TODO webpack@4 doesn't support `{ children: [{ colors: true }, { colors: true }] }` for stats
 
 
      if (compiler.compilers && statsForWebpack4) {
        statsOptions.colors = statsOptions.children.some(child => child.colors);
      }
 
      const printedStats = stats.toString(statsOptions); // Avoid extra empty line when `stats: 'none'`
 
      if (printedStats) {
        // eslint-disable-next-line no-console
        console.log(printedStats);
      } // eslint-disable-next-line no-param-reassign
 
 
      context.callbacks = []; // Execute callback that are delayed
 
      callbacks.forEach(callback => {
        callback(stats);
      });
    });
  }
 
  context.compiler.hooks.watchRun.tap("webpack-dev-middleware", invalid);
  context.compiler.hooks.invalid.tap("webpack-dev-middleware", invalid);
  (context.compiler.webpack ? context.compiler.hooks.afterDone : context.compiler.hooks.done).tap("webpack-dev-middleware", done);
}