@best-shot/dev-server 0.16.0 → 0.17.1
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 +5 -1
- package/lib/server.mjs +50 -53
- package/package.json +2 -2
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(
|
|
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,71 @@ 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
|
|
9
|
-
|
|
8
|
+
export class DevServer extends WebpackDevServer {
|
|
9
|
+
constructor(options, compiler) {
|
|
10
|
+
waitPage.apply(compiler);
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
const publicPath = options.publicPath ?? compiler.options.output.publicPath;
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
/* eslint-disable no-param-reassign */
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
options.proxy &&= (
|
|
17
|
+
Array.isArray(options.proxy) ? options.proxy : [options.proxy]
|
|
18
|
+
).map((item) => ({
|
|
19
|
+
changeOrigin: true,
|
|
20
|
+
secure: false,
|
|
21
|
+
...item,
|
|
22
|
+
}));
|
|
16
23
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
options.hot ??= 'only';
|
|
25
|
+
options.static ??= false;
|
|
26
|
+
options.allowedHosts ??= ['all'];
|
|
20
27
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
item.changeOrigin ??= true;
|
|
25
|
-
item.secure ??= false;
|
|
26
|
-
}
|
|
28
|
+
if (options.port === 443) {
|
|
29
|
+
options.server ??= {};
|
|
30
|
+
options.server.type ??= 'https';
|
|
27
31
|
}
|
|
28
|
-
}
|
|
29
32
|
|
|
30
|
-
|
|
33
|
+
/* eslint-enable no-param-reassign */
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
super(
|
|
36
|
+
{
|
|
37
|
+
...options,
|
|
38
|
+
setupMiddlewares(middlewares, devServer) {
|
|
39
|
+
if (process.env.TERM_PROGRAM === 'vscode') {
|
|
40
|
+
devServer.app.use('/__open-in-editor', launchMiddleware('code'));
|
|
41
|
+
}
|
|
39
42
|
|
|
40
|
-
|
|
43
|
+
devServer.app.use(staticFile());
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
name: 'webpack-wait-page',
|
|
44
|
-
middleware: waitPage.middleware(devServer),
|
|
45
|
-
});
|
|
45
|
+
devServer.app.use(waitPage.middleware(devServer));
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
if (publicPath.startsWith('/')) {
|
|
48
|
+
const index = middlewares.findIndex(
|
|
49
|
+
({ name }) => name === 'connect-history-api-fallback',
|
|
50
|
+
);
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
if (index > -1) {
|
|
53
|
+
// eslint-disable-next-line no-param-reassign
|
|
54
|
+
middlewares[index].path = publicPath;
|
|
55
|
+
}
|
|
55
56
|
}
|
|
56
|
-
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
middlewares.push({
|
|
59
|
+
name: 'page-not-found',
|
|
60
|
+
middleware: notFound({
|
|
61
|
+
publicPath: publicPath.startsWith('/') ? publicPath : '/',
|
|
62
|
+
}),
|
|
63
|
+
});
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
if (typeof options.setupMiddlewares === 'function') {
|
|
66
|
+
options.setupMiddlewares(middlewares, devServer);
|
|
67
|
+
}
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
return middlewares;
|
|
70
|
+
},
|
|
70
71
|
},
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
Server.start();
|
|
76
|
-
|
|
77
|
-
return Server;
|
|
72
|
+
compiler,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
78
75
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@best-shot/dev-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.1",
|
|
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": "^
|
|
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
|
},
|