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.
Files changed (91) hide show
  1. package/README.md +26 -36
  2. package/client/cjs/client.cjs +14 -15
  3. package/client/cjs/events.cjs +2 -2
  4. package/client/cjs/hot.cjs +1 -1
  5. package/client/cjs/index.cjs +1 -1
  6. package/client/cjs/main.cjs +22 -41
  7. package/client/cjs/ui/overlay.cjs +7 -7
  8. package/client/cjs/ui/progress.cjs +1 -1
  9. package/client/cjs/ui/utils.cjs +1 -1
  10. package/client/esm/client.js +14 -15
  11. package/client/esm/events.js +2 -2
  12. package/client/esm/hot.js +1 -1
  13. package/client/esm/index.js +1 -1
  14. package/client/esm/main.js +22 -41
  15. package/client/esm/ui/overlay.js +7 -7
  16. package/client/esm/ui/progress.js +1 -1
  17. package/client/esm/ui/utils.js +1 -1
  18. package/package.json +12 -8
  19. package/server/cjs/{dev/utils/compose.cjs → compose.cjs} +8 -10
  20. package/server/cjs/dev/Service.cjs +269 -0
  21. package/server/cjs/dev/index.cjs +9 -11
  22. package/server/cjs/dev/middleware.cjs +54 -28
  23. package/server/cjs/dev/utils/fs.cjs +29 -0
  24. package/server/cjs/dev/utils/{boundary.cjs → hash.cjs} +14 -10
  25. package/server/cjs/dev/utils/http.cjs +168 -10
  26. package/server/cjs/dev/utils/path.cjs +46 -0
  27. package/server/cjs/dev/utils/paths.cjs +59 -0
  28. package/server/cjs/dev/utils/ready.cjs +6 -9
  29. package/server/cjs/dev/utils/setupHooks.cjs +51 -40
  30. package/server/cjs/dev/utils/setupOutputFileSystem.cjs +6 -39
  31. package/server/cjs/dev/utils/setupWatching.cjs +3 -3
  32. package/server/cjs/dev/utils/setupWriteToDisk.cjs +23 -31
  33. package/server/cjs/hot/Socket.cjs +88 -111
  34. package/server/cjs/hot/index.cjs +13 -15
  35. package/server/cjs/hot/utils.cjs +100 -0
  36. package/server/cjs/index.cjs +17 -7
  37. package/server/cjs/schema.cjs +127 -0
  38. package/server/cjs/utils.cjs +45 -0
  39. package/server/esm/{dev/utils/compose.js → compose.js} +8 -10
  40. package/server/esm/dev/Service.js +260 -0
  41. package/server/esm/dev/index.js +8 -10
  42. package/server/esm/dev/middleware.js +53 -27
  43. package/server/esm/dev/utils/fs.js +27 -0
  44. package/server/esm/dev/utils/{boundary.js → hash.js} +14 -10
  45. package/server/esm/dev/utils/http.js +159 -8
  46. package/server/esm/dev/utils/path.js +42 -0
  47. package/server/esm/dev/utils/paths.js +57 -0
  48. package/server/esm/dev/utils/ready.js +6 -9
  49. package/server/esm/dev/utils/setupHooks.js +46 -35
  50. package/server/esm/dev/utils/setupOutputFileSystem.js +5 -38
  51. package/server/esm/dev/utils/setupWatching.js +2 -2
  52. package/server/esm/dev/utils/setupWriteToDisk.js +22 -30
  53. package/server/esm/hot/Socket.js +87 -110
  54. package/server/esm/hot/index.js +13 -15
  55. package/server/esm/hot/utils.js +93 -0
  56. package/server/esm/index.js +17 -7
  57. package/server/esm/schema.js +125 -0
  58. package/server/esm/utils.js +37 -0
  59. package/types/client/client.d.ts +1 -1
  60. package/types/client/events.d.ts +6 -6
  61. package/types/client/message.d.ts +6 -5
  62. package/types/client/ui/overlay.d.ts +1 -1
  63. package/types/server/dev/Service.d.ts +82 -0
  64. package/types/server/dev/index.d.ts +4 -4
  65. package/types/server/dev/interface.d.ts +26 -34
  66. package/types/server/dev/utils/fs.d.ts +27 -0
  67. package/types/server/dev/utils/hash.d.ts +9 -0
  68. package/types/server/dev/utils/http.d.ts +31 -14
  69. package/types/server/dev/utils/path.d.ts +22 -0
  70. package/types/server/dev/utils/paths.d.ts +7 -0
  71. package/types/server/dev/utils/ready.d.ts +2 -2
  72. package/types/server/hot/Socket.d.ts +6 -10
  73. package/types/server/hot/index.d.ts +4 -9
  74. package/types/server/hot/interface.d.ts +20 -0
  75. package/types/server/hot/utils.d.ts +13 -0
  76. package/types/server/index.d.ts +8 -8
  77. package/types/server/interface.d.ts +9 -0
  78. package/types/server/schema.d.ts +7 -0
  79. package/types/server/utils.d.ts +12 -0
  80. package/global.d.ts +0 -16
  81. package/server/cjs/dev/Files.cjs +0 -394
  82. package/server/cjs/dev/utils/common.cjs +0 -98
  83. package/server/cjs/dev/utils/getPaths.cjs +0 -65
  84. package/server/esm/dev/Files.js +0 -384
  85. package/server/esm/dev/utils/common.js +0 -98
  86. package/server/esm/dev/utils/getPaths.js +0 -63
  87. package/types/server/dev/Files.d.ts +0 -83
  88. package/types/server/dev/utils/boundary.d.ts +0 -8
  89. package/types/server/dev/utils/common.d.ts +0 -44
  90. package/types/server/dev/utils/getPaths.d.ts +0 -10
  91. /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
- ```js
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/logo.svg'),
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: /\.jsx?$/i,
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
- index: false,
173
- outputFileSystem: fs,
161
+ fs,
174
162
  headers: {
175
- 'Cache-Control': 'no-store',
176
- 'Access-Control-Allow-Origin': '*',
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 => {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.8.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 = error => {
27
- if (options.live) {
26
+ const fallback = () => {
27
+ if (options.reload) {
28
28
  self.location.reload();
29
- } else if (error) {
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 setProblems = (type, problems) => {
53
+ const setIssues = (type, issues) => {
55
54
  if (options.overlay) {
56
- overlay$1.setProblems(type, problems);
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 problems) {
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 onProblems = ({ errors, warnings }) => {
68
+ const onIssues = ({ errors, warnings }) => {
70
69
  progress$1.hide();
71
- setProblems('errors', errors);
72
- setProblems('warnings', warnings);
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 onSuccess = () => {
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 'problems':
109
- onProblems(payload);
107
+ case 'issues':
108
+ onIssues(payload);
110
109
  break;
111
110
  case 'ok':
112
- onSuccess();
111
+ onOk();
113
112
  break;
114
113
  }
115
114
  events.emit(action, payload, options);
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.8.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
  /**
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.8.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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.8.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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.8.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 resolveProtocol = (params, protocol) => {
27
- switch (params.get('tls')) {
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 resolveOrigin = params => {
36
+ const getOrigin = params => {
37
37
  const { location } = self;
38
- let host = params.get('host');
39
- let protocol;
40
- if (host) {
41
- protocol = resolveProtocol(params, location.protocol);
42
- } else {
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
- return `${protocol}//${host}`;
44
+ const protocol = getProtocol(params, location.protocol);
45
+ return `${protocol}//${location.host}`;
55
46
  };
56
- const resolveOptions = () => {
47
+ const getOptions = () => {
57
48
  const params = new URLSearchParams(__resourceQuery);
58
- const origin = resolveOrigin(params);
59
- const hmr = params.get('hmr') !== 'false';
60
- const live = params.get('live') !== 'false';
61
- const overlay = params.get('overlay') !== 'false';
62
- const progress = params.get('progress') !== 'false';
63
- try {
64
- const options = __WDS_HOT_OPTIONS__;
65
- return {
66
- live,
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(resolveOptions());
59
+ client(getOptions());
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.8.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}-problems {
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}-problems::-webkit-scrollbar {
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}-problems">
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
- setProblems(type, problems) {
196
- const count = problems.length;
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 problems) {
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.8.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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.8.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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.8.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 = error => {
25
- if (options.live) {
24
+ const fallback = () => {
25
+ if (options.reload) {
26
26
  self.location.reload();
27
- } else if (error) {
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 setProblems = (type, problems) => {
51
+ const setIssues = (type, issues) => {
53
52
  if (options.overlay) {
54
- overlay.setProblems(type, problems);
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 problems) {
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 onProblems = ({ errors, warnings }) => {
66
+ const onIssues = ({ errors, warnings }) => {
68
67
  progress.hide();
69
- setProblems('errors', errors);
70
- setProblems('warnings', warnings);
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 onSuccess = () => {
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 'problems':
107
- onProblems(payload);
105
+ case 'issues':
106
+ onIssues(payload);
108
107
  break;
109
108
  case 'ok':
110
- onSuccess();
109
+ onOk();
111
110
  break;
112
111
  }
113
112
  emit(action, payload, options);
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.8.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.8.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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.8.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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.8.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 resolveProtocol = (params, protocol) => {
25
- switch (params.get('tls')) {
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 resolveOrigin = params => {
34
+ const getOrigin = params => {
35
35
  const { location } = self;
36
- let host = params.get('host');
37
- let protocol;
38
- if (host) {
39
- protocol = resolveProtocol(params, location.protocol);
40
- } else {
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
- return `${protocol}//${host}`;
42
+ const protocol = getProtocol(params, location.protocol);
43
+ return `${protocol}//${location.host}`;
53
44
  };
54
- const resolveOptions = () => {
45
+ const getOptions = () => {
55
46
  const params = new URLSearchParams(__resourceQuery);
56
- const origin = resolveOrigin(params);
57
- const hmr = params.get('hmr') !== 'false';
58
- const live = params.get('live') !== 'false';
59
- const overlay = params.get('overlay') !== 'false';
60
- const progress = params.get('progress') !== 'false';
61
- try {
62
- const options = __WDS_HOT_OPTIONS__;
63
- return {
64
- live,
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(resolveOptions());
57
+ createClient(getOptions());