@best-shot/dev-server 0.13.1 → 0.13.2

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/server.mjs CHANGED
@@ -1,49 +1,11 @@
1
- import { createRequire } from 'module';
2
-
3
1
  import launchMiddleware from 'launch-editor-middleware';
4
2
  import WebpackDevServer from 'webpack-dev-server';
5
3
 
6
4
  import { notFound } from '../middleware/not-found/index.mjs';
5
+ import { staticFile } from '../middleware/static-file/index.mjs';
7
6
  import * as waitPage from '../middleware/wait-page/index.mjs';
8
7
 
9
- class BestShotDevServer extends WebpackDevServer {
10
- // https://github.com/webpack/webpack-dev-server/blob/79a169baa3eeaf71df068de5d9c6150684dfe35f/lib/Server.js#L1556
11
- setupHistoryApiFallbackFeature() {
12
- const { historyApiFallback } = this.options;
13
-
14
- if (
15
- typeof historyApiFallback.logger === 'undefined' &&
16
- !historyApiFallback.verbose
17
- ) {
18
- historyApiFallback.logger = this.logger.log.bind(
19
- this.logger,
20
- '[connect-history-api-fallback]',
21
- );
22
- }
23
-
24
- const {
25
- devMiddleware: {
26
- publicPath = this.compiler.options.output.publicPath,
27
- } = {},
28
- } = this.options;
29
-
30
- const requireLazy = createRequire(import.meta.url);
31
- const connectHistoryApiFallback = requireLazy(
32
- 'connect-history-api-fallback',
33
- );
34
-
35
- if (publicPath.startsWith('/')) {
36
- this.app.use(publicPath, connectHistoryApiFallback(historyApiFallback));
37
- } else {
38
- this.app.use(connectHistoryApiFallback(historyApiFallback));
39
- }
40
- }
41
- }
42
-
43
- export function DevServer(
44
- compiler,
45
- { onAfterSetupMiddleware, onBeforeSetupMiddleware, ...options },
46
- ) {
8
+ export function DevServer(compiler, { setupMiddlewares, ...options }) {
47
9
  waitPage.apply(compiler);
48
10
 
49
11
  process.env.WEBPACK_DEV_SERVER_BASE_PORT = 1234;
@@ -54,32 +16,50 @@ export function DevServer(
54
16
  if (options.hot === undefined) {
55
17
  options.hot = 'only';
56
18
  }
19
+
57
20
  if (options.static === undefined) {
58
21
  options.static = false;
59
22
  }
60
23
  /* eslint-enable no-param-reassign */
61
24
 
62
- const Server = new BestShotDevServer(
25
+ const Server = new WebpackDevServer(
63
26
  {
64
27
  ...options,
65
- onBeforeSetupMiddleware(server) {
28
+ setupMiddlewares(middlewares, devServer) {
66
29
  if (process.env.TERM_PROGRAM === 'vscode') {
67
- server.app.use('/__open-in-editor', launchMiddleware('code'));
68
- }
69
- if (typeof onBeforeSetupMiddleware === 'function') {
70
- onBeforeSetupMiddleware(server);
30
+ devServer.app.use('/__open-in-editor', launchMiddleware('code'));
71
31
  }
72
- server.app.use(waitPage.middleware(server));
73
- },
74
- onAfterSetupMiddleware(server) {
75
- if (typeof onAfterSetupMiddleware === 'function') {
76
- onAfterSetupMiddleware(server);
32
+
33
+ devServer.app.use(staticFile());
34
+
35
+ middlewares.unshift({
36
+ name: 'webpack-wait-page',
37
+ middleware: waitPage.middleware(devServer),
38
+ });
39
+
40
+ if (publicPath.startsWith('/')) {
41
+ const index = middlewares.findIndex(
42
+ ({ name }) => name === 'connect-history-api-fallback',
43
+ );
44
+
45
+ if (index > -1) {
46
+ // eslint-disable-next-line no-param-reassign
47
+ middlewares[index].path = publicPath;
48
+ }
77
49
  }
78
- server.app.use(
79
- notFound({
50
+
51
+ middlewares.push({
52
+ name: 'page-not-found',
53
+ middleware: notFound({
80
54
  publicPath: publicPath.startsWith('/') ? publicPath : '/',
81
55
  }),
82
- );
56
+ });
57
+
58
+ if (typeof setupMiddlewares === 'function') {
59
+ return setupMiddlewares(middlewares, devServer);
60
+ }
61
+
62
+ return middlewares;
83
63
  },
84
64
  },
85
65
  compiler,
@@ -21,8 +21,7 @@
21
21
  user-select: none;
22
22
  }
23
23
 
24
- img,
25
- h1 {
24
+ img {
26
25
  pointer-events: none;
27
26
  }
28
27
 
@@ -41,21 +40,23 @@
41
40
 
42
41
  .logo {
43
42
  margin-right: 4%;
44
- height: 48px;
45
- height: 10vw;
46
- height: clamp(32px, 10vw, 64px);
43
+ width: 44px;
44
+ width: 8vw;
45
+ width: clamp(32px, 8vw, 54px);
46
+ height: 44px;
47
+ height: 8vw;
48
+ height: clamp(32px, 8vw, 54px);
47
49
  }
48
50
 
49
51
  .not-found {
50
- width: 80%;
51
- max-width: 720px;
52
+ margin-bottom: 20vh;
53
+ width: 60%;
54
+ max-width: 400px;
52
55
  }
53
56
 
54
- .text {
55
- font-size: 44px;
56
- font-size: 8vw;
57
- font-size: clamp(32px, 8vw, 60px);
58
- line-height: 0.75;
57
+ header {
58
+ margin-bottom: 20vh;
59
+ text-align: right;
59
60
  }
60
61
 
61
62
  h1 {
@@ -65,11 +66,16 @@
65
66
  margin: 0;
66
67
  width: 100%;
67
68
  white-space: nowrap;
69
+ font-size: 44px;
70
+ font-size: 8vw;
71
+ font-size: clamp(32px, 8vw, 60px);
72
+ line-height: 1;
68
73
  }
69
74
 
70
75
  p {
71
76
  margin-top: 0.5em;
72
77
  margin-bottom: 0;
78
+ white-space: nowrap;
73
79
  font-size: 18px;
74
80
  font-size: 4vw;
75
81
  font-size: clamp(14px, 4vw, 22px);
@@ -89,11 +95,10 @@
89
95
  </style>
90
96
  </head>
91
97
  <body>
92
- <div style="flex: 3"></div>
93
- <div style="text-align: right">
98
+ <header>
94
99
  <h1>
95
100
  <img alt="logo" class="logo" src="/.best-shot/logo.svg" />
96
- <span class="text">BEST SHOT</span>
101
+ BEST SHOT
97
102
  </h1>
98
103
  <p>Page not found</p>
99
104
  [? if (publicPath) { ?]
@@ -104,10 +109,7 @@
104
109
  </a>
105
110
  </p>
106
111
  [? } ?]
107
- </div>
108
- <div style="flex: 2"></div>
112
+ </header>
109
113
  <img alt="404" class="not-found" src="/.best-shot/404.svg" />
110
-
111
- <div style="flex: 8"></div>
112
114
  </body>
113
115
  </html>
@@ -11,13 +11,6 @@ const router = Router({ strict: true });
11
11
 
12
12
  const __dirname = dirname(fileURLToPath(import.meta.url));
13
13
 
14
- router.get(
15
- '/.best-shot/:name(404.svg|logo.svg|logo.png)',
16
- ({ params: { name } }, res) => {
17
- res.sendFile(name, { root: __dirname });
18
- },
19
- );
20
-
21
14
  router.use(({ method, url }, res, next) => {
22
15
  if (method !== 'GET' || isRaw(url)) {
23
16
  res.status(404).type('text').end();
@@ -0,0 +1,31 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 219.289 55.546">
2
+ <path
3
+ fill="#eaebf2"
4
+ d="m216.823-.012-33.578 6.965 5.456 2.98Zm-14.399 17.011-9.176-4.677 23.58-12.335Z"
5
+ />
6
+ <path
7
+ fill="#ddddea"
8
+ d="m216.823-.012-28.122 9.945 3.254 7.599 1.293-5.206Z"
9
+ />
10
+ <path fill="#c2c2d3" d="m193.248 12.326-1.293 5.206 5.484-3.13Z" />
11
+ <path
12
+ fill="none"
13
+ stroke="#ddd"
14
+ stroke-dasharray="3 2 3 2"
15
+ stroke-linejoin="bevel"
16
+ stroke-miterlimit="10"
17
+ d="M.174 40.82a101.3 101.3 0 0 0 33.189 5.384c17.724-.348 40.835-7.472 53.346-10.947s20.852-5.56 35.1-5.56 38.228 7.124 37.186 15.813-10.6 7.993-12.511 1.911 5.213-8.862 5.213-8.862 23.458-7.646 36.317-16.855"
18
+ />
19
+ <path
20
+ fill="#3bf"
21
+ d="m100.029 46.782 12.269-28.607h3.77l-11.963 28.298h19.424v3.316h-23.5Zm16.516-13.237h3.493v22h-3.493Z"
22
+ />
23
+ <path
24
+ fill="#93f"
25
+ d="M85.231 55.546q-5.127 0-7.778-2.739t-2.649-7.641V28.554q0-4.926 2.664-7.653t7.766-2.727q5.127 0 7.778 2.714t2.651 7.665v16.613q0 4.926-2.664 7.653t-7.768 2.727Zm0-3.368q3.493 0 5.152-1.822a7.442 7.442 0 0 0 1.659-5.19V28.554a7.433 7.433 0 0 0-1.659-5.2q-1.659-1.81-5.152-1.81t-5.152 1.81a7.433 7.433 0 0 0-1.659 5.2v16.612a7.442 7.442 0 0 0 1.659 5.19q1.659 1.822 5.152 1.822Z"
26
+ />
27
+ <path
28
+ fill="#f46"
29
+ d="m46.843 46.782 12.269-28.607h3.77L50.919 46.473h19.424v3.316h-23.5Zm16.516-13.237h3.493v22h-3.493Z"
30
+ />
31
+ </svg>
@@ -0,0 +1,19 @@
1
+ import { dirname } from 'path';
2
+ import { fileURLToPath } from 'url';
3
+
4
+ import { Router } from 'express';
5
+
6
+ const router = Router({ strict: true });
7
+
8
+ export function staticFile() {
9
+ const __dirname = dirname(fileURLToPath(import.meta.url));
10
+
11
+ router.get(
12
+ '/.best-shot/:name(404.svg|logo.svg|logo.png)',
13
+ ({ params: { name } }, res) => {
14
+ res.sendFile(name, { root: __dirname });
15
+ },
16
+ );
17
+
18
+ return router;
19
+ }
File without changes
@@ -0,0 +1,5 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
2
+ <path fill="#3bf" d="m50 100-8.04-8.04L79.8 29.8 100 50z" />
3
+ <path fill="#93f" d="M23.57 73.57 0 50l16.6-16.59 41.07 2.62-34.1 37.54z" />
4
+ <path fill="#f46" d="M23.79 26.2 50 0l21.16 21.16z" />
5
+ </svg>
@@ -1,3 +1,5 @@
1
+ import { readFileSync } from 'fs';
2
+
1
3
  import webpackDevServerWaitpage from 'webpack-dev-server-waitpage';
2
4
 
3
5
  import { isRaw } from '../../lib/utils.mjs';
@@ -7,9 +9,13 @@ export function apply(compiler) {
7
9
  }
8
10
 
9
11
  export function middleware(server) {
10
- return webpackDevServerWaitpage(server, {
11
- title: 'Bundling...',
12
+ const template = readFileSync(
13
+ new URL('template.html', import.meta.url),
14
+ 'utf8',
15
+ );
12
16
 
17
+ return webpackDevServerWaitpage(server, {
18
+ template,
13
19
  ignore: (req) => isRaw(req.url),
14
20
  });
15
21
  }
@@ -0,0 +1,112 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta content="IE=edge" http-equiv="X-UA-Compatible" />
6
+ <meta content="webkit" name="renderer" />
7
+ <meta
8
+ content="width=device-width,initial-scale=1,user-scalable=no,shrink-to-fit=no,viewport-fit=cover"
9
+ name="viewport"
10
+ />
11
+ <meta content="1" http-equiv="refresh" />
12
+ <title>Bundling...</title>
13
+ <link href="/.best-shot/logo.png" rel="shortcut icon" type="image/png" />
14
+ <style>
15
+ html {
16
+ min-width: 300px;
17
+ height: 100%;
18
+ min-height: 300px;
19
+ -webkit-user-select: none;
20
+ -moz-user-select: none;
21
+ -ms-user-select: none;
22
+ user-select: none;
23
+ }
24
+
25
+ img {
26
+ pointer-events: none;
27
+ }
28
+
29
+ body {
30
+ display: flex;
31
+ flex-direction: column;
32
+ align-items: center;
33
+ justify-content: center;
34
+ margin: 0;
35
+ background-color: white;
36
+ height: 100%;
37
+ color: #999999;
38
+ font-family: -apple-system, BlinkMacSystemFont, roboto, 'Segoe UI',
39
+ Segoe, Helvetica, Arial, monospace;
40
+ }
41
+
42
+ .logo {
43
+ margin-right: 4%;
44
+ width: 44px;
45
+ width: 8vw;
46
+ width: clamp(32px, 8vw, 54px);
47
+ height: 44px;
48
+ height: 8vw;
49
+ height: clamp(32px, 8vw, 54px);
50
+ }
51
+
52
+ header {
53
+ margin-bottom: 20vh;
54
+ text-align: right;
55
+ }
56
+
57
+ h1 {
58
+ display: flex;
59
+ align-items: center;
60
+ justify-content: center;
61
+ margin: 0;
62
+ width: 100%;
63
+ white-space: nowrap;
64
+ font-size: 44px;
65
+ font-size: 8vw;
66
+ font-size: clamp(32px, 8vw, 60px);
67
+ line-height: 1;
68
+ }
69
+
70
+ p {
71
+ margin-top: 0.5em;
72
+ margin-bottom: 0;
73
+ white-space: nowrap;
74
+ font-size: 18px;
75
+ font-size: 4vw;
76
+ font-size: clamp(14px, 4vw, 22px);
77
+ }
78
+
79
+ progress {
80
+ margin-top: 10px;
81
+ width: 60%;
82
+ height: 24px;
83
+ }
84
+
85
+ @media (prefers-color-scheme: dark) {
86
+ body {
87
+ background-color: #222222;
88
+ }
89
+ }
90
+ </style>
91
+ </head>
92
+ <body>
93
+ <header>
94
+ <h1>
95
+ <img alt="logo" class="logo" src="/.best-shot/logo.svg" />
96
+ BEST SHOT
97
+ </h1>
98
+ <p>Bundling...</p>
99
+ </header>
100
+
101
+ &#x3C;% for (var i = 0 ; i &#x3C; progress.length ; i++) { var percent =
102
+ Math.round(100 * progress[i][0]); %> &#x3C;%= percent %> %
103
+ <progress max="100" value="<%= percent %>"></progress>
104
+
105
+ <p class="message">&#x3C;%= progress[i][1] || '' %></p>
106
+ <p class="modules">&#x3C;%= progress[i][2] || '' %></p>
107
+ <p class="active">&#x3C;%= progress[i][3] || '' %></p>
108
+ &#x3C;% for (var m = 4 ; m &#x3C; progress[i].length; m++) { %>
109
+ <p class="last">&#x3C;%= progress[i][m] || '' %></p>
110
+ &#x3C;% } %> &#x3C;% } %>
111
+ </body>
112
+ </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@best-shot/dev-server",
3
- "version": "0.13.1",
3
+ "version": "0.13.2",
4
4
  "description": "DevServer support of `@best-shot/cli`",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -31,18 +31,18 @@
31
31
  },
32
32
  "main": "index.mjs",
33
33
  "dependencies": {
34
- "@best-shot/config": "^0.2.4",
34
+ "@best-shot/config": "^0.2.8",
35
35
  "chalk": "^4.1.2",
36
36
  "connect-history-api-fallback": "^1.6.0",
37
37
  "ejs": "^3.1.6",
38
38
  "express": "^4.17.2",
39
- "launch-editor-middleware": "^2.2.1",
39
+ "launch-editor-middleware": "^2.3.0",
40
40
  "lodash": "^4.17.21",
41
- "webpack-dev-server": "^4.6.0",
41
+ "webpack-dev-server": "^4.7.3",
42
42
  "webpack-dev-server-waitpage": "^2.1.1"
43
43
  },
44
44
  "peerDependencies": {
45
- "@best-shot/cli": "^0.12.2"
45
+ "@best-shot/cli": "^0.12.3"
46
46
  },
47
47
  "engines": {
48
48
  "node": "^14.17.0 || >=16.13.0"
@@ -1,72 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 361.29 118.5">
2
- <defs>
3
- <linearGradient
4
- id="a"
5
- x1=".49"
6
- x2=".49"
7
- y1="1"
8
- y2="-.23"
9
- gradientUnits="objectBoundingBox"
10
- >
11
- <stop offset="0" stop-color="#fff" stop-opacity="0" />
12
- <stop offset=".5" stop-color="#f3f3f3" stop-opacity=".125" />
13
- <stop offset="1" stop-color="#aa9" stop-opacity=".75" />
14
- </linearGradient>
15
- </defs>
16
- <path
17
- fill="url(#a)"
18
- d="M219.14-365.3h-361.28c6.71-8.48 16.14-16.43 28.01-23.63a203.46 203.46 0 0141.4-18.57 316.21 316.21 0 0151.86-12.15A398.76 398.76 0 0138.5-424a398.76 398.76 0 0159.37 4.35 316.21 316.21 0 0151.85 12.15 203.46 203.46 0 0141.4 18.57c11.88 7.2 21.3 15.15 28.02 23.63z"
19
- opacity=".5"
20
- transform="translate(142.14 483.8)"
21
- />
22
- <path fill="#ddd" d="M180.9 80.1l-43.3 14.4V46.6l43.3-9.6z" />
23
- <path fill="#eee" d="M180.9 80.1L224 94.5V46.6L180.9 37z" />
24
- <path
25
- fill="#aaa"
26
- d="M180.55 81.6q-10.18 0-15.27-4.72t-5.08-12.75V36.58q0-8.19 5.14-12.83t15.2-4.64q10.13 0 15.24 4.61t5.12 12.86v27.55q0 8.19-5.15 12.83t-15.2 4.64zm0-8.49q5.26 0 7.6-2.4a9.02 9.02 0 002.34-6.58V36.58a9 9 0 00-2.34-6.62q-2.34-2.37-7.6-2.37t-7.6 2.37a9 9 0 00-2.34 6.61v27.56a9.02 9.02 0 002.33 6.59q2.35 2.4 7.6 2.4z"
27
- />
28
- <path fill="#bbb" d="M180.9 108.9l-43.3-14.4V46.6l43.3 14.3z" />
29
- <path fill="#f2f3f8" d="M171.3 80.1L128 65.7l9.6-19.1 43.3 14.3z" />
30
- <path
31
- fill="#aaa"
32
- d="M79 82.1l23.5-43.2h10.1L89.7 81.6H124v7.8H79v-7.3zm30.2-18.6h9.6v35.1h-9.6V63.5z"
33
- />
34
- <path
35
- fill="#aaa"
36
- d="M236.3 82.1l23.5-43.2h10.1L247 81.6h34.4v7.8h-45v-7.3zm30.2-18.6h9.6v35.1h-9.6z"
37
- />
38
- <path
39
- fill="#999"
40
- d="M148.3 83.4l-.1 1.5-4-1.4-.1 1.5 3.9 1.4v1.5l-4-1.4V88l4 1.4v1.5l-5.7-1.9.3-7.5z"
41
- />
42
- <path
43
- fill="#999"
44
- d="M153.9 90l1 3.2-1.8-.6-1-3.2-1.7-.6-.1 2.8-1.6-.6.2-7.5 5.2 1.8a1.17 1.17 0 01.6.6 1.65 1.65 0 01.2 1l-.2 3.5zm-3.4-2.6l2.8 1 .1-1.7-2.8-1-.1 1.7"
45
- />
46
- <path
47
- fill="#999"
48
- d="M161 92.5l1 3.2-1.8-.6-1-3.2-1.7-.6-.1 2.8-1.6-.6.2-7.5 5.2 1.8a1.17 1.17 0 01.6.6 1.65 1.65 0 01.2 1l-.2 3.5zm-3.4-2.7l2.8 1 .1-1.7-2.8-1-.1 1.7"
49
- />
50
- <path
51
- fill="#999"
52
- d="M169.2 91.8l-.2 6.3-6.1-2.1.2-7.5 5.2 1.8a1.17 1.17 0 01.6.6.76.76 0 01.3.9zm-4.6 3.3l2.8 1 .2-4.5-2.8-1-.2 4.5"
53
- />
54
- <path
55
- fill="#999"
56
- d="M175.1 97.2l1 3.2-1.8-.6-1-3.2-1.7-.6-.1 2.8-1.6-.6.2-7.5 5.2 1.8a1.17 1.17 0 01.6.6 1.65 1.65 0 01.2 1l-.2 3.5zm-3.4-2.6l2.8 1 .1-1.7-2.8-1-.1 1.7"
57
- />
58
- <path fill="#ddd" d="M180.9 108.9L224 94.5V46.6l-43.1 14.3z" />
59
- <path fill="#fafafa" d="M190.5 80.1l43.1-14.4-9.6-19.1-43.1 14.3z" />
60
- <path fill="#eaebf2" d="M288.24 0l-34.6 1.1 4.9 4.2z" />
61
- <path fill="#eaebf2" d="M270.94 15.4l-8.3-6.7 25.6-8.7z" />
62
- <path fill="#ddddea" d="M288.24 0l-29.7 5.3 1.9 8.7 2.2-5.3z" />
63
- <path fill="#c2c2d3" d="M262.64 8.7l-2.2 5.3 6-2.3z" />
64
- <path
65
- fill="none"
66
- stroke="#ddd"
67
- stroke-dasharray="2 2 2 2"
68
- stroke-linecap="round"
69
- stroke-miterlimit="10"
70
- d="M233.64 15.7s-5.8 17.9-17.5 13.7a3.1 3.1 0 01.9-6c2.9-.2 7.3.1 13.7 1 23.1 3.3 26.7-7.4 26.7-7.4"
71
- />
72
- </svg>
@@ -1,5 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
2
- <path fill="#3bf" d="M50 100l-8.04-8.04L79.8 29.8 100 50z" />
3
- <path fill="#93f" d="M23.57 73.57L0 50l16.6-16.59 41.07 2.62-34.1 37.54z" />
4
- <path fill="#f46" d="M23.79 26.2L50 0l21.16 21.16z" />
5
- </svg>