webpack-dev-service 0.8.0 → 0.9.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 +26 -36
- package/client/cjs/client.cjs +14 -15
- package/client/cjs/events.cjs +2 -2
- package/client/cjs/hot.cjs +1 -1
- package/client/cjs/index.cjs +1 -1
- package/client/cjs/main.cjs +22 -41
- package/client/cjs/ui/overlay.cjs +7 -7
- package/client/cjs/ui/progress.cjs +1 -1
- package/client/cjs/ui/utils.cjs +1 -1
- package/client/esm/client.js +14 -15
- package/client/esm/events.js +2 -2
- package/client/esm/hot.js +1 -1
- package/client/esm/index.js +1 -1
- package/client/esm/main.js +22 -41
- package/client/esm/ui/overlay.js +7 -7
- package/client/esm/ui/progress.js +1 -1
- package/client/esm/ui/utils.js +1 -1
- package/package.json +12 -8
- package/server/cjs/{dev/utils/compose.cjs → compose.cjs} +8 -10
- package/server/cjs/dev/Service.cjs +269 -0
- package/server/cjs/dev/index.cjs +9 -11
- package/server/cjs/dev/middleware.cjs +54 -28
- package/server/cjs/dev/utils/fs.cjs +29 -0
- package/server/cjs/dev/utils/{boundary.cjs → hash.cjs} +14 -10
- package/server/cjs/dev/utils/http.cjs +168 -10
- package/server/cjs/dev/utils/path.cjs +46 -0
- package/server/cjs/dev/utils/paths.cjs +59 -0
- package/server/cjs/dev/utils/ready.cjs +6 -9
- package/server/cjs/dev/utils/setupHooks.cjs +51 -40
- package/server/cjs/dev/utils/setupOutputFileSystem.cjs +6 -39
- package/server/cjs/dev/utils/setupWatching.cjs +3 -3
- package/server/cjs/dev/utils/setupWriteToDisk.cjs +23 -31
- package/server/cjs/hot/Socket.cjs +88 -111
- package/server/cjs/hot/index.cjs +13 -15
- package/server/cjs/hot/utils.cjs +100 -0
- package/server/cjs/index.cjs +17 -7
- package/server/cjs/schema.cjs +127 -0
- package/server/cjs/utils.cjs +45 -0
- package/server/esm/{dev/utils/compose.js → compose.js} +8 -10
- package/server/esm/dev/Service.js +260 -0
- package/server/esm/dev/index.js +8 -10
- package/server/esm/dev/middleware.js +53 -27
- package/server/esm/dev/utils/fs.js +27 -0
- package/server/esm/dev/utils/{boundary.js → hash.js} +14 -10
- package/server/esm/dev/utils/http.js +159 -8
- package/server/esm/dev/utils/path.js +42 -0
- package/server/esm/dev/utils/paths.js +57 -0
- package/server/esm/dev/utils/ready.js +6 -9
- package/server/esm/dev/utils/setupHooks.js +46 -35
- package/server/esm/dev/utils/setupOutputFileSystem.js +5 -38
- package/server/esm/dev/utils/setupWatching.js +2 -2
- package/server/esm/dev/utils/setupWriteToDisk.js +22 -30
- package/server/esm/hot/Socket.js +87 -110
- package/server/esm/hot/index.js +13 -15
- package/server/esm/hot/utils.js +93 -0
- package/server/esm/index.js +17 -7
- package/server/esm/schema.js +125 -0
- package/server/esm/utils.js +37 -0
- package/types/client/client.d.ts +1 -1
- package/types/client/events.d.ts +6 -6
- package/types/client/message.d.ts +6 -5
- package/types/client/ui/overlay.d.ts +1 -1
- package/types/server/dev/Service.d.ts +82 -0
- package/types/server/dev/index.d.ts +4 -4
- package/types/server/dev/interface.d.ts +26 -34
- package/types/server/dev/utils/fs.d.ts +27 -0
- package/types/server/dev/utils/hash.d.ts +9 -0
- package/types/server/dev/utils/http.d.ts +31 -14
- package/types/server/dev/utils/path.d.ts +22 -0
- package/types/server/dev/utils/paths.d.ts +7 -0
- package/types/server/dev/utils/ready.d.ts +2 -2
- package/types/server/hot/Socket.d.ts +6 -10
- package/types/server/hot/index.d.ts +4 -9
- package/types/server/hot/interface.d.ts +20 -0
- package/types/server/hot/utils.d.ts +13 -0
- package/types/server/index.d.ts +8 -8
- package/types/server/interface.d.ts +9 -0
- package/types/server/schema.d.ts +7 -0
- package/types/server/utils.d.ts +12 -0
- package/global.d.ts +0 -16
- package/server/cjs/dev/Files.cjs +0 -394
- package/server/cjs/dev/utils/common.cjs +0 -98
- package/server/cjs/dev/utils/getPaths.cjs +0 -65
- package/server/esm/dev/Files.js +0 -384
- package/server/esm/dev/utils/common.js +0 -98
- package/server/esm/dev/utils/getPaths.js +0 -63
- package/types/server/dev/Files.d.ts +0 -83
- package/types/server/dev/utils/boundary.d.ts +0 -8
- package/types/server/dev/utils/common.d.ts +0 -44
- package/types/server/dev/utils/getPaths.d.ts +0 -10
- /package/types/server/{dev/utils/compose.d.ts → compose.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
### Usage
|
|
14
14
|
|
|
15
|
-
```
|
|
15
|
+
```ts
|
|
16
16
|
/**
|
|
17
17
|
* @module webpack
|
|
18
18
|
* @description Webpack config
|
|
@@ -22,6 +22,7 @@ import Koa from 'koa';
|
|
|
22
22
|
import path from 'path';
|
|
23
23
|
import memfs from 'memfs';
|
|
24
24
|
import webpack from 'webpack';
|
|
25
|
+
import compress from 'koa-compress';
|
|
25
26
|
import dev from 'webpack-dev-service';
|
|
26
27
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
27
28
|
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
@@ -39,7 +40,7 @@ const html = {
|
|
|
39
40
|
filename: entryHTML,
|
|
40
41
|
templateParameters: { lang: 'en' },
|
|
41
42
|
template: path.resolve('index.ejs'),
|
|
42
|
-
favicon: path.resolve('src/
|
|
43
|
+
favicon: path.resolve('src/images/favicon.ico'),
|
|
43
44
|
meta: { 'theme-color': '#4285f4', viewport: 'width=device-width,initial-scale=1.0' }
|
|
44
45
|
};
|
|
45
46
|
|
|
@@ -47,8 +48,6 @@ function createMemfs() {
|
|
|
47
48
|
const volume = new memfs.Volume();
|
|
48
49
|
const fs = memfs.createFsFromVolume(volume);
|
|
49
50
|
|
|
50
|
-
fs.join = path.join.bind(path);
|
|
51
|
-
|
|
52
51
|
return fs;
|
|
53
52
|
}
|
|
54
53
|
|
|
@@ -60,16 +59,10 @@ const compiler = webpack({
|
|
|
60
59
|
name: 'react',
|
|
61
60
|
mode: 'development',
|
|
62
61
|
context: path.resolve('src'),
|
|
63
|
-
entry:
|
|
64
|
-
// Entry file
|
|
65
|
-
path.resolve('src/index.jsx'),
|
|
66
|
-
// Hot client
|
|
67
|
-
'webpack-dev-service/client'
|
|
68
|
-
],
|
|
62
|
+
entry: path.resolve('src/index.tsx'),
|
|
69
63
|
output: {
|
|
70
64
|
publicPath: '/public/',
|
|
71
65
|
filename: `js/[name].js`,
|
|
72
|
-
hashFunction: 'xxhash64',
|
|
73
66
|
path: path.resolve('public'),
|
|
74
67
|
chunkFilename: `js/[name].js`,
|
|
75
68
|
assetModuleFilename: `[path][name][ext]`
|
|
@@ -77,7 +70,7 @@ const compiler = webpack({
|
|
|
77
70
|
devtool: 'eval-cheap-module-source-map',
|
|
78
71
|
resolve: {
|
|
79
72
|
fallback: { url: false },
|
|
80
|
-
extensions: ['.js', '.jsx']
|
|
73
|
+
extensions: ['.ts', '.tsx', '.js', '.jsx']
|
|
81
74
|
},
|
|
82
75
|
watchOptions: {
|
|
83
76
|
aggregateTimeout: 256
|
|
@@ -90,20 +83,28 @@ const compiler = webpack({
|
|
|
90
83
|
runtimeModules: false,
|
|
91
84
|
dependentModules: false
|
|
92
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
|
+
],
|
|
93
95
|
module: {
|
|
94
96
|
strictExportPresence: true,
|
|
95
97
|
rules: [
|
|
96
98
|
{
|
|
97
99
|
oneOf: [
|
|
98
100
|
{
|
|
99
|
-
test: /\.
|
|
101
|
+
test: /\.[jt]sx?$/i,
|
|
100
102
|
exclude: /[\\/]node_modules[\\/]/,
|
|
101
103
|
use: [
|
|
102
104
|
{
|
|
103
105
|
loader: 'swc-loader',
|
|
104
106
|
options: {
|
|
105
107
|
jsc: {
|
|
106
|
-
target: 'es2015',
|
|
107
108
|
externalHelpers: true,
|
|
108
109
|
parser: {
|
|
109
110
|
tsx: true,
|
|
@@ -113,9 +114,6 @@ const compiler = webpack({
|
|
|
113
114
|
react: {
|
|
114
115
|
runtime: 'automatic'
|
|
115
116
|
}
|
|
116
|
-
},
|
|
117
|
-
experimental: {
|
|
118
|
-
cacheRoot: path.resolve('node_modules/.cache/swc')
|
|
119
117
|
}
|
|
120
118
|
},
|
|
121
119
|
env: {
|
|
@@ -146,41 +144,33 @@ const compiler = webpack({
|
|
|
146
144
|
]
|
|
147
145
|
},
|
|
148
146
|
{
|
|
149
|
-
test: /\.svg$/i,
|
|
147
|
+
test: /\.(svg|mp4)$/i,
|
|
150
148
|
type: 'asset/resource',
|
|
151
149
|
exclude: /[\\/]node_modules[\\/]/
|
|
152
150
|
}
|
|
153
151
|
]
|
|
154
152
|
}
|
|
155
153
|
]
|
|
156
|
-
}
|
|
157
|
-
plugins: [
|
|
158
|
-
new webpack.ProgressPlugin(progress),
|
|
159
|
-
new HtmlWebpackPlugin(html),
|
|
160
|
-
new MiniCssExtractPlugin({
|
|
161
|
-
ignoreOrder: true,
|
|
162
|
-
filename: 'css/[name].css',
|
|
163
|
-
chunkFilename: 'css/[name].css'
|
|
164
|
-
})
|
|
165
|
-
]
|
|
154
|
+
}
|
|
166
155
|
});
|
|
167
156
|
|
|
168
157
|
const port = 8000;
|
|
169
158
|
const app = new Koa();
|
|
170
159
|
const fs = createMemfs();
|
|
171
160
|
const server = dev(compiler, {
|
|
172
|
-
|
|
173
|
-
outputFileSystem: fs,
|
|
161
|
+
fs,
|
|
174
162
|
headers: {
|
|
175
|
-
'Cache-Control': 'no-
|
|
176
|
-
'
|
|
177
|
-
'Access-Control-Allow-Methods': '*',
|
|
178
|
-
'Access-Control-Allow-Headers': '*',
|
|
179
|
-
'X-Content-Type-Options': 'nosniff',
|
|
180
|
-
'Access-Control-Allow-Credentials': 'true'
|
|
163
|
+
'Cache-Control': 'no-cache',
|
|
164
|
+
'X-Content-Type-Options': 'nosniff'
|
|
181
165
|
}
|
|
182
166
|
});
|
|
183
167
|
|
|
168
|
+
app.use(
|
|
169
|
+
compress({
|
|
170
|
+
br: false
|
|
171
|
+
})
|
|
172
|
+
);
|
|
173
|
+
|
|
184
174
|
app.use(server);
|
|
185
175
|
|
|
186
176
|
app.use(async ctx => {
|
package/client/cjs/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.9.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
|
|
@@ -23,11 +23,10 @@ function createClient(options) {
|
|
|
23
23
|
const RETRY_INTERVAL = 3000;
|
|
24
24
|
const progress$1 = new progress();
|
|
25
25
|
const overlay$1 = new overlay(options.name);
|
|
26
|
-
const fallback =
|
|
27
|
-
if (options.
|
|
26
|
+
const fallback = () => {
|
|
27
|
+
if (options.reload) {
|
|
28
28
|
self.location.reload();
|
|
29
|
-
} else
|
|
30
|
-
console.error(error);
|
|
29
|
+
} else {
|
|
31
30
|
console.warn('Use fallback update but you turn off live reload, please reload by yourself.');
|
|
32
31
|
}
|
|
33
32
|
};
|
|
@@ -51,9 +50,9 @@ function createClient(options) {
|
|
|
51
50
|
const onHash = ({ hash }) => {
|
|
52
51
|
hot.setHash(hash);
|
|
53
52
|
};
|
|
54
|
-
const
|
|
53
|
+
const setIssues = (type, issues) => {
|
|
55
54
|
if (options.overlay) {
|
|
56
|
-
overlay$1.
|
|
55
|
+
overlay$1.setIssues(type, issues);
|
|
57
56
|
}
|
|
58
57
|
const maps = {
|
|
59
58
|
errors: ['\x1b[38;2;100;30;22m\x1b[48;2;255;95;88m ERROR \x1b[0m', 'error'],
|
|
@@ -61,15 +60,15 @@ function createClient(options) {
|
|
|
61
60
|
};
|
|
62
61
|
const [name, method] = maps[type];
|
|
63
62
|
const debug = console[method];
|
|
64
|
-
for (const { moduleName, chunkName, message } of
|
|
63
|
+
for (const { moduleName, chunkName, message } of issues) {
|
|
65
64
|
const filename = moduleName || chunkName || 'unknown';
|
|
66
65
|
debug(`${name} in ${filename}\n${message}`);
|
|
67
66
|
}
|
|
68
67
|
};
|
|
69
|
-
const
|
|
68
|
+
const onIssues = ({ errors, warnings }) => {
|
|
70
69
|
progress$1.hide();
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
setIssues('errors', errors);
|
|
71
|
+
setIssues('warnings', warnings);
|
|
73
72
|
if (options.overlay) {
|
|
74
73
|
overlay$1.show();
|
|
75
74
|
}
|
|
@@ -77,7 +76,7 @@ function createClient(options) {
|
|
|
77
76
|
applyUpdateAsync();
|
|
78
77
|
}
|
|
79
78
|
};
|
|
80
|
-
const
|
|
79
|
+
const onOk = () => {
|
|
81
80
|
overlay$1.hide();
|
|
82
81
|
progress$1.hide();
|
|
83
82
|
applyUpdateAsync();
|
|
@@ -105,11 +104,11 @@ function createClient(options) {
|
|
|
105
104
|
case 'hash':
|
|
106
105
|
onHash(payload);
|
|
107
106
|
break;
|
|
108
|
-
case '
|
|
109
|
-
|
|
107
|
+
case 'issues':
|
|
108
|
+
onIssues(payload);
|
|
110
109
|
break;
|
|
111
110
|
case 'ok':
|
|
112
|
-
|
|
111
|
+
onOk();
|
|
113
112
|
break;
|
|
114
113
|
}
|
|
115
114
|
events.emit(action, payload, options);
|
package/client/cjs/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.9.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
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
const events = {
|
|
16
16
|
ok: [],
|
|
17
17
|
hash: [],
|
|
18
|
+
issues: [],
|
|
18
19
|
invalid: [],
|
|
19
|
-
problems: [],
|
|
20
20
|
progress: []
|
|
21
21
|
};
|
|
22
22
|
/**
|
package/client/cjs/hot.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.9.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/client/cjs/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.9.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/client/cjs/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.9.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
|
|
@@ -23,8 +23,8 @@ const getCurrentScript = () => {
|
|
|
23
23
|
return currentScript;
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
|
-
const
|
|
27
|
-
switch (params.get('
|
|
26
|
+
const getProtocol = (params, protocol) => {
|
|
27
|
+
switch (params.get('wss')) {
|
|
28
28
|
case 'true':
|
|
29
29
|
return 'wss:';
|
|
30
30
|
case 'false':
|
|
@@ -33,46 +33,27 @@ const resolveProtocol = (params, protocol) => {
|
|
|
33
33
|
return isTLS(protocol) ? 'wss:' : 'ws:';
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
|
-
const
|
|
36
|
+
const getOrigin = params => {
|
|
37
37
|
const { location } = self;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
protocol =
|
|
42
|
-
|
|
43
|
-
const script = getCurrentScript();
|
|
44
|
-
if (script) {
|
|
45
|
-
const { src } = script;
|
|
46
|
-
const url = new URL(src, location.href);
|
|
47
|
-
host = url.host;
|
|
48
|
-
protocol = resolveProtocol(params, url.protocol);
|
|
49
|
-
} else {
|
|
50
|
-
host = location.host;
|
|
51
|
-
protocol = resolveProtocol(params, location.protocol);
|
|
52
|
-
}
|
|
38
|
+
const script = getCurrentScript();
|
|
39
|
+
if (script) {
|
|
40
|
+
const url = new URL(script.src, location.href);
|
|
41
|
+
const protocol = getProtocol(params, url.protocol);
|
|
42
|
+
return `${protocol}//${url.host}`;
|
|
53
43
|
}
|
|
54
|
-
|
|
44
|
+
const protocol = getProtocol(params, location.protocol);
|
|
45
|
+
return `${protocol}//${location.host}`;
|
|
55
46
|
};
|
|
56
|
-
const
|
|
47
|
+
const getOptions = () => {
|
|
57
48
|
const params = new URLSearchParams(__resourceQuery);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
origin,
|
|
68
|
-
overlay,
|
|
69
|
-
name: options.name,
|
|
70
|
-
path: options.path,
|
|
71
|
-
hmr: options.hmr === false ? false : hmr,
|
|
72
|
-
progress: options.progress === false ? false : progress
|
|
73
|
-
};
|
|
74
|
-
} catch (_a) {
|
|
75
|
-
throw new Error('Imported the hot client but the hot server is not enabled.');
|
|
76
|
-
}
|
|
49
|
+
return {
|
|
50
|
+
origin: getOrigin(params),
|
|
51
|
+
hmr: params.get('hmr') !== 'false',
|
|
52
|
+
path: params.get('path') || '/hot',
|
|
53
|
+
name: params.get('name') || 'webpack',
|
|
54
|
+
reload: params.get('reload') !== 'false',
|
|
55
|
+
overlay: params.get('overlay') !== 'false',
|
|
56
|
+
progress: params.get('progress') !== 'false'
|
|
57
|
+
};
|
|
77
58
|
};
|
|
78
|
-
client(
|
|
59
|
+
client(getOptions());
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.9.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
|
|
@@ -98,7 +98,7 @@ const CSS = `
|
|
|
98
98
|
.${OVERLAY}-warnings-title {
|
|
99
99
|
color: #ffbd2e;
|
|
100
100
|
}
|
|
101
|
-
.${OVERLAY}-
|
|
101
|
+
.${OVERLAY}-issues {
|
|
102
102
|
padding: 0 16px;
|
|
103
103
|
overflow-y: auto;
|
|
104
104
|
scrollbar-width: none;
|
|
@@ -107,7 +107,7 @@ const CSS = `
|
|
|
107
107
|
overscroll-behavior: contain;
|
|
108
108
|
-webkit-overflow-scrolling: touch;
|
|
109
109
|
}
|
|
110
|
-
.${OVERLAY}-
|
|
110
|
+
.${OVERLAY}-issues::-webkit-scrollbar {
|
|
111
111
|
display: none;
|
|
112
112
|
}
|
|
113
113
|
.${OVERLAY}-errors,
|
|
@@ -168,7 +168,7 @@ const HTML = `
|
|
|
168
168
|
<em class="${OVERLAY}-errors-title"></em>
|
|
169
169
|
<em class="${OVERLAY}-warnings-title"></em>
|
|
170
170
|
</div>
|
|
171
|
-
<aside class="${OVERLAY}-
|
|
171
|
+
<aside class="${OVERLAY}-issues">
|
|
172
172
|
<article class="${OVERLAY}-errors ${OVERLAY}-hidden"></article>
|
|
173
173
|
<article class="${OVERLAY}-warnings ${OVERLAY}-hidden"></article>
|
|
174
174
|
</aside>
|
|
@@ -192,8 +192,8 @@ class Overlay {
|
|
|
192
192
|
this.hide();
|
|
193
193
|
});
|
|
194
194
|
}
|
|
195
|
-
|
|
196
|
-
const count =
|
|
195
|
+
setIssues(type, issues) {
|
|
196
|
+
const count = issues.length;
|
|
197
197
|
const hidden = `${OVERLAY}-hidden`;
|
|
198
198
|
const problemMaps = {
|
|
199
199
|
errors: ['Error', this.errorsTitle, this.errorsList],
|
|
@@ -203,7 +203,7 @@ class Overlay {
|
|
|
203
203
|
if (count > 0) {
|
|
204
204
|
let html = '';
|
|
205
205
|
problemTitle.innerText = `${count} ${name}(s)`;
|
|
206
|
-
for (const { moduleName, chunkName, message } of
|
|
206
|
+
for (const { moduleName, chunkName, message } of issues) {
|
|
207
207
|
const details = utils.ansiToHTML(message);
|
|
208
208
|
const filename = moduleName || chunkName || 'unknown';
|
|
209
209
|
html += `<section><em>${name}</em> in ${filename}<pre>${details}</pre></section>`;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.9.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/client/cjs/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.9.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/client/esm/client.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.9.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
|
|
@@ -21,11 +21,10 @@ function createClient(options) {
|
|
|
21
21
|
const RETRY_INTERVAL = 3000;
|
|
22
22
|
const progress = new Progress();
|
|
23
23
|
const overlay = new Overlay(options.name);
|
|
24
|
-
const fallback =
|
|
25
|
-
if (options.
|
|
24
|
+
const fallback = () => {
|
|
25
|
+
if (options.reload) {
|
|
26
26
|
self.location.reload();
|
|
27
|
-
} else
|
|
28
|
-
console.error(error);
|
|
27
|
+
} else {
|
|
29
28
|
console.warn('Use fallback update but you turn off live reload, please reload by yourself.');
|
|
30
29
|
}
|
|
31
30
|
};
|
|
@@ -49,9 +48,9 @@ function createClient(options) {
|
|
|
49
48
|
const onHash = ({ hash }) => {
|
|
50
49
|
setHash(hash);
|
|
51
50
|
};
|
|
52
|
-
const
|
|
51
|
+
const setIssues = (type, issues) => {
|
|
53
52
|
if (options.overlay) {
|
|
54
|
-
overlay.
|
|
53
|
+
overlay.setIssues(type, issues);
|
|
55
54
|
}
|
|
56
55
|
const maps = {
|
|
57
56
|
errors: ['\x1b[38;2;100;30;22m\x1b[48;2;255;95;88m ERROR \x1b[0m', 'error'],
|
|
@@ -59,15 +58,15 @@ function createClient(options) {
|
|
|
59
58
|
};
|
|
60
59
|
const [name, method] = maps[type];
|
|
61
60
|
const debug = console[method];
|
|
62
|
-
for (const { moduleName, chunkName, message } of
|
|
61
|
+
for (const { moduleName, chunkName, message } of issues) {
|
|
63
62
|
const filename = moduleName || chunkName || 'unknown';
|
|
64
63
|
debug(`${name} in ${filename}\n${message}`);
|
|
65
64
|
}
|
|
66
65
|
};
|
|
67
|
-
const
|
|
66
|
+
const onIssues = ({ errors, warnings }) => {
|
|
68
67
|
progress.hide();
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
setIssues('errors', errors);
|
|
69
|
+
setIssues('warnings', warnings);
|
|
71
70
|
if (options.overlay) {
|
|
72
71
|
overlay.show();
|
|
73
72
|
}
|
|
@@ -75,7 +74,7 @@ function createClient(options) {
|
|
|
75
74
|
applyUpdateAsync();
|
|
76
75
|
}
|
|
77
76
|
};
|
|
78
|
-
const
|
|
77
|
+
const onOk = () => {
|
|
79
78
|
overlay.hide();
|
|
80
79
|
progress.hide();
|
|
81
80
|
applyUpdateAsync();
|
|
@@ -103,11 +102,11 @@ function createClient(options) {
|
|
|
103
102
|
case 'hash':
|
|
104
103
|
onHash(payload);
|
|
105
104
|
break;
|
|
106
|
-
case '
|
|
107
|
-
|
|
105
|
+
case 'issues':
|
|
106
|
+
onIssues(payload);
|
|
108
107
|
break;
|
|
109
108
|
case 'ok':
|
|
110
|
-
|
|
109
|
+
onOk();
|
|
111
110
|
break;
|
|
112
111
|
}
|
|
113
112
|
emit(action, payload, options);
|
package/client/esm/events.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.9.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
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
const events = {
|
|
14
14
|
ok: [],
|
|
15
15
|
hash: [],
|
|
16
|
+
issues: [],
|
|
16
17
|
invalid: [],
|
|
17
|
-
problems: [],
|
|
18
18
|
progress: []
|
|
19
19
|
};
|
|
20
20
|
/**
|
package/client/esm/hot.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.9.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/client/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.9.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/client/esm/main.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.
|
|
4
|
+
* @version 0.9.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
|
|
@@ -21,8 +21,8 @@ const getCurrentScript = () => {
|
|
|
21
21
|
return currentScript;
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
|
-
const
|
|
25
|
-
switch (params.get('
|
|
24
|
+
const getProtocol = (params, protocol) => {
|
|
25
|
+
switch (params.get('wss')) {
|
|
26
26
|
case 'true':
|
|
27
27
|
return 'wss:';
|
|
28
28
|
case 'false':
|
|
@@ -31,46 +31,27 @@ const resolveProtocol = (params, protocol) => {
|
|
|
31
31
|
return isTLS(protocol) ? 'wss:' : 'ws:';
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
-
const
|
|
34
|
+
const getOrigin = params => {
|
|
35
35
|
const { location } = self;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
protocol =
|
|
40
|
-
|
|
41
|
-
const script = getCurrentScript();
|
|
42
|
-
if (script) {
|
|
43
|
-
const { src } = script;
|
|
44
|
-
const url = new URL(src, location.href);
|
|
45
|
-
host = url.host;
|
|
46
|
-
protocol = resolveProtocol(params, url.protocol);
|
|
47
|
-
} else {
|
|
48
|
-
host = location.host;
|
|
49
|
-
protocol = resolveProtocol(params, location.protocol);
|
|
50
|
-
}
|
|
36
|
+
const script = getCurrentScript();
|
|
37
|
+
if (script) {
|
|
38
|
+
const url = new URL(script.src, location.href);
|
|
39
|
+
const protocol = getProtocol(params, url.protocol);
|
|
40
|
+
return `${protocol}//${url.host}`;
|
|
51
41
|
}
|
|
52
|
-
|
|
42
|
+
const protocol = getProtocol(params, location.protocol);
|
|
43
|
+
return `${protocol}//${location.host}`;
|
|
53
44
|
};
|
|
54
|
-
const
|
|
45
|
+
const getOptions = () => {
|
|
55
46
|
const params = new URLSearchParams(__resourceQuery);
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
origin,
|
|
66
|
-
overlay,
|
|
67
|
-
name: options.name,
|
|
68
|
-
path: options.path,
|
|
69
|
-
hmr: options.hmr === false ? false : hmr,
|
|
70
|
-
progress: options.progress === false ? false : progress
|
|
71
|
-
};
|
|
72
|
-
} catch (_a) {
|
|
73
|
-
throw new Error('Imported the hot client but the hot server is not enabled.');
|
|
74
|
-
}
|
|
47
|
+
return {
|
|
48
|
+
origin: getOrigin(params),
|
|
49
|
+
hmr: params.get('hmr') !== 'false',
|
|
50
|
+
path: params.get('path') || '/hot',
|
|
51
|
+
name: params.get('name') || 'webpack',
|
|
52
|
+
reload: params.get('reload') !== 'false',
|
|
53
|
+
overlay: params.get('overlay') !== 'false',
|
|
54
|
+
progress: params.get('progress') !== 'false'
|
|
55
|
+
};
|
|
75
56
|
};
|
|
76
|
-
createClient(
|
|
57
|
+
createClient(getOptions());
|