piral-cli-webpack5 1.0.0-pre.1960 → 1.0.1-beta.5640
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +31 -10
- package/extend-config.js +125 -18
- package/lib/actions.d.ts +2 -2
- package/lib/actions.js +33 -39
- package/lib/actions.js.map +1 -1
- package/lib/{configs → enhancers/hmr-webpack-config-enhancer}/HotModuleServerPlugin.js +1 -1
- package/lib/enhancers/hmr-webpack-config-enhancer/HotModuleServerPlugin.js.map +1 -0
- package/lib/enhancers/hmr-webpack-config-enhancer/index.d.ts +5 -0
- package/lib/enhancers/hmr-webpack-config-enhancer/index.js +30 -0
- package/lib/enhancers/hmr-webpack-config-enhancer/index.js.map +1 -0
- package/lib/enhancers/html5-entry-webpack-config-enhancer/helpers.d.ts +2 -2
- package/lib/enhancers/html5-entry-webpack-config-enhancer/helpers.js +1 -1
- package/lib/enhancers/html5-entry-webpack-config-enhancer/helpers.js.map +1 -1
- package/lib/enhancers/html5-entry-webpack-config-enhancer/index.d.ts +2 -1
- package/lib/enhancers/html5-entry-webpack-config-enhancer/index.js +17 -6
- package/lib/enhancers/html5-entry-webpack-config-enhancer/index.js.map +1 -1
- package/lib/enhancers/pilet-webpack-config-enhancer/helpers.d.ts +5 -0
- package/lib/enhancers/pilet-webpack-config-enhancer/helpers.js +53 -1
- package/lib/enhancers/pilet-webpack-config-enhancer/helpers.js.map +1 -1
- package/lib/enhancers/pilet-webpack-config-enhancer/index.d.ts +18 -4
- package/lib/enhancers/pilet-webpack-config-enhancer/index.js +117 -49
- package/lib/enhancers/pilet-webpack-config-enhancer/index.js.map +1 -1
- package/lib/enhancers/piral-instance-webpack-config-enhancer/helpers.js +2 -0
- package/lib/enhancers/piral-instance-webpack-config-enhancer/helpers.js.map +1 -1
- package/lib/enhancers/piral-instance-webpack-config-enhancer/index.d.ts +2 -3
- package/lib/enhancers/piral-instance-webpack-config-enhancer/index.js +6 -7
- package/lib/enhancers/piral-instance-webpack-config-enhancer/index.js.map +1 -1
- package/lib/helpers.d.ts +2 -1
- package/lib/helpers.js +10 -4
- package/lib/helpers.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/plugins/SheetLoader.d.ts +1 -0
- package/lib/plugins/SheetLoader.js +19 -0
- package/lib/plugins/SheetLoader.js.map +1 -0
- package/lib/plugins/SheetPlugin.d.ts +7 -0
- package/lib/plugins/SheetPlugin.js +31 -0
- package/lib/plugins/SheetPlugin.js.map +1 -0
- package/lib/plugins/StylesLoader.d.ts +1 -0
- package/lib/plugins/StylesLoader.js +14 -0
- package/lib/plugins/StylesLoader.js.map +1 -0
- package/lib/plugins/StylesPlugin.d.ts +6 -0
- package/lib/plugins/StylesPlugin.js +34 -0
- package/lib/plugins/StylesPlugin.js.map +1 -0
- package/lib/webpack/bundler-run.d.ts +2 -21
- package/lib/webpack/bundler-run.js +54 -46
- package/lib/webpack/bundler-run.js.map +1 -1
- package/lib/webpack/common.d.ts +8 -0
- package/lib/webpack/common.js +104 -0
- package/lib/webpack/common.js.map +1 -0
- package/lib/webpack/pilet.d.ts +19 -0
- package/lib/webpack/pilet.js +97 -0
- package/lib/webpack/pilet.js.map +1 -0
- package/lib/webpack/piral.d.ts +16 -0
- package/lib/webpack/piral.js +90 -0
- package/lib/webpack/piral.js.map +1 -0
- package/package.json +28 -29
- package/src/actions.ts +33 -20
- package/src/{configs → enhancers/hmr-webpack-config-enhancer}/HotModuleServerPlugin.ts +1 -1
- package/src/enhancers/hmr-webpack-config-enhancer/index.ts +34 -0
- package/src/enhancers/html5-entry-webpack-config-enhancer/helpers.ts +7 -7
- package/src/enhancers/html5-entry-webpack-config-enhancer/index.ts +31 -19
- package/src/enhancers/pilet-webpack-config-enhancer/helpers.ts +62 -0
- package/src/enhancers/pilet-webpack-config-enhancer/index.ts +187 -59
- package/src/enhancers/piral-instance-webpack-config-enhancer/helpers.ts +2 -0
- package/src/enhancers/piral-instance-webpack-config-enhancer/index.ts +14 -18
- package/src/helpers.ts +15 -5
- package/src/index.ts +1 -1
- package/src/plugins/SheetLoader.ts +16 -0
- package/src/plugins/SheetPlugin.ts +34 -0
- package/src/plugins/StylesLoader.ts +11 -0
- package/src/plugins/StylesPlugin.ts +35 -0
- package/src/webpack/bundler-run.ts +60 -56
- package/src/webpack/common.ts +111 -0
- package/src/webpack/pilet.ts +121 -0
- package/src/webpack/piral.ts +110 -0
- package/src/webpack-hot-middleware/LICENSE +20 -0
- package/src/webpack-hot-middleware/client-overlay.js +99 -0
- package/src/webpack-hot-middleware/client.js +306 -0
- package/src/webpack-hot-middleware/helpers.js +9 -0
- package/src/webpack-hot-middleware/middleware.js +175 -0
- package/src/webpack-hot-middleware/process-update.js +157 -0
- package/lib/configs/HotModuleServerPlugin.js.map +0 -1
- package/lib/configs/SheetLoader.d.ts +0 -1
- package/lib/configs/SheetLoader.js +0 -27
- package/lib/configs/SheetLoader.js.map +0 -1
- package/lib/configs/common.d.ts +0 -6
- package/lib/configs/common.js +0 -115
- package/lib/configs/common.js.map +0 -1
- package/lib/configs/index.d.ts +0 -2
- package/lib/configs/index.js +0 -15
- package/lib/configs/index.js.map +0 -1
- package/lib/configs/pilet.d.ts +0 -3
- package/lib/configs/pilet.js +0 -72
- package/lib/configs/pilet.js.map +0 -1
- package/lib/configs/piral.d.ts +0 -2
- package/lib/configs/piral.js +0 -65
- package/lib/configs/piral.js.map +0 -1
- package/lib/webpack/bundler-calls.d.ts +0 -3
- package/lib/webpack/bundler-calls.js +0 -93
- package/lib/webpack/bundler-calls.js.map +0 -1
- package/lib/webpack/index.d.ts +0 -1
- package/lib/webpack/index.js +0 -14
- package/lib/webpack/index.js.map +0 -1
- package/lib/webpack/run-build-pilet.d.ts +0 -1
- package/lib/webpack/run-build-pilet.js +0 -53
- package/lib/webpack/run-build-pilet.js.map +0 -1
- package/lib/webpack/run-build-piral.d.ts +0 -1
- package/lib/webpack/run-build-piral.js +0 -56
- package/lib/webpack/run-build-piral.js.map +0 -1
- package/lib/webpack/run-debug-mono-piral.d.ts +0 -1
- package/lib/webpack/run-debug-mono-piral.js +0 -61
- package/lib/webpack/run-debug-mono-piral.js.map +0 -1
- package/lib/webpack/run-debug-pilet.d.ts +0 -1
- package/lib/webpack/run-debug-pilet.js +0 -77
- package/lib/webpack/run-debug-pilet.js.map +0 -1
- package/lib/webpack/run-debug-piral.d.ts +0 -1
- package/lib/webpack/run-debug-piral.js +0 -76
- package/lib/webpack/run-debug-piral.js.map +0 -1
- package/src/configs/SheetLoader.ts +0 -12
- package/src/configs/common.ts +0 -118
- package/src/configs/index.ts +0 -2
- package/src/configs/pilet.ts +0 -82
- package/src/configs/piral.ts +0 -73
- package/src/webpack/bundler-calls.ts +0 -107
- package/src/webpack/index.ts +0 -1
- package/src/webpack/run-build-pilet.ts +0 -82
- package/src/webpack/run-build-piral.ts +0 -83
- package/src/webpack/run-debug-mono-piral.ts +0 -76
- package/src/webpack/run-debug-pilet.ts +0 -94
- package/src/webpack/run-debug-piral.ts +0 -95
- /package/lib/{configs → enhancers/hmr-webpack-config-enhancer}/HotModuleServerPlugin.d.ts +0 -0
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/*eslint-env browser*/
|
|
2
|
+
/*global __resourceQuery __webpack_public_path__*/
|
|
3
|
+
|
|
4
|
+
var options = {
|
|
5
|
+
path: '/__webpack_hmr',
|
|
6
|
+
timeout: 20 * 1000,
|
|
7
|
+
overlay: true,
|
|
8
|
+
reload: false,
|
|
9
|
+
log: true,
|
|
10
|
+
warn: true,
|
|
11
|
+
name: '',
|
|
12
|
+
autoConnect: true,
|
|
13
|
+
overlayStyles: {},
|
|
14
|
+
overlayWarnings: false,
|
|
15
|
+
ansiColors: {},
|
|
16
|
+
};
|
|
17
|
+
if (__resourceQuery) {
|
|
18
|
+
var querystring = require('querystring');
|
|
19
|
+
var overrides = querystring.parse(__resourceQuery.slice(1));
|
|
20
|
+
setOverrides(overrides);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (typeof window === 'undefined') {
|
|
24
|
+
// do nothing
|
|
25
|
+
} else if (typeof window.EventSource === 'undefined') {
|
|
26
|
+
console.warn(
|
|
27
|
+
"webpack-hot-middleware's client requires EventSource to work. " +
|
|
28
|
+
'You should include a polyfill if you want to support this browser: ' +
|
|
29
|
+
'https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events#Tools'
|
|
30
|
+
);
|
|
31
|
+
} else {
|
|
32
|
+
if (options.autoConnect) {
|
|
33
|
+
connect();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* istanbul ignore next */
|
|
38
|
+
function setOptionsAndConnect(overrides) {
|
|
39
|
+
setOverrides(overrides);
|
|
40
|
+
connect();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function setOverrides(overrides) {
|
|
44
|
+
if (overrides.autoConnect)
|
|
45
|
+
options.autoConnect = overrides.autoConnect == 'true';
|
|
46
|
+
if (overrides.path) options.path = overrides.path;
|
|
47
|
+
if (overrides.timeout) options.timeout = overrides.timeout;
|
|
48
|
+
if (overrides.overlay) options.overlay = overrides.overlay !== 'false';
|
|
49
|
+
if (overrides.reload) options.reload = overrides.reload !== 'false';
|
|
50
|
+
if (overrides.noInfo && overrides.noInfo !== 'false') {
|
|
51
|
+
options.log = false;
|
|
52
|
+
}
|
|
53
|
+
if (overrides.name) {
|
|
54
|
+
options.name = overrides.name;
|
|
55
|
+
}
|
|
56
|
+
if (overrides.quiet && overrides.quiet !== 'false') {
|
|
57
|
+
options.log = false;
|
|
58
|
+
options.warn = false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (overrides.dynamicPublicPath) {
|
|
62
|
+
options.path = __webpack_public_path__ + options.path;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (overrides.ansiColors)
|
|
66
|
+
options.ansiColors = JSON.parse(overrides.ansiColors);
|
|
67
|
+
if (overrides.overlayStyles)
|
|
68
|
+
options.overlayStyles = JSON.parse(overrides.overlayStyles);
|
|
69
|
+
|
|
70
|
+
if (overrides.overlayWarnings) {
|
|
71
|
+
options.overlayWarnings = overrides.overlayWarnings == 'true';
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function EventSourceWrapper() {
|
|
76
|
+
var source;
|
|
77
|
+
var lastActivity = new Date();
|
|
78
|
+
var listeners = [];
|
|
79
|
+
|
|
80
|
+
init();
|
|
81
|
+
var timer = setInterval(function() {
|
|
82
|
+
if (new Date() - lastActivity > options.timeout) {
|
|
83
|
+
handleDisconnect();
|
|
84
|
+
}
|
|
85
|
+
}, options.timeout / 2);
|
|
86
|
+
|
|
87
|
+
function init() {
|
|
88
|
+
source = new window.EventSource(options.path);
|
|
89
|
+
source.onopen = handleOnline;
|
|
90
|
+
source.onerror = handleDisconnect;
|
|
91
|
+
source.onmessage = handleMessage;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function handleOnline() {
|
|
95
|
+
if (options.log) console.log('[HMR] connected');
|
|
96
|
+
lastActivity = new Date();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function handleMessage(event) {
|
|
100
|
+
lastActivity = new Date();
|
|
101
|
+
for (var i = 0; i < listeners.length; i++) {
|
|
102
|
+
listeners[i](event);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function handleDisconnect() {
|
|
107
|
+
clearInterval(timer);
|
|
108
|
+
source.close();
|
|
109
|
+
setTimeout(init, options.timeout);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
addMessageListener: function(fn) {
|
|
114
|
+
listeners.push(fn);
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function getEventSourceWrapper() {
|
|
120
|
+
if (!window.__whmEventSourceWrapper) {
|
|
121
|
+
window.__whmEventSourceWrapper = {};
|
|
122
|
+
}
|
|
123
|
+
if (!window.__whmEventSourceWrapper[options.path]) {
|
|
124
|
+
// cache the wrapper for other entries loaded on
|
|
125
|
+
// the same page with the same options.path
|
|
126
|
+
window.__whmEventSourceWrapper[options.path] = EventSourceWrapper();
|
|
127
|
+
}
|
|
128
|
+
return window.__whmEventSourceWrapper[options.path];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function connect() {
|
|
132
|
+
getEventSourceWrapper().addMessageListener(handleMessage);
|
|
133
|
+
|
|
134
|
+
function handleMessage(event) {
|
|
135
|
+
if (event.data == '\uD83D\uDC93') {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
processMessage(JSON.parse(event.data));
|
|
140
|
+
} catch (ex) {
|
|
141
|
+
if (options.warn) {
|
|
142
|
+
console.warn('Invalid HMR message: ' + event.data + '\n' + ex);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// the reporter needs to be a singleton on the page
|
|
149
|
+
// in case the client is being used by multiple bundles
|
|
150
|
+
// we only want to report once.
|
|
151
|
+
// all the errors will go to all clients
|
|
152
|
+
var singletonKey = '__webpack_hot_middleware_reporter__';
|
|
153
|
+
var reporter;
|
|
154
|
+
if (typeof window !== 'undefined') {
|
|
155
|
+
if (!window[singletonKey]) {
|
|
156
|
+
window[singletonKey] = createReporter();
|
|
157
|
+
}
|
|
158
|
+
reporter = window[singletonKey];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function createReporter() {
|
|
162
|
+
var strip = require('strip-ansi');
|
|
163
|
+
|
|
164
|
+
var overlay;
|
|
165
|
+
if (typeof document !== 'undefined' && options.overlay) {
|
|
166
|
+
overlay = require('./client-overlay')({
|
|
167
|
+
ansiColors: options.ansiColors,
|
|
168
|
+
overlayStyles: options.overlayStyles,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
var styles = {
|
|
173
|
+
errors: 'color: #ff0000;',
|
|
174
|
+
warnings: 'color: #999933;',
|
|
175
|
+
};
|
|
176
|
+
var previousProblems = null;
|
|
177
|
+
function log(type, obj) {
|
|
178
|
+
var newProblems = obj[type]
|
|
179
|
+
.map(function(msg) {
|
|
180
|
+
return strip(msg);
|
|
181
|
+
})
|
|
182
|
+
.join('\n');
|
|
183
|
+
if (previousProblems == newProblems) {
|
|
184
|
+
return;
|
|
185
|
+
} else {
|
|
186
|
+
previousProblems = newProblems;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
var style = styles[type];
|
|
190
|
+
var name = obj.name ? "'" + obj.name + "' " : '';
|
|
191
|
+
var title = '[HMR] bundle ' + name + 'has ' + obj[type].length + ' ' + type;
|
|
192
|
+
// NOTE: console.warn or console.error will print the stack trace
|
|
193
|
+
// which isn't helpful here, so using console.log to escape it.
|
|
194
|
+
if (console.group && console.groupEnd) {
|
|
195
|
+
console.group('%c' + title, style);
|
|
196
|
+
console.log('%c' + newProblems, style);
|
|
197
|
+
console.groupEnd();
|
|
198
|
+
} else {
|
|
199
|
+
console.log(
|
|
200
|
+
'%c' + title + '\n\t%c' + newProblems.replace(/\n/g, '\n\t'),
|
|
201
|
+
style + 'font-weight: bold;',
|
|
202
|
+
style + 'font-weight: normal;'
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return {
|
|
208
|
+
cleanProblemsCache: function() {
|
|
209
|
+
previousProblems = null;
|
|
210
|
+
},
|
|
211
|
+
problems: function(type, obj) {
|
|
212
|
+
if (options.warn) {
|
|
213
|
+
log(type, obj);
|
|
214
|
+
}
|
|
215
|
+
if (overlay) {
|
|
216
|
+
if (options.overlayWarnings || type === 'errors') {
|
|
217
|
+
overlay.showProblems(type, obj[type]);
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
overlay.clear();
|
|
221
|
+
}
|
|
222
|
+
return true;
|
|
223
|
+
},
|
|
224
|
+
success: function() {
|
|
225
|
+
if (overlay) overlay.clear();
|
|
226
|
+
},
|
|
227
|
+
useCustomOverlay: function(customOverlay) {
|
|
228
|
+
overlay = customOverlay;
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
var processUpdate = require('./process-update');
|
|
234
|
+
|
|
235
|
+
var customHandler;
|
|
236
|
+
var subscribeAllHandler;
|
|
237
|
+
function processMessage(obj) {
|
|
238
|
+
switch (obj.action) {
|
|
239
|
+
case 'building':
|
|
240
|
+
if (options.log) {
|
|
241
|
+
console.log(
|
|
242
|
+
'[HMR] bundle ' +
|
|
243
|
+
(obj.name ? "'" + obj.name + "' " : '') +
|
|
244
|
+
'rebuilding'
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
break;
|
|
248
|
+
case 'built':
|
|
249
|
+
if (options.log) {
|
|
250
|
+
console.log(
|
|
251
|
+
'[HMR] bundle ' +
|
|
252
|
+
(obj.name ? "'" + obj.name + "' " : '') +
|
|
253
|
+
'rebuilt in ' +
|
|
254
|
+
obj.time +
|
|
255
|
+
'ms'
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
// fall through
|
|
259
|
+
case 'sync':
|
|
260
|
+
if (obj.name && options.name && obj.name !== options.name) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
var applyUpdate = true;
|
|
264
|
+
if (obj.errors.length > 0) {
|
|
265
|
+
if (reporter) reporter.problems('errors', obj);
|
|
266
|
+
applyUpdate = false;
|
|
267
|
+
} else if (obj.warnings.length > 0) {
|
|
268
|
+
if (reporter) {
|
|
269
|
+
var overlayShown = reporter.problems('warnings', obj);
|
|
270
|
+
applyUpdate = overlayShown;
|
|
271
|
+
}
|
|
272
|
+
} else {
|
|
273
|
+
if (reporter) {
|
|
274
|
+
reporter.cleanProblemsCache();
|
|
275
|
+
reporter.success();
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (applyUpdate) {
|
|
279
|
+
processUpdate(obj.hash, obj.modules, options);
|
|
280
|
+
}
|
|
281
|
+
break;
|
|
282
|
+
default:
|
|
283
|
+
if (customHandler) {
|
|
284
|
+
customHandler(obj);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (subscribeAllHandler) {
|
|
289
|
+
subscribeAllHandler(obj);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (module) {
|
|
294
|
+
module.exports = {
|
|
295
|
+
subscribeAll: function subscribeAll(handler) {
|
|
296
|
+
subscribeAllHandler = handler;
|
|
297
|
+
},
|
|
298
|
+
subscribe: function subscribe(handler) {
|
|
299
|
+
customHandler = handler;
|
|
300
|
+
},
|
|
301
|
+
useCustomOverlay: function useCustomOverlay(customOverlay) {
|
|
302
|
+
if (reporter) reporter.useCustomOverlay(customOverlay);
|
|
303
|
+
},
|
|
304
|
+
setOptionsAndConnect: setOptionsAndConnect,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
module.exports = webpackHotMiddleware;
|
|
2
|
+
|
|
3
|
+
var helpers = require('./helpers');
|
|
4
|
+
var pathMatch = helpers.pathMatch;
|
|
5
|
+
|
|
6
|
+
function webpackHotMiddleware(compiler, opts) {
|
|
7
|
+
opts = opts || {};
|
|
8
|
+
opts.log =
|
|
9
|
+
typeof opts.log == 'undefined' ? console.log.bind(console) : opts.log;
|
|
10
|
+
opts.path = opts.path || '/__webpack_hmr';
|
|
11
|
+
opts.heartbeat = opts.heartbeat || 10 * 1000;
|
|
12
|
+
|
|
13
|
+
var eventStream = createEventStream(opts.heartbeat);
|
|
14
|
+
var latestStats = null;
|
|
15
|
+
var closed = false;
|
|
16
|
+
|
|
17
|
+
if (compiler.hooks) {
|
|
18
|
+
compiler.hooks.invalid.tap('webpack-hot-middleware', onInvalid);
|
|
19
|
+
compiler.hooks.done.tap('webpack-hot-middleware', onDone);
|
|
20
|
+
} else {
|
|
21
|
+
compiler.plugin('invalid', onInvalid);
|
|
22
|
+
compiler.plugin('done', onDone);
|
|
23
|
+
}
|
|
24
|
+
function onInvalid() {
|
|
25
|
+
if (closed) return;
|
|
26
|
+
latestStats = null;
|
|
27
|
+
if (opts.log) opts.log('webpack building...');
|
|
28
|
+
eventStream.publish({ action: 'building' });
|
|
29
|
+
}
|
|
30
|
+
function onDone(statsResult) {
|
|
31
|
+
if (closed) return;
|
|
32
|
+
// Keep hold of latest stats so they can be propagated to new clients
|
|
33
|
+
latestStats = statsResult;
|
|
34
|
+
publishStats('built', latestStats, eventStream, opts.log);
|
|
35
|
+
}
|
|
36
|
+
var middleware = function (req, res, next) {
|
|
37
|
+
if (closed) return next();
|
|
38
|
+
if (!pathMatch(req.url, opts.path)) return next();
|
|
39
|
+
eventStream.handler(req, res);
|
|
40
|
+
if (latestStats) {
|
|
41
|
+
// Explicitly not passing in `log` fn as we don't want to log again on
|
|
42
|
+
// the server
|
|
43
|
+
publishStats('sync', latestStats, eventStream);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
middleware.publish = function (payload) {
|
|
47
|
+
if (closed) return;
|
|
48
|
+
eventStream.publish(payload);
|
|
49
|
+
};
|
|
50
|
+
middleware.close = function () {
|
|
51
|
+
if (closed) return;
|
|
52
|
+
// Can't remove compiler plugins, so we just set a flag and noop if closed
|
|
53
|
+
// https://github.com/webpack/tapable/issues/32#issuecomment-350644466
|
|
54
|
+
closed = true;
|
|
55
|
+
eventStream.close();
|
|
56
|
+
eventStream = null;
|
|
57
|
+
};
|
|
58
|
+
return middleware;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function createEventStream(heartbeat) {
|
|
62
|
+
var clientId = 0;
|
|
63
|
+
var clients = {};
|
|
64
|
+
function everyClient(fn) {
|
|
65
|
+
Object.keys(clients).forEach(function (id) {
|
|
66
|
+
fn(clients[id]);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
var interval = setInterval(function heartbeatTick() {
|
|
70
|
+
everyClient(function (client) {
|
|
71
|
+
client.write('data: \uD83D\uDC93\n\n');
|
|
72
|
+
});
|
|
73
|
+
}, heartbeat).unref();
|
|
74
|
+
return {
|
|
75
|
+
close: function () {
|
|
76
|
+
clearInterval(interval);
|
|
77
|
+
everyClient(function (client) {
|
|
78
|
+
if (!client.finished) client.end();
|
|
79
|
+
});
|
|
80
|
+
clients = {};
|
|
81
|
+
},
|
|
82
|
+
handler: function (req, res) {
|
|
83
|
+
var headers = {
|
|
84
|
+
'Access-Control-Allow-Origin': '*',
|
|
85
|
+
'Content-Type': 'text/event-stream;charset=utf-8',
|
|
86
|
+
'Cache-Control': 'no-cache, no-transform',
|
|
87
|
+
// While behind nginx, event stream should not be buffered:
|
|
88
|
+
// http://nginx.org/docs/http/ngx_http_proxy_module.html#proxy_buffering
|
|
89
|
+
'X-Accel-Buffering': 'no',
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
var isHttp1 = !(parseInt(req.httpVersion) >= 2);
|
|
93
|
+
if (isHttp1) {
|
|
94
|
+
req.socket.setKeepAlive(true);
|
|
95
|
+
Object.assign(headers, {
|
|
96
|
+
Connection: 'keep-alive',
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
res.writeHead(200, headers);
|
|
101
|
+
res.write('\n');
|
|
102
|
+
var id = clientId++;
|
|
103
|
+
clients[id] = res;
|
|
104
|
+
req.on('close', function () {
|
|
105
|
+
if (!res.finished) res.end();
|
|
106
|
+
delete clients[id];
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
publish: function (payload) {
|
|
110
|
+
everyClient(function (client) {
|
|
111
|
+
client.write('data: ' + JSON.stringify(payload) + '\n\n');
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function publishStats(action, statsResult, eventStream, log) {
|
|
118
|
+
var stats = statsResult.toJson({
|
|
119
|
+
all: false,
|
|
120
|
+
cached: true,
|
|
121
|
+
children: true,
|
|
122
|
+
modules: true,
|
|
123
|
+
timings: true,
|
|
124
|
+
hash: true,
|
|
125
|
+
});
|
|
126
|
+
// For multi-compiler, stats will be an object with a 'children' array of stats
|
|
127
|
+
var bundles = extractBundles(stats);
|
|
128
|
+
bundles.forEach(function (stats) {
|
|
129
|
+
var name = stats.name || '';
|
|
130
|
+
|
|
131
|
+
// Fallback to compilation name in case of 1 bundle (if it exists)
|
|
132
|
+
if (bundles.length === 1 && !name && statsResult.compilation) {
|
|
133
|
+
name = statsResult.compilation.name || '';
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (log) {
|
|
137
|
+
log(
|
|
138
|
+
'webpack built ' +
|
|
139
|
+
(name ? name + ' ' : '') +
|
|
140
|
+
stats.hash +
|
|
141
|
+
' in ' +
|
|
142
|
+
stats.time +
|
|
143
|
+
'ms'
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
eventStream.publish({
|
|
147
|
+
name: name,
|
|
148
|
+
action: action,
|
|
149
|
+
time: stats.time,
|
|
150
|
+
hash: stats.hash,
|
|
151
|
+
warnings: stats.warnings || [],
|
|
152
|
+
errors: stats.errors || [],
|
|
153
|
+
modules: buildModuleMap(stats.modules),
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function extractBundles(stats) {
|
|
159
|
+
// Stats has modules, single bundle
|
|
160
|
+
if (stats.modules) return [stats];
|
|
161
|
+
|
|
162
|
+
// Stats has children, multiple bundles
|
|
163
|
+
if (stats.children && stats.children.length) return stats.children;
|
|
164
|
+
|
|
165
|
+
// Not sure, assume single
|
|
166
|
+
return [stats];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function buildModuleMap(modules) {
|
|
170
|
+
var map = {};
|
|
171
|
+
modules.forEach(function (module) {
|
|
172
|
+
map[module.id] = module.name;
|
|
173
|
+
});
|
|
174
|
+
return map;
|
|
175
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Based heavily on https://github.com/webpack/webpack/blob/
|
|
3
|
+
* c0afdf9c6abc1dd70707c594e473802a566f7b6e/hot/only-dev-server.js
|
|
4
|
+
* Original copyright Tobias Koppers @sokra (MIT license)
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/* global window __webpack_hash__ */
|
|
8
|
+
|
|
9
|
+
if (!module.hot) {
|
|
10
|
+
throw new Error('[HMR] Hot Module Replacement is disabled.');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
var hmrDocsUrl = 'https://webpack.js.org/concepts/hot-module-replacement/'; // eslint-disable-line max-len
|
|
14
|
+
|
|
15
|
+
var lastHash;
|
|
16
|
+
var failureStatuses = { abort: 1, fail: 1 };
|
|
17
|
+
var applyOptions = {
|
|
18
|
+
ignoreUnaccepted: true,
|
|
19
|
+
ignoreDeclined: true,
|
|
20
|
+
ignoreErrored: true,
|
|
21
|
+
onUnaccepted: function (data) {
|
|
22
|
+
console.warn(
|
|
23
|
+
'Ignored an update to unaccepted module ' + data.chain.join(' -> ')
|
|
24
|
+
);
|
|
25
|
+
},
|
|
26
|
+
onDeclined: function (data) {
|
|
27
|
+
console.warn(
|
|
28
|
+
'Ignored an update to declined module ' + data.chain.join(' -> ')
|
|
29
|
+
);
|
|
30
|
+
},
|
|
31
|
+
onErrored: function (data) {
|
|
32
|
+
console.error(data.error);
|
|
33
|
+
console.warn(
|
|
34
|
+
'Ignored an error while updating module ' +
|
|
35
|
+
data.moduleId +
|
|
36
|
+
' (' +
|
|
37
|
+
data.type +
|
|
38
|
+
')'
|
|
39
|
+
);
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function upToDate(hash) {
|
|
44
|
+
if (hash) lastHash = hash;
|
|
45
|
+
return lastHash == __webpack_hash__;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = function (hash, moduleMap, options) {
|
|
49
|
+
var reload = options.reload;
|
|
50
|
+
if (!upToDate(hash) && module.hot.status() == 'idle') {
|
|
51
|
+
if (options.log) console.log('[HMR] Checking for updates on the server...');
|
|
52
|
+
check();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function check() {
|
|
56
|
+
var cb = function (err, updatedModules) {
|
|
57
|
+
if (err) return handleError(err);
|
|
58
|
+
|
|
59
|
+
if (!updatedModules || !updatedModules.length) {
|
|
60
|
+
if (options.warn) {
|
|
61
|
+
console.warn('[HMR] Cannot find update (Full reload needed)');
|
|
62
|
+
console.warn('[HMR] (Probably because of restarting the server)');
|
|
63
|
+
}
|
|
64
|
+
performReload();
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
var applyCallback = function (applyErr, renewedModules) {
|
|
69
|
+
if (applyErr) return handleError(applyErr);
|
|
70
|
+
|
|
71
|
+
if (!upToDate()) check();
|
|
72
|
+
|
|
73
|
+
logUpdates(updatedModules, renewedModules);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
var applyResult = module.hot.apply(applyOptions, applyCallback);
|
|
77
|
+
// webpack 2 promise
|
|
78
|
+
if (applyResult && applyResult.then) {
|
|
79
|
+
// HotModuleReplacement.runtime.js refers to the result as `outdatedModules`
|
|
80
|
+
applyResult.then(function (outdatedModules) {
|
|
81
|
+
applyCallback(null, outdatedModules);
|
|
82
|
+
});
|
|
83
|
+
applyResult.catch(applyCallback);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
var result = module.hot.check(false, cb);
|
|
88
|
+
// webpack 2 promise
|
|
89
|
+
if (result && result.then) {
|
|
90
|
+
result.then(function (updatedModules) {
|
|
91
|
+
cb(null, updatedModules);
|
|
92
|
+
});
|
|
93
|
+
result.catch(cb);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function logUpdates(updatedModules, renewedModules) {
|
|
98
|
+
var unacceptedModules = updatedModules.filter(function (moduleId) {
|
|
99
|
+
return renewedModules && renewedModules.indexOf(moduleId) < 0;
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
if (unacceptedModules.length > 0) {
|
|
103
|
+
if (options.warn) {
|
|
104
|
+
console.warn(
|
|
105
|
+
"[HMR] The following modules couldn't be hot updated: " +
|
|
106
|
+
'(Full reload needed)\n' +
|
|
107
|
+
'This is usually because the modules which have changed ' +
|
|
108
|
+
'(and their parents) do not know how to hot reload themselves. ' +
|
|
109
|
+
'See ' +
|
|
110
|
+
hmrDocsUrl +
|
|
111
|
+
' for more details.'
|
|
112
|
+
);
|
|
113
|
+
unacceptedModules.forEach(function (moduleId) {
|
|
114
|
+
console.warn('[HMR] - ' + (moduleMap[moduleId] || moduleId));
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
performReload();
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (options.log) {
|
|
122
|
+
if (!renewedModules || renewedModules.length === 0) {
|
|
123
|
+
console.log('[HMR] Nothing hot updated.');
|
|
124
|
+
} else {
|
|
125
|
+
console.log('[HMR] Updated modules:');
|
|
126
|
+
renewedModules.forEach(function (moduleId) {
|
|
127
|
+
console.log('[HMR] - ' + (moduleMap[moduleId] || moduleId));
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (upToDate()) {
|
|
132
|
+
console.log('[HMR] App is up to date.');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function handleError(err) {
|
|
138
|
+
if (module.hot.status() in failureStatuses) {
|
|
139
|
+
if (options.warn) {
|
|
140
|
+
console.warn('[HMR] Cannot check for update (Full reload needed)');
|
|
141
|
+
console.warn('[HMR] ' + (err.stack || err.message));
|
|
142
|
+
}
|
|
143
|
+
performReload();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (options.warn) {
|
|
147
|
+
console.warn('[HMR] Update check failed: ' + (err.stack || err.message));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function performReload() {
|
|
152
|
+
if (reload) {
|
|
153
|
+
if (options.warn) console.warn('[HMR] Reloading page');
|
|
154
|
+
window.location.reload();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HotModuleServerPlugin.js","sourceRoot":"","sources":["../../src/configs/HotModuleServerPlugin.ts"],"names":[],"mappings":";;;AAEA,MAAa,qBAAqB;IAChC,YAAoB,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;IAAG,CAAC;IAEvC,KAAK,CAAC,QAAkB;QACtB,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;QACnC,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;QACtB,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;QACrD,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACrC,CAAC;CACF;AATD,sDASC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function SheetLoader(): Promise<void>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
function SheetLoader() {
|
|
13
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
-
const callback = this.async();
|
|
15
|
-
const stylesheet = [
|
|
16
|
-
`var d=document`,
|
|
17
|
-
`var e=d.createElement("link")`,
|
|
18
|
-
`e.type="text/css"`,
|
|
19
|
-
`e.rel="stylesheet"`,
|
|
20
|
-
`e.href=__webpack_public_path__ + ${JSON.stringify('main.css')}`,
|
|
21
|
-
`d.head.appendChild(e)`,
|
|
22
|
-
].join(';');
|
|
23
|
-
callback(undefined, stylesheet);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
exports.default = SheetLoader;
|
|
27
|
-
//# sourceMappingURL=SheetLoader.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SheetLoader.js","sourceRoot":"","sources":["../../src/configs/SheetLoader.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,SAA8B,WAAW;;QACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;QAC9B,MAAM,UAAU,GAAG;YACjB,gBAAgB;YAChB,+BAA+B;YAC/B,mBAAmB;YACnB,oBAAoB;YACpB,oCAAoC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE;YAChE,uBAAuB;SACxB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACZ,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAClC,CAAC;CAAA;AAXD,8BAWC"}
|
package/lib/configs/common.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { RuleSetRule } from 'webpack';
|
|
2
|
-
export declare const extensions: string[];
|
|
3
|
-
export declare function getVariables(): Record<string, string>;
|
|
4
|
-
export declare function getHmrEntry(hmrPort: number): [] | [string];
|
|
5
|
-
export declare function getPlugins(plugins: Array<any>, showProgress: boolean, production: boolean, hmrPort?: number): any[];
|
|
6
|
-
export declare function getRules(baseDir: string, production: boolean, pilet: boolean): Array<RuleSetRule>;
|