webpack-dev-service 0.15.16 → 0.16.0
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/README.md +35 -36
- package/cjs/client/HotUpdate.cjs +78 -0
- package/cjs/client/HotUpdate.d.cts +26 -0
- package/cjs/client/client.cjs +15 -17
- package/cjs/client/events.cjs +1 -1
- package/cjs/client/index.cjs +1 -1
- package/cjs/client/main.cjs +1 -1
- package/cjs/client/ui/Overlay.cjs +3 -3
- package/cjs/client/ui/Progress.cjs +5 -5
- package/cjs/client/ui/images/webpack-logo.svg.cjs +1 -1
- package/cjs/client/ui/utils.cjs +12 -11
- package/cjs/client/ui/utils.d.cts +6 -2
- package/cjs/server/compose.cjs +1 -1
- package/cjs/server/dev/ReadStream.cjs +1 -1
- package/cjs/server/dev/Service.cjs +1 -1
- package/cjs/server/dev/index.cjs +3 -10
- package/cjs/server/dev/index.d.cts +1 -1
- package/cjs/server/dev/interface.d.cts +0 -3
- package/cjs/server/dev/middleware.cjs +8 -15
- package/cjs/server/dev/middleware.d.cts +1 -1
- package/cjs/server/dev/utils/fs.cjs +1 -1
- package/cjs/server/dev/utils/hash.cjs +1 -1
- package/cjs/server/dev/utils/http.cjs +1 -1
- package/cjs/server/dev/utils/path.cjs +1 -1
- package/cjs/server/dev/utils/paths.cjs +1 -1
- package/cjs/server/dev/utils/ready.cjs +1 -1
- package/cjs/server/dev/utils/setupHooks.cjs +9 -6
- package/cjs/server/dev/utils/setupOutputFileSystem.cjs +1 -1
- package/cjs/server/dev/utils/setupWatching.cjs +1 -1
- package/cjs/server/dev/utils/setupWriteToDisk.cjs +1 -1
- package/cjs/server/hot/Socket.cjs +8 -1
- package/cjs/server/hot/index.cjs +3 -3
- package/cjs/server/hot/utils.cjs +1 -1
- package/cjs/server/index.cjs +4 -5
- package/cjs/server/index.d.cts +1 -1
- package/cjs/server/schema.cjs +1 -1
- package/cjs/server/utils.cjs +1 -1
- package/esm/client/HotUpdate.d.ts +26 -0
- package/esm/client/HotUpdate.js +76 -0
- package/esm/client/client.js +16 -18
- package/esm/client/events.js +1 -1
- package/esm/client/index.js +1 -1
- package/esm/client/main.js +1 -1
- package/esm/client/ui/Overlay.js +4 -4
- package/esm/client/ui/Progress.js +6 -6
- package/esm/client/ui/images/webpack-logo.svg.js +1 -1
- package/esm/client/ui/utils.d.ts +6 -2
- package/esm/client/ui/utils.js +11 -10
- package/esm/server/compose.js +1 -1
- package/esm/server/dev/ReadStream.js +1 -1
- package/esm/server/dev/Service.js +1 -1
- package/esm/server/dev/index.d.ts +1 -1
- package/esm/server/dev/index.js +3 -10
- package/esm/server/dev/interface.d.ts +0 -3
- package/esm/server/dev/middleware.d.ts +1 -1
- package/esm/server/dev/middleware.js +8 -15
- package/esm/server/dev/utils/fs.js +1 -1
- package/esm/server/dev/utils/hash.js +1 -1
- package/esm/server/dev/utils/http.js +1 -1
- package/esm/server/dev/utils/path.js +1 -1
- package/esm/server/dev/utils/paths.js +1 -1
- package/esm/server/dev/utils/ready.js +1 -1
- package/esm/server/dev/utils/setupHooks.js +9 -6
- package/esm/server/dev/utils/setupOutputFileSystem.js +1 -1
- package/esm/server/dev/utils/setupWatching.js +1 -1
- package/esm/server/dev/utils/setupWriteToDisk.js +1 -1
- package/esm/server/hot/Socket.js +8 -1
- package/esm/server/hot/index.js +3 -3
- package/esm/server/hot/utils.js +1 -1
- package/esm/server/index.d.ts +1 -1
- package/esm/server/index.js +4 -5
- package/esm/server/schema.js +1 -1
- package/esm/server/utils.js +1 -1
- package/global.d.ts +0 -2
- package/package.json +5 -5
- package/cjs/client/hot.cjs +0 -111
- package/cjs/client/hot.d.cts +0 -16
- package/esm/client/hot.d.ts +0 -16
- package/esm/client/hot.js +0 -108
package/README.md
CHANGED
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
import Koa from 'koa';
|
|
22
|
-
import memfs from 'memfs';
|
|
23
22
|
import path from 'node:path';
|
|
24
23
|
import webpack from 'webpack';
|
|
25
24
|
import compress from 'koa-compress';
|
|
25
|
+
import { Volume, createFsFromVolume } from 'memfs';
|
|
26
26
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
27
27
|
import { server as dev } from 'webpack-dev-service';
|
|
28
28
|
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
@@ -45,10 +45,9 @@ const html = {
|
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
function createMemfs() {
|
|
48
|
-
const volume = new
|
|
49
|
-
const fs = memfs.createFsFromVolume(volume);
|
|
48
|
+
const volume = new Volume();
|
|
50
49
|
|
|
51
|
-
return
|
|
50
|
+
return createFsFromVolume(volume);
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
function httpError(error) {
|
|
@@ -67,33 +66,7 @@ const compiler = webpack({
|
|
|
67
66
|
path: path.resolve('wwwroot/public'),
|
|
68
67
|
assetModuleFilename: `[path][name][ext]`
|
|
69
68
|
},
|
|
70
|
-
devtool: 'eval-cheap-module-source-map',
|
|
71
|
-
resolve: {
|
|
72
|
-
fallback: { url: false },
|
|
73
|
-
extensions: ['.ts', '.tsx', '.js', '.jsx']
|
|
74
|
-
},
|
|
75
|
-
watchOptions: {
|
|
76
|
-
aggregateTimeout: 256
|
|
77
|
-
},
|
|
78
|
-
stats: {
|
|
79
|
-
colors: true,
|
|
80
|
-
chunks: false,
|
|
81
|
-
children: false,
|
|
82
|
-
entrypoints: false,
|
|
83
|
-
runtimeModules: false,
|
|
84
|
-
dependentModules: false
|
|
85
|
-
},
|
|
86
|
-
plugins: [
|
|
87
|
-
new HtmlWebpackPlugin(html),
|
|
88
|
-
new MiniCssExtractPlugin({
|
|
89
|
-
ignoreOrder: true,
|
|
90
|
-
filename: 'css/[name].css',
|
|
91
|
-
chunkFilename: 'css/[name].css'
|
|
92
|
-
}),
|
|
93
|
-
new webpack.ProgressPlugin(progress)
|
|
94
|
-
],
|
|
95
69
|
module: {
|
|
96
|
-
strictExportPresence: true,
|
|
97
70
|
rules: [
|
|
98
71
|
{
|
|
99
72
|
oneOf: [
|
|
@@ -136,7 +109,7 @@ const compiler = webpack({
|
|
|
136
109
|
esModule: true,
|
|
137
110
|
modules: {
|
|
138
111
|
auto: true,
|
|
139
|
-
namedExport:
|
|
112
|
+
namedExport: true,
|
|
140
113
|
localIdentName: '[local]-[hash:8]',
|
|
141
114
|
exportLocalsConvention: 'camel-case-only'
|
|
142
115
|
}
|
|
@@ -152,13 +125,41 @@ const compiler = webpack({
|
|
|
152
125
|
]
|
|
153
126
|
}
|
|
154
127
|
]
|
|
155
|
-
}
|
|
128
|
+
},
|
|
129
|
+
resolve: {
|
|
130
|
+
extensions: ['.ts', '.tsx', '.js', '.jsx']
|
|
131
|
+
},
|
|
132
|
+
plugins: [
|
|
133
|
+
new HtmlWebpackPlugin(html),
|
|
134
|
+
new MiniCssExtractPlugin({
|
|
135
|
+
ignoreOrder: true,
|
|
136
|
+
filename: 'css/[name].css',
|
|
137
|
+
chunkFilename: 'css/[name].css'
|
|
138
|
+
}),
|
|
139
|
+
new webpack.ProgressPlugin(progress)
|
|
140
|
+
],
|
|
141
|
+
watchOptions: {
|
|
142
|
+
aggregateTimeout: 256
|
|
143
|
+
},
|
|
144
|
+
stats: {
|
|
145
|
+
all: false,
|
|
146
|
+
assets: true,
|
|
147
|
+
colors: true,
|
|
148
|
+
errors: true,
|
|
149
|
+
timings: true,
|
|
150
|
+
version: true,
|
|
151
|
+
warnings: true,
|
|
152
|
+
errorsCount: true,
|
|
153
|
+
warningsCount: true,
|
|
154
|
+
groupAssetsByPath: true
|
|
155
|
+
},
|
|
156
|
+
devtool: 'eval-cheap-module-source-map'
|
|
156
157
|
});
|
|
157
158
|
|
|
158
159
|
const port = 8000;
|
|
159
160
|
const app = new Koa();
|
|
160
161
|
const fs = createMemfs();
|
|
161
|
-
const server = dev(compiler, {
|
|
162
|
+
const server = await dev(compiler, {
|
|
162
163
|
fs,
|
|
163
164
|
headers: {
|
|
164
165
|
'Cache-Control': 'no-cache',
|
|
@@ -184,9 +185,7 @@ app.on('error', error => {
|
|
|
184
185
|
});
|
|
185
186
|
|
|
186
187
|
app.listen(port, () => {
|
|
187
|
-
server.
|
|
188
|
-
server.logger.info(`server run at: \u001B[36mhttp://127.0.0.1:${port}\u001B[0m`);
|
|
189
|
-
});
|
|
188
|
+
server.logger.info(`server run at: \x1b[36mhttp://127.0.0.1:${port}\x1b[0m`);
|
|
190
189
|
});
|
|
191
190
|
```
|
|
192
191
|
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @package webpack-dev-service
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @version 0.16.0
|
|
5
|
+
* @author nuintun <nuintun@qq.com>
|
|
6
|
+
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
|
+
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @module HotUpdate
|
|
14
|
+
*/
|
|
15
|
+
class HotUpdate {
|
|
16
|
+
#hmr;
|
|
17
|
+
#fallback;
|
|
18
|
+
#pending = false;
|
|
19
|
+
#hash = __webpack_hash__;
|
|
20
|
+
#hot = module.hot;
|
|
21
|
+
/**
|
|
22
|
+
* @constructor
|
|
23
|
+
* @param hmr Whether to enable HMR hot update.
|
|
24
|
+
* @param fallback Fallback handler for update failures.
|
|
25
|
+
*/
|
|
26
|
+
constructor(hmr = true, fallback) {
|
|
27
|
+
this.#hmr = hmr;
|
|
28
|
+
this.#fallback = fallback;
|
|
29
|
+
// Listen to status changes
|
|
30
|
+
this.#hot?.addStatusHandler(async status => {
|
|
31
|
+
if (this.#pending && status === 'idle') {
|
|
32
|
+
this.#pending = false;
|
|
33
|
+
await this.performUpdate();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @method updateHash
|
|
39
|
+
* @description Update hash value.
|
|
40
|
+
* @param hash New hash value.
|
|
41
|
+
*/
|
|
42
|
+
updateHash(hash) {
|
|
43
|
+
this.#hash = hash;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @method #isUpdateAvailable
|
|
47
|
+
* @description Check if new updates are available.
|
|
48
|
+
*/
|
|
49
|
+
#isUpdateAvailable() {
|
|
50
|
+
return this.#hash !== __webpack_hash__;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @method performUpdate
|
|
54
|
+
* @description Execute update strategy.
|
|
55
|
+
*/
|
|
56
|
+
async performUpdate() {
|
|
57
|
+
if (this.#isUpdateAvailable()) {
|
|
58
|
+
if (!this.#hmr || !this.#hot) {
|
|
59
|
+
await this.#fallback();
|
|
60
|
+
} else if (this.#hot.status() === 'idle') {
|
|
61
|
+
try {
|
|
62
|
+
const outdated = await this.#hot.check(true);
|
|
63
|
+
if (this.#isUpdateAvailable()) {
|
|
64
|
+
if (outdated == null || outdated.length <= 0) {
|
|
65
|
+
await this.#fallback();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
} catch (error) {
|
|
69
|
+
await this.#fallback(error);
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
this.#pending = true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
exports.HotUpdate = HotUpdate;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module HotUpdate
|
|
3
|
+
*/
|
|
4
|
+
export interface Fallback {
|
|
5
|
+
(error?: Error): Promise<void> | void;
|
|
6
|
+
}
|
|
7
|
+
export declare class HotUpdate {
|
|
8
|
+
#private;
|
|
9
|
+
/**
|
|
10
|
+
* @constructor
|
|
11
|
+
* @param hmr Whether to enable HMR hot update.
|
|
12
|
+
* @param fallback Fallback handler for update failures.
|
|
13
|
+
*/
|
|
14
|
+
constructor(hmr: boolean | undefined, fallback: Fallback);
|
|
15
|
+
/**
|
|
16
|
+
* @method updateHash
|
|
17
|
+
* @description Update hash value.
|
|
18
|
+
* @param hash New hash value.
|
|
19
|
+
*/
|
|
20
|
+
updateHash(hash: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* @method performUpdate
|
|
23
|
+
* @description Execute update strategy.
|
|
24
|
+
*/
|
|
25
|
+
performUpdate(): Promise<void>;
|
|
26
|
+
}
|
package/cjs/client/client.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.16.0
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
7
|
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
@@ -12,31 +12,29 @@
|
|
|
12
12
|
const events = require('./events.cjs');
|
|
13
13
|
const Overlay = require('./ui/Overlay.cjs');
|
|
14
14
|
const Progress = require('./ui/Progress.cjs');
|
|
15
|
-
const
|
|
15
|
+
const HotUpdate = require('./HotUpdate.cjs');
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @module client
|
|
19
19
|
*/
|
|
20
20
|
function createClient(options) {
|
|
21
|
-
let updateTimer;
|
|
22
|
-
const UPDATE_DELAY = 128;
|
|
23
21
|
const RETRY_INTERVAL = 3000;
|
|
24
22
|
const progress = new Progress.Progress();
|
|
25
23
|
const overlay = new Overlay.Overlay(options.name);
|
|
26
24
|
const fallback = () => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
25
|
+
return new Promise(resolve => {
|
|
26
|
+
queueMicrotask(() => {
|
|
27
|
+
if (options.reload) {
|
|
28
|
+
self.location.reload();
|
|
29
|
+
} else {
|
|
30
|
+
console.warn('[HMR] Hot update failed. Please reload the page manually.');
|
|
31
|
+
}
|
|
32
|
+
resolve();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
37
35
|
};
|
|
36
|
+
const hot = new HotUpdate.HotUpdate(options.hmr, fallback);
|
|
38
37
|
const onInvalid = () => {
|
|
39
|
-
clearTimeout(updateTimer);
|
|
40
38
|
if (options.progress) {
|
|
41
39
|
progress.update(0);
|
|
42
40
|
progress.show();
|
|
@@ -74,14 +72,14 @@ function createClient(options) {
|
|
|
74
72
|
overlay.show();
|
|
75
73
|
}
|
|
76
74
|
if (errors.length <= 0) {
|
|
77
|
-
|
|
75
|
+
hot.performUpdate();
|
|
78
76
|
}
|
|
79
77
|
};
|
|
80
78
|
const onOk = () => {
|
|
81
79
|
progress.update(1);
|
|
82
80
|
progress.hide();
|
|
83
81
|
overlay.hide();
|
|
84
|
-
|
|
82
|
+
hot.performUpdate();
|
|
85
83
|
};
|
|
86
84
|
const parseMessage = message => {
|
|
87
85
|
try {
|
package/cjs/client/events.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.16.0
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
7
|
* @see https://github.com/nuintun/webpack-dev-service#readme
|
package/cjs/client/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.16.0
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
7
|
* @see https://github.com/nuintun/webpack-dev-service#readme
|
package/cjs/client/main.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.16.0
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
7
|
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.16.0
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
7
|
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
@@ -185,8 +185,8 @@ class Overlay {
|
|
|
185
185
|
#warningsTitle;
|
|
186
186
|
constructor(name) {
|
|
187
187
|
const root = utils.getRootElement(OVERLAY);
|
|
188
|
-
utils.
|
|
189
|
-
const [dialog] = utils.
|
|
188
|
+
utils.insertCSSString(CSS, root);
|
|
189
|
+
const [dialog] = utils.appendDOMString('text/html', HTML, root);
|
|
190
190
|
this.#dialog = dialog;
|
|
191
191
|
this.#name = dialog.querySelector(`.${OVERLAY}-name`);
|
|
192
192
|
this.#close = dialog.querySelector(`.${OVERLAY}-close`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.16.0
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
7
|
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
@@ -52,8 +52,8 @@ const CSS = `
|
|
|
52
52
|
transform: matrix(0, -1, 1, 0, 0, 96) translateZ(0);
|
|
53
53
|
}
|
|
54
54
|
`;
|
|
55
|
-
const
|
|
56
|
-
<svg class="${PROGRESS}" x="0" y="0" viewBox="0 0 96 96">
|
|
55
|
+
const SVG = `
|
|
56
|
+
<svg xmlns="http://www.w3.org/2000/svg" class="${PROGRESS}" x="0" y="0" viewBox="0 0 96 96">
|
|
57
57
|
<circle fill="#101619" cx="50%" cy="50%" r="44" />
|
|
58
58
|
<circle class="${PROGRESS}-track" cx="50%" cy="50%" r="44" />
|
|
59
59
|
<image href="${webpackLogo}" x="16" y="16" width="64" height="64"/>
|
|
@@ -66,8 +66,8 @@ class Progress {
|
|
|
66
66
|
#track;
|
|
67
67
|
constructor() {
|
|
68
68
|
const root = utils.getRootElement(PROGRESS);
|
|
69
|
-
utils.
|
|
70
|
-
[this.#svg] = utils.
|
|
69
|
+
utils.insertCSSString(CSS, root);
|
|
70
|
+
[this.#svg] = utils.appendDOMString('image/svg+xml', SVG, root);
|
|
71
71
|
this.#track = this.#svg.querySelector(`.${PROGRESS}-track`);
|
|
72
72
|
}
|
|
73
73
|
update(percentage) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.16.0
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
7
|
* @see https://github.com/nuintun/webpack-dev-service#readme
|
package/cjs/client/ui/utils.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.16.0
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
7
|
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
@@ -99,32 +99,33 @@ function ansiToHTML(text) {
|
|
|
99
99
|
}
|
|
100
100
|
function getRootElement(tagName) {
|
|
101
101
|
const stage = document.createElement(tagName);
|
|
102
|
-
const
|
|
102
|
+
const shadowRoot = stage.attachShadow({ mode: 'closed' });
|
|
103
103
|
document.body.appendChild(stage);
|
|
104
|
-
return
|
|
104
|
+
return shadowRoot;
|
|
105
105
|
}
|
|
106
|
-
function
|
|
107
|
-
styleElement.appendChild(document.createTextNode(css
|
|
106
|
+
function insertCSSString(css, root = document.body, styleElement = document.createElement('style')) {
|
|
107
|
+
styleElement.appendChild(document.createTextNode(css));
|
|
108
108
|
if (!root.contains(styleElement)) {
|
|
109
109
|
root.appendChild(styleElement);
|
|
110
110
|
}
|
|
111
111
|
return styleElement;
|
|
112
112
|
}
|
|
113
|
-
function
|
|
113
|
+
function appendDOMString(type, string, root = document.body) {
|
|
114
114
|
const nodes = [];
|
|
115
115
|
const parser = new DOMParser();
|
|
116
116
|
const fragment = document.createDocumentFragment();
|
|
117
|
-
const { body } = parser.parseFromString(
|
|
118
|
-
|
|
119
|
-
nodes.push(
|
|
117
|
+
const { body, childNodes } = parser.parseFromString(string, type);
|
|
118
|
+
for (const node of body ? body.childNodes : childNodes) {
|
|
119
|
+
nodes.push(node);
|
|
120
|
+
fragment.appendChild(node);
|
|
120
121
|
}
|
|
121
122
|
root.appendChild(fragment);
|
|
122
123
|
return nodes;
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
exports.ansiToHTML = ansiToHTML;
|
|
126
|
-
exports.
|
|
127
|
+
exports.appendDOMString = appendDOMString;
|
|
127
128
|
exports.blockToHTML = blockToHTML;
|
|
128
129
|
exports.escapeHTML = escapeHTML;
|
|
129
130
|
exports.getRootElement = getRootElement;
|
|
130
|
-
exports.
|
|
131
|
+
exports.insertCSSString = insertCSSString;
|
|
@@ -7,9 +7,13 @@ export declare function blockToHTML({ style, value, url }: AnsiBlock): string;
|
|
|
7
7
|
export declare function ansiToHTML(text: string): string;
|
|
8
8
|
export type RootElement = HTMLElement | ShadowRoot;
|
|
9
9
|
export declare function getRootElement(tagName: string): ShadowRoot;
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function insertCSSString(
|
|
11
11
|
css: string,
|
|
12
12
|
root?: HTMLElement | ShadowRoot,
|
|
13
13
|
styleElement?: HTMLStyleElement
|
|
14
14
|
): HTMLStyleElement;
|
|
15
|
-
export declare function
|
|
15
|
+
export declare function appendDOMString<T extends DOMParserSupportedType>(
|
|
16
|
+
type: T,
|
|
17
|
+
string: string,
|
|
18
|
+
root?: RootElement
|
|
19
|
+
): (T extends 'image/svg+xml' ? SVGElement : HTMLElement)[];
|
package/cjs/server/compose.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.16.0
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
7
|
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.16.0
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
7
|
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.16.0
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
7
|
* @see https://github.com/nuintun/webpack-dev-service#readme
|
package/cjs/server/dev/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.16.0
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
7
|
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
-
const ready = require('./utils/ready.cjs');
|
|
13
12
|
const fs = require('./utils/fs.cjs');
|
|
14
13
|
const middleware = require('./middleware.cjs');
|
|
15
14
|
const setupHooks = require('./utils/setupHooks.cjs');
|
|
@@ -38,18 +37,12 @@ function setup(compiler, options) {
|
|
|
38
37
|
setupWatching.setupWatching(context);
|
|
39
38
|
return context;
|
|
40
39
|
}
|
|
41
|
-
function dev(compiler, options) {
|
|
40
|
+
async function dev(compiler, options) {
|
|
42
41
|
const context = setup(compiler, options);
|
|
43
|
-
return Object.assign(middleware.middleware(context), {
|
|
44
|
-
get state() {
|
|
45
|
-
return !!context.stats;
|
|
46
|
-
},
|
|
42
|
+
return Object.assign(await middleware.middleware(context), {
|
|
47
43
|
get logger() {
|
|
48
44
|
return context.logger;
|
|
49
45
|
},
|
|
50
|
-
ready(callback) {
|
|
51
|
-
ready.ready(context, callback);
|
|
52
|
-
},
|
|
53
46
|
close(callback) {
|
|
54
47
|
context.watching.close(callback);
|
|
55
48
|
},
|
|
@@ -5,4 +5,4 @@ import { Middleware } from 'koa';
|
|
|
5
5
|
import { UnionCompiler } from '../interface.cjs';
|
|
6
6
|
import { Expose, Options } from './interface.cjs';
|
|
7
7
|
export { Expose, Options };
|
|
8
|
-
export declare function dev(compiler: UnionCompiler, options: Options): Middleware & Expose
|
|
8
|
+
export declare function dev(compiler: UnionCompiler, options: Options): Promise<Middleware & Expose>;
|
|
@@ -13,8 +13,6 @@ export interface ErrorCallback {
|
|
|
13
13
|
}
|
|
14
14
|
export interface Expose {
|
|
15
15
|
readonly logger: Logger;
|
|
16
|
-
readonly state: boolean;
|
|
17
|
-
readonly ready: (callback: Callback) => void;
|
|
18
16
|
readonly close: (callback: ErrorCallback) => void;
|
|
19
17
|
readonly invalidate: (callback: ErrorCallback) => void;
|
|
20
18
|
}
|
|
@@ -29,7 +27,6 @@ export interface Context {
|
|
|
29
27
|
callbacks: Callback[];
|
|
30
28
|
compiler: UnionCompiler;
|
|
31
29
|
watching: UnionWatching;
|
|
32
|
-
services?: FileService[];
|
|
33
30
|
stats: UnionStats | null;
|
|
34
31
|
options: Options & {
|
|
35
32
|
fs: FileSystem;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.16.0
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
7
|
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
@@ -18,11 +18,6 @@ const paths = require('./utils/paths.cjs');
|
|
|
18
18
|
* @module middleware
|
|
19
19
|
*/
|
|
20
20
|
function getFileServices(context, stats) {
|
|
21
|
-
const cached = context.services;
|
|
22
|
-
// Cache hit.
|
|
23
|
-
if (cached) {
|
|
24
|
-
return cached;
|
|
25
|
-
}
|
|
26
21
|
const { options } = context;
|
|
27
22
|
const paths$1 = paths.getPaths(stats);
|
|
28
23
|
const services = [];
|
|
@@ -30,8 +25,6 @@ function getFileServices(context, stats) {
|
|
|
30
25
|
for (const [outputPath, publicPath] of paths$1) {
|
|
31
26
|
services.push([publicPath, new Service.Service(outputPath, options)]);
|
|
32
27
|
}
|
|
33
|
-
// Cache services.
|
|
34
|
-
context.services = services;
|
|
35
28
|
// Return services.
|
|
36
29
|
return services;
|
|
37
30
|
}
|
|
@@ -49,24 +42,24 @@ function getFileServicesAsync(context) {
|
|
|
49
42
|
}
|
|
50
43
|
});
|
|
51
44
|
}
|
|
52
|
-
function middleware(context) {
|
|
45
|
+
async function middleware(context) {
|
|
46
|
+
// Get the file services.
|
|
47
|
+
const services = await getFileServicesAsync(context);
|
|
53
48
|
// Middleware.
|
|
54
|
-
return async (
|
|
55
|
-
const { request } =
|
|
49
|
+
return async (context, next) => {
|
|
50
|
+
const { request } = context;
|
|
56
51
|
const pathname = http.decodeURI(request.path);
|
|
57
52
|
// Pathname decode failed or includes null byte(s).
|
|
58
53
|
if (pathname === -1 || pathname.includes('\0')) {
|
|
59
|
-
return
|
|
54
|
+
return context.throw(400);
|
|
60
55
|
}
|
|
61
56
|
// Get request method.
|
|
62
57
|
const { method } = request;
|
|
63
58
|
// Only support GET and HEAD (405).
|
|
64
59
|
if (method === 'GET' || method === 'HEAD') {
|
|
65
|
-
// Get the file services.
|
|
66
|
-
const services = await getFileServicesAsync(context);
|
|
67
60
|
// Try to respond.
|
|
68
61
|
for (const [publicPath, service] of services) {
|
|
69
|
-
if (await service.respond(pathname,
|
|
62
|
+
if (await service.respond(pathname, context, publicPath)) {
|
|
70
63
|
return;
|
|
71
64
|
}
|
|
72
65
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.16.0
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
7
|
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.16.0
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
7
|
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.16.0
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
7
|
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.16.0
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
7
|
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.16.0
|
|
5
5
|
* @author nuintun <nuintun@qq.com>
|
|
6
6
|
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
7
|
* @see https://github.com/nuintun/webpack-dev-service#readme
|