@best-shot/dev-server 0.16.0 → 0.17.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/lib/action.mjs CHANGED
@@ -73,9 +73,13 @@ export function action({ _: [command] }) {
73
73
  if (shouldServe.length > 0) {
74
74
  const { DevServer } = await import('./server.mjs');
75
75
 
76
+ process.env.WEBPACK_DEV_SERVER_BASE_PORT = 1234;
77
+
76
78
  shouldServe.forEach((config) => {
77
79
  const compiler = createCompiler(config);
78
- DevServer(compiler, config.devServer);
80
+ const instance = new DevServer(config.devServer, compiler);
81
+
82
+ instance.start();
79
83
  });
80
84
  }
81
85
  });
package/lib/server.mjs CHANGED
@@ -5,74 +5,64 @@ import { notFound } from '../middleware/not-found/index.mjs';
5
5
  import { staticFile } from '../middleware/static-file/index.mjs';
6
6
  import * as waitPage from '../middleware/wait-page/index.mjs';
7
7
 
8
- export function DevServer(compiler, { setupMiddlewares, ...options }) {
9
- waitPage.apply(compiler);
8
+ export class DevServer extends WebpackDevServer {
9
+ constructor(options, compiler) {
10
+ waitPage.apply(compiler);
10
11
 
11
- process.env.WEBPACK_DEV_SERVER_BASE_PORT = 1234;
12
+ const publicPath = options.publicPath ?? compiler.options.output.publicPath;
12
13
 
13
- const publicPath = options.publicPath || compiler.options.output.publicPath;
14
+ /* eslint-disable no-param-reassign */
14
15
 
15
- /* eslint-disable no-param-reassign */
16
+ options.proxy &&= options.proxy.map((item) => ({
17
+ changeOrigin: true,
18
+ secure: false,
19
+ ...item,
20
+ }));
16
21
 
17
- options.hot ??= 'only';
18
- options.static ??= false;
19
- options.allowedHosts ??= ['all'];
22
+ options.hot ??= 'only';
23
+ options.static ??= false;
24
+ options.allowedHosts ??= ['all'];
20
25
 
21
- if (options.proxy !== undefined) {
22
- for (const item of Object.values(options.proxy)) {
23
- if (item) {
24
- item.changeOrigin ??= true;
25
- item.secure ??= false;
26
- }
27
- }
28
- }
29
-
30
- /* eslint-enable no-param-reassign */
26
+ /* eslint-enable no-param-reassign */
31
27
 
32
- const Server = new WebpackDevServer(
33
- {
34
- ...options,
35
- setupMiddlewares(middlewares, devServer) {
36
- if (process.env.TERM_PROGRAM === 'vscode') {
37
- devServer.app.use('/__open-in-editor', launchMiddleware('code'));
38
- }
28
+ super(
29
+ {
30
+ ...options,
31
+ setupMiddlewares(middlewares, devServer) {
32
+ if (process.env.TERM_PROGRAM === 'vscode') {
33
+ devServer.app.use('/__open-in-editor', launchMiddleware('code'));
34
+ }
39
35
 
40
- devServer.app.use(staticFile());
36
+ devServer.app.use(staticFile());
41
37
 
42
- middlewares.unshift({
43
- name: 'webpack-wait-page',
44
- middleware: waitPage.middleware(devServer),
45
- });
38
+ devServer.app.use(waitPage.middleware(devServer));
46
39
 
47
- if (publicPath.startsWith('/')) {
48
- const index = middlewares.findIndex(
49
- ({ name }) => name === 'connect-history-api-fallback',
50
- );
40
+ if (publicPath.startsWith('/')) {
41
+ const index = middlewares.findIndex(
42
+ ({ name }) => name === 'connect-history-api-fallback',
43
+ );
51
44
 
52
- if (index > -1) {
53
- // eslint-disable-next-line no-param-reassign
54
- middlewares[index].path = publicPath;
45
+ if (index > -1) {
46
+ // eslint-disable-next-line no-param-reassign
47
+ middlewares[index].path = publicPath;
48
+ }
55
49
  }
56
- }
57
50
 
58
- middlewares.push({
59
- name: 'page-not-found',
60
- middleware: notFound({
61
- publicPath: publicPath.startsWith('/') ? publicPath : '/',
62
- }),
63
- });
51
+ middlewares.push({
52
+ name: 'page-not-found',
53
+ middleware: notFound({
54
+ publicPath: publicPath.startsWith('/') ? publicPath : '/',
55
+ }),
56
+ });
64
57
 
65
- if (typeof setupMiddlewares === 'function') {
66
- return setupMiddlewares(middlewares, devServer);
67
- }
58
+ if (typeof options.setupMiddlewares === 'function') {
59
+ options.setupMiddlewares(middlewares, devServer);
60
+ }
68
61
 
69
- return middlewares;
62
+ return middlewares;
63
+ },
70
64
  },
71
- },
72
- compiler,
73
- );
74
-
75
- Server.start();
76
-
77
- return Server;
65
+ compiler,
66
+ );
67
+ }
78
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@best-shot/dev-server",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "DevServer support of `@best-shot/cli`",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -36,7 +36,7 @@
36
36
  "ejs": "^3.1.9",
37
37
  "express": "^4.18.2",
38
38
  "launch-editor-middleware": "^2.6.1",
39
- "webpack-dev-server": "^4.15.1",
39
+ "webpack-dev-server": "^5.0.2",
40
40
  "webpack-dev-server-waitpage": "^2.1.1",
41
41
  "@best-shot/config": "^0.5.0"
42
42
  },