@modern-js/server 0.0.0-bundle-deps-2021101244657 → 0.0.0-plugins-202111301002
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/CHANGELOG.md +24 -11
- package/dist/js/modern/dev-tools/babel/register.js +1 -1
- package/dist/js/modern/dev-tools/dev-server-plugin.js +2 -2
- package/dist/js/modern/libs/render/cache/type.js +0 -1
- package/dist/js/modern/libs/route/matcher.js +1 -1
- package/dist/js/modern/libs/serve-file.js +23 -25
- package/dist/js/modern/server/dev-server.js +1 -1
- package/dist/js/modern/server/index.js +26 -10
- package/dist/js/modern/server/modern-server.js +42 -10
- package/dist/js/modern/type.js +0 -1
- package/dist/js/node/dev-tools/babel/register.js +1 -1
- package/dist/js/node/dev-tools/dev-server-plugin.js +2 -2
- package/dist/js/node/libs/route/matcher.js +1 -1
- package/dist/js/node/libs/serve-file.js +25 -26
- package/dist/js/node/server/dev-server.js +1 -1
- package/dist/js/node/server/index.js +31 -19
- package/dist/js/node/server/modern-server.js +42 -10
- package/dist/types/dev-tools/dev-server-plugin.d.ts +1 -1
- package/dist/types/dev-tools/socket-server.d.ts +1 -1
- package/dist/types/libs/serve-file.d.ts +1 -1
- package/dist/types/server/modern-server.d.ts +1 -0
- package/dist/types/type.d.ts +1 -1
- package/package.json +31 -21
- package/src/dev-tools/babel/register.ts +1 -1
- package/src/dev-tools/dev-server-plugin.ts +2 -4
- package/src/dev-tools/socket-server.ts +1 -1
- package/src/libs/route/matcher.ts +1 -1
- package/src/libs/serve-file.ts +16 -20
- package/src/server/dev-server.ts +2 -2
- package/src/server/index.ts +8 -9
- package/src/server/modern-server.ts +39 -8
- package/src/type.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
# @modern-js/server
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 1.1.2
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
- @modern-js/
|
|
15
|
-
- @modern-js/
|
|
16
|
-
- @modern-js/utils@
|
|
7
|
+
- 0fa83663: support more .env files
|
|
8
|
+
- f594fbc8: fix apple icon and favicon support
|
|
9
|
+
- d1fde77a: fix public/ file in windows
|
|
10
|
+
- Updated dependencies [6f7fe574]
|
|
11
|
+
- Updated dependencies [b011e0c5]
|
|
12
|
+
- Updated dependencies [0fa83663]
|
|
13
|
+
- Updated dependencies [f594fbc8]
|
|
14
|
+
- @modern-js/core@1.1.2
|
|
15
|
+
- @modern-js/server-utils@1.1.1
|
|
16
|
+
- @modern-js/bff-utils@1.1.1
|
|
17
|
+
- @modern-js/hmr-client@1.1.1
|
|
18
|
+
- @modern-js/server-plugin@1.1.1
|
|
19
|
+
- @modern-js/utils@1.1.2
|
|
20
|
+
|
|
21
|
+
## 1.1.1
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- c0fc0700: feat: support deploy plugin
|
|
26
|
+
- Updated dependencies [687c92c7]
|
|
27
|
+
- Updated dependencies [c0fc0700]
|
|
28
|
+
- @modern-js/core@1.1.1
|
|
29
|
+
- @modern-js/utils@1.1.1
|
|
17
30
|
|
|
18
31
|
## 1.1.0
|
|
19
32
|
|
|
@@ -15,7 +15,7 @@ export const enableRegister = (projectRoot, config) => {
|
|
|
15
15
|
syntax: 'es6+',
|
|
16
16
|
type: 'commonjs'
|
|
17
17
|
});
|
|
18
|
-
return require('@
|
|
18
|
+
return require('@babel/register')(_objectSpread(_objectSpread({}, babelConfig), {}, {
|
|
19
19
|
only: [function (filePath) {
|
|
20
20
|
// TODO: wait params
|
|
21
21
|
if (filePath.includes(`node_modules${path.sep}.modern-js`)) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Webpack from '
|
|
1
|
+
import Webpack from 'webpack';
|
|
2
2
|
const {
|
|
3
3
|
EntryPlugin
|
|
4
4
|
} = Webpack;
|
|
@@ -18,7 +18,7 @@ export default class DevServerPlugin {
|
|
|
18
18
|
|
|
19
19
|
const clientEntry = `${require.resolve('@modern-js/hmr-client')}?${host}${path}${port}`;
|
|
20
20
|
|
|
21
|
-
const hotEntry = require.resolve('
|
|
21
|
+
const hotEntry = require.resolve('webpack/hot/dev-server');
|
|
22
22
|
|
|
23
23
|
const additionalEntries = [clientEntry, hotEntry]; // use a hook to add entries if available
|
|
24
24
|
|
|
@@ -2,7 +2,7 @@ import { removeTailSlash } from '@modern-js/utils';
|
|
|
2
2
|
import { match, pathToRegexp } from 'path-to-regexp';
|
|
3
3
|
import { ModernRoute } from "./route"; // eslint-disable-next-line no-useless-escape
|
|
4
4
|
|
|
5
|
-
const regCharsDetector = /[^a-zA-Z\-_0-9
|
|
5
|
+
const regCharsDetector = /[^a-zA-Z\-_0-9\/\.]/;
|
|
6
6
|
export class RouteMatcher {
|
|
7
7
|
constructor(spec) {
|
|
8
8
|
this.spec = void 0;
|
|
@@ -1,30 +1,28 @@
|
|
|
1
1
|
// Todo 看看是不是能 fork 一份,即使命中也返回
|
|
2
2
|
import serve from 'serve-static';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import { isString, isRegExp } from '@modern-js/utils';
|
|
4
|
+
export const createStaticFileHandler = rules => // eslint-disable-next-line consistent-return
|
|
5
|
+
async (context, next) => {
|
|
6
|
+
const {
|
|
7
|
+
url: requestUrl,
|
|
8
|
+
req,
|
|
9
|
+
res
|
|
10
|
+
} = context;
|
|
11
|
+
const hitRule = rules.find(item => {
|
|
12
|
+
if (isString(item.path) && requestUrl.startsWith(item.path)) {
|
|
13
|
+
return true;
|
|
14
|
+
} else if (isRegExp(item.path) && item.path.test(requestUrl)) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
8
17
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
url: requestUrl,
|
|
12
|
-
req,
|
|
13
|
-
res
|
|
14
|
-
} = context;
|
|
15
|
-
const hit = Object.keys(middlewares).find(u => requestUrl.startsWith(u));
|
|
18
|
+
return false;
|
|
19
|
+
});
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
next();
|
|
25
|
-
});
|
|
26
|
-
} else {
|
|
27
|
-
return next();
|
|
28
|
-
}
|
|
29
|
-
};
|
|
21
|
+
if (hitRule) {
|
|
22
|
+
serve(hitRule.target)(req, res, () => {
|
|
23
|
+
next();
|
|
24
|
+
});
|
|
25
|
+
} else {
|
|
26
|
+
return next();
|
|
27
|
+
}
|
|
30
28
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { HMR_SOCK_PATH } from '@modern-js/utils';
|
|
3
|
-
import webpackDevMiddleware from '
|
|
3
|
+
import webpackDevMiddleware from 'webpack-dev-middleware';
|
|
4
4
|
import { createMockHandler } from "../dev-tools/mock";
|
|
5
5
|
import { createProxyHandler } from "../libs/proxy";
|
|
6
6
|
import SocketServer from "../dev-tools/socket-server";
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { createServer } from 'http';
|
|
2
2
|
import { createServer as createHttpsServer } from 'https';
|
|
3
3
|
import { serverManager } from '@modern-js/server-plugin';
|
|
4
|
-
import {
|
|
4
|
+
import { logger as defaultLogger } from '@modern-js/utils';
|
|
5
5
|
import { ModernServer } from "./modern-server";
|
|
6
|
-
import { ModernDevServer } from "./dev-server";
|
|
7
|
-
import { WebModernDevServer, WebModernServer } from "./web-server";
|
|
8
|
-
import { APIModernDevServer, APIModernServer } from "./api-server";
|
|
9
6
|
import { measure as defaultMeasure } from "../libs/measure";
|
|
10
|
-
import { genHttpsOptions } from "../dev-tools/https";
|
|
11
7
|
export class Server {
|
|
12
8
|
constructor(options) {
|
|
13
|
-
var _options$plugins
|
|
9
|
+
var _options$plugins;
|
|
14
10
|
|
|
15
11
|
this.options = void 0;
|
|
16
12
|
this.server = void 0;
|
|
@@ -20,10 +16,6 @@ export class Server {
|
|
|
20
16
|
(_options$plugins = options.plugins) === null || _options$plugins === void 0 ? void 0 : _options$plugins.forEach(p => {
|
|
21
17
|
serverManager.usePlugin(p);
|
|
22
18
|
});
|
|
23
|
-
|
|
24
|
-
if (((_options$config = options.config) === null || _options$config === void 0 ? void 0 : (_options$config$outpu = _options$config.output) === null || _options$config$outpu === void 0 ? void 0 : _options$config$outpu.polyfill) === 'ua') {
|
|
25
|
-
serverManager.usePlugin(compatRequire('@modern-js/plugin-polyfill'));
|
|
26
|
-
}
|
|
27
19
|
}
|
|
28
20
|
|
|
29
21
|
getRequestHandler() {
|
|
@@ -60,6 +52,10 @@ export class Server {
|
|
|
60
52
|
const devHttpsOption = typeof options.dev === 'object' && options.dev.https;
|
|
61
53
|
|
|
62
54
|
if (devHttpsOption) {
|
|
55
|
+
const {
|
|
56
|
+
genHttpsOptions
|
|
57
|
+
} = require("../dev-tools/https");
|
|
58
|
+
|
|
63
59
|
const httpsOptions = await genHttpsOptions(devHttpsOption);
|
|
64
60
|
this.app = createHttpsServer(httpsOptions, this.getRequestHandler());
|
|
65
61
|
} else {
|
|
@@ -101,8 +97,16 @@ export class Server {
|
|
|
101
97
|
} = this;
|
|
102
98
|
|
|
103
99
|
if (options.apiOnly) {
|
|
100
|
+
const {
|
|
101
|
+
APIModernServer
|
|
102
|
+
} = require("./api-server");
|
|
103
|
+
|
|
104
104
|
return new APIModernServer(options, this.runner);
|
|
105
105
|
} else if (options.webOnly) {
|
|
106
|
+
const {
|
|
107
|
+
WebModernServer
|
|
108
|
+
} = require("./web-server");
|
|
109
|
+
|
|
106
110
|
return new WebModernServer(options, this.runner);
|
|
107
111
|
} else {
|
|
108
112
|
return new ModernServer(options, this.runner);
|
|
@@ -115,10 +119,22 @@ export class Server {
|
|
|
115
119
|
} = this;
|
|
116
120
|
|
|
117
121
|
if (options.apiOnly) {
|
|
122
|
+
const {
|
|
123
|
+
APIModernDevServer
|
|
124
|
+
} = require("./api-server");
|
|
125
|
+
|
|
118
126
|
return new APIModernDevServer(options, this.runner);
|
|
119
127
|
} else if (options.webOnly) {
|
|
128
|
+
const {
|
|
129
|
+
WebModernDevServer
|
|
130
|
+
} = require("./web-server");
|
|
131
|
+
|
|
120
132
|
return new WebModernDevServer(options, this.runner);
|
|
121
133
|
} else {
|
|
134
|
+
const {
|
|
135
|
+
ModernDevServer
|
|
136
|
+
} = require("./dev-server");
|
|
137
|
+
|
|
122
138
|
return new ModernDevServer(options, this.runner);
|
|
123
139
|
}
|
|
124
140
|
}
|
|
@@ -120,12 +120,17 @@ export class ModernServer {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
await this.prepareFrameHandler();
|
|
123
|
+
const {
|
|
124
|
+
favicon,
|
|
125
|
+
faviconByEntries
|
|
126
|
+
} = this.conf.output;
|
|
127
|
+
const favicons = this.prepareFavicons(favicon, faviconByEntries); // Only work when without setting `assetPrefix`.
|
|
128
|
+
// Setting `assetPrefix` means these resources should be uploaded to CDN.
|
|
129
|
+
|
|
130
|
+
const staticPathRegExp = new RegExp(`^/(static/|upload/|favicon.ico|icon.png${favicons.length > 0 ? `|${favicons.join('|')}` : ''})`);
|
|
123
131
|
this.staticFileHandler = createStaticFileHandler([{
|
|
124
|
-
path:
|
|
125
|
-
target:
|
|
126
|
-
}, {
|
|
127
|
-
path: '/upload/',
|
|
128
|
-
target: path.join(distDir, 'upload')
|
|
132
|
+
path: staticPathRegExp,
|
|
133
|
+
target: distDir
|
|
129
134
|
}]);
|
|
130
135
|
this.routeRenderHandler = createRenderHandler({
|
|
131
136
|
distDir,
|
|
@@ -194,13 +199,20 @@ export class ModernServer {
|
|
|
194
199
|
async prepareFrameHandler() {
|
|
195
200
|
const {
|
|
196
201
|
workDir,
|
|
197
|
-
runner
|
|
202
|
+
runner,
|
|
203
|
+
conf
|
|
198
204
|
} = this; // inner tool, gather user inject
|
|
199
205
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
206
|
+
let userAPIExt = [];
|
|
207
|
+
let userWebExt = [];
|
|
208
|
+
|
|
209
|
+
if (!conf.server.disableUserExtension) {
|
|
210
|
+
({
|
|
211
|
+
api: userAPIExt,
|
|
212
|
+
web: userWebExt
|
|
213
|
+
} = gather(workDir));
|
|
214
|
+
} // server hook, gather plugin inject
|
|
215
|
+
|
|
204
216
|
|
|
205
217
|
const _createMiddlewareColl = createMiddlewareCollecter(),
|
|
206
218
|
{
|
|
@@ -277,6 +289,26 @@ export class ModernServer {
|
|
|
277
289
|
this.addHandler(mid);
|
|
278
290
|
});
|
|
279
291
|
}
|
|
292
|
+
|
|
293
|
+
prepareFavicons(favicon, faviconByEntries) {
|
|
294
|
+
const faviconNames = [];
|
|
295
|
+
|
|
296
|
+
if (favicon) {
|
|
297
|
+
faviconNames.push(favicon.substring(favicon.lastIndexOf('/') + 1));
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (faviconByEntries) {
|
|
301
|
+
Object.keys(faviconByEntries).forEach(f => {
|
|
302
|
+
const curFavicon = faviconByEntries[f];
|
|
303
|
+
|
|
304
|
+
if (curFavicon) {
|
|
305
|
+
faviconNames.push(curFavicon.substring(curFavicon.lastIndexOf('/') + 1));
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return faviconNames;
|
|
311
|
+
}
|
|
280
312
|
/* —————————————————————— private function —————————————————————— */
|
|
281
313
|
// handler route.json, include api / csr / ssr
|
|
282
314
|
// eslint-disable-next-line max-statements
|
package/dist/js/modern/type.js
CHANGED
|
@@ -29,7 +29,7 @@ const enableRegister = (projectRoot, config) => {
|
|
|
29
29
|
syntax: 'es6+',
|
|
30
30
|
type: 'commonjs'
|
|
31
31
|
});
|
|
32
|
-
return require('@
|
|
32
|
+
return require('@babel/register')(_objectSpread(_objectSpread({}, babelConfig), {}, {
|
|
33
33
|
only: [function (filePath) {
|
|
34
34
|
// TODO: wait params
|
|
35
35
|
if (filePath.includes(`node_modules${_path.default.sep}.modern-js`)) {
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _webpack = _interopRequireDefault(require("
|
|
8
|
+
var _webpack = _interopRequireDefault(require("webpack"));
|
|
9
9
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
|
|
@@ -29,7 +29,7 @@ class DevServerPlugin {
|
|
|
29
29
|
|
|
30
30
|
const clientEntry = `${require.resolve('@modern-js/hmr-client')}?${host}${path}${port}`;
|
|
31
31
|
|
|
32
|
-
const hotEntry = require.resolve('
|
|
32
|
+
const hotEntry = require.resolve('webpack/hot/dev-server');
|
|
33
33
|
|
|
34
34
|
const additionalEntries = [clientEntry, hotEntry]; // use a hook to add entries if available
|
|
35
35
|
|
|
@@ -12,7 +12,7 @@ var _pathToRegexp = require("path-to-regexp");
|
|
|
12
12
|
var _route = require("./route");
|
|
13
13
|
|
|
14
14
|
// eslint-disable-next-line no-useless-escape
|
|
15
|
-
const regCharsDetector = /[^a-zA-Z\-_0-9
|
|
15
|
+
const regCharsDetector = /[^a-zA-Z\-_0-9\/\.]/;
|
|
16
16
|
|
|
17
17
|
class RouteMatcher {
|
|
18
18
|
constructor(spec) {
|
|
@@ -7,36 +7,35 @@ exports.createStaticFileHandler = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _serveStatic = _interopRequireDefault(require("serve-static"));
|
|
9
9
|
|
|
10
|
+
var _utils = require("@modern-js/utils");
|
|
11
|
+
|
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
13
|
|
|
12
14
|
// Todo 看看是不是能 fork 一份,即使命中也返回
|
|
13
|
-
const createStaticFileHandler = rules =>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const hit = Object.keys(middlewares).find(u => requestUrl.startsWith(u));
|
|
26
|
-
|
|
27
|
-
if (hit) {
|
|
28
|
-
// when matches static resources, delete the first layer of req.url
|
|
29
|
-
const removed = hit;
|
|
30
|
-
context.url = requestUrl.slice(removed.length - 1);
|
|
31
|
-
middlewares[hit](req, res, () => {
|
|
32
|
-
// will invok next, recover req.url
|
|
33
|
-
context.url = removed + context.url;
|
|
34
|
-
next();
|
|
35
|
-
});
|
|
36
|
-
} else {
|
|
37
|
-
return next();
|
|
15
|
+
const createStaticFileHandler = rules => // eslint-disable-next-line consistent-return
|
|
16
|
+
async (context, next) => {
|
|
17
|
+
const {
|
|
18
|
+
url: requestUrl,
|
|
19
|
+
req,
|
|
20
|
+
res
|
|
21
|
+
} = context;
|
|
22
|
+
const hitRule = rules.find(item => {
|
|
23
|
+
if ((0, _utils.isString)(item.path) && requestUrl.startsWith(item.path)) {
|
|
24
|
+
return true;
|
|
25
|
+
} else if ((0, _utils.isRegExp)(item.path) && item.path.test(requestUrl)) {
|
|
26
|
+
return true;
|
|
38
27
|
}
|
|
39
|
-
|
|
28
|
+
|
|
29
|
+
return false;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (hitRule) {
|
|
33
|
+
(0, _serveStatic.default)(hitRule.target)(req, res, () => {
|
|
34
|
+
next();
|
|
35
|
+
});
|
|
36
|
+
} else {
|
|
37
|
+
return next();
|
|
38
|
+
}
|
|
40
39
|
};
|
|
41
40
|
|
|
42
41
|
exports.createStaticFileHandler = createStaticFileHandler;
|
|
@@ -9,7 +9,7 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
9
9
|
|
|
10
10
|
var _utils = require("@modern-js/utils");
|
|
11
11
|
|
|
12
|
-
var _webpackDevMiddleware = _interopRequireDefault(require("
|
|
12
|
+
var _webpackDevMiddleware = _interopRequireDefault(require("webpack-dev-middleware"));
|
|
13
13
|
|
|
14
14
|
var _mock = require("../dev-tools/mock");
|
|
15
15
|
|
|
@@ -15,19 +15,11 @@ var _utils = require("@modern-js/utils");
|
|
|
15
15
|
|
|
16
16
|
var _modernServer = require("./modern-server");
|
|
17
17
|
|
|
18
|
-
var _devServer = require("./dev-server");
|
|
19
|
-
|
|
20
|
-
var _webServer = require("./web-server");
|
|
21
|
-
|
|
22
|
-
var _apiServer = require("./api-server");
|
|
23
|
-
|
|
24
18
|
var _measure = require("../libs/measure");
|
|
25
19
|
|
|
26
|
-
var _https2 = require("../dev-tools/https");
|
|
27
|
-
|
|
28
20
|
class Server {
|
|
29
21
|
constructor(options) {
|
|
30
|
-
var _options$plugins
|
|
22
|
+
var _options$plugins;
|
|
31
23
|
|
|
32
24
|
this.options = void 0;
|
|
33
25
|
this.server = void 0;
|
|
@@ -37,10 +29,6 @@ class Server {
|
|
|
37
29
|
(_options$plugins = options.plugins) === null || _options$plugins === void 0 ? void 0 : _options$plugins.forEach(p => {
|
|
38
30
|
_serverPlugin.serverManager.usePlugin(p);
|
|
39
31
|
});
|
|
40
|
-
|
|
41
|
-
if (((_options$config = options.config) === null || _options$config === void 0 ? void 0 : (_options$config$outpu = _options$config.output) === null || _options$config$outpu === void 0 ? void 0 : _options$config$outpu.polyfill) === 'ua') {
|
|
42
|
-
_serverPlugin.serverManager.usePlugin((0, _utils.compatRequire)('@modern-js/plugin-polyfill'));
|
|
43
|
-
}
|
|
44
32
|
}
|
|
45
33
|
|
|
46
34
|
getRequestHandler() {
|
|
@@ -77,7 +65,11 @@ class Server {
|
|
|
77
65
|
const devHttpsOption = typeof options.dev === 'object' && options.dev.https;
|
|
78
66
|
|
|
79
67
|
if (devHttpsOption) {
|
|
80
|
-
const
|
|
68
|
+
const {
|
|
69
|
+
genHttpsOptions
|
|
70
|
+
} = require("../dev-tools/https");
|
|
71
|
+
|
|
72
|
+
const httpsOptions = await genHttpsOptions(devHttpsOption);
|
|
81
73
|
this.app = (0, _https.createServer)(httpsOptions, this.getRequestHandler());
|
|
82
74
|
} else {
|
|
83
75
|
this.app = (0, _http.createServer)(this.getRequestHandler());
|
|
@@ -118,9 +110,17 @@ class Server {
|
|
|
118
110
|
} = this;
|
|
119
111
|
|
|
120
112
|
if (options.apiOnly) {
|
|
121
|
-
|
|
113
|
+
const {
|
|
114
|
+
APIModernServer
|
|
115
|
+
} = require("./api-server");
|
|
116
|
+
|
|
117
|
+
return new APIModernServer(options, this.runner);
|
|
122
118
|
} else if (options.webOnly) {
|
|
123
|
-
|
|
119
|
+
const {
|
|
120
|
+
WebModernServer
|
|
121
|
+
} = require("./web-server");
|
|
122
|
+
|
|
123
|
+
return new WebModernServer(options, this.runner);
|
|
124
124
|
} else {
|
|
125
125
|
return new _modernServer.ModernServer(options, this.runner);
|
|
126
126
|
}
|
|
@@ -132,11 +132,23 @@ class Server {
|
|
|
132
132
|
} = this;
|
|
133
133
|
|
|
134
134
|
if (options.apiOnly) {
|
|
135
|
-
|
|
135
|
+
const {
|
|
136
|
+
APIModernDevServer
|
|
137
|
+
} = require("./api-server");
|
|
138
|
+
|
|
139
|
+
return new APIModernDevServer(options, this.runner);
|
|
136
140
|
} else if (options.webOnly) {
|
|
137
|
-
|
|
141
|
+
const {
|
|
142
|
+
WebModernDevServer
|
|
143
|
+
} = require("./web-server");
|
|
144
|
+
|
|
145
|
+
return new WebModernDevServer(options, this.runner);
|
|
138
146
|
} else {
|
|
139
|
-
|
|
147
|
+
const {
|
|
148
|
+
ModernDevServer
|
|
149
|
+
} = require("./dev-server");
|
|
150
|
+
|
|
151
|
+
return new ModernDevServer(options, this.runner);
|
|
140
152
|
}
|
|
141
153
|
}
|
|
142
154
|
|
|
@@ -148,12 +148,17 @@ class ModernServer {
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
await this.prepareFrameHandler();
|
|
151
|
+
const {
|
|
152
|
+
favicon,
|
|
153
|
+
faviconByEntries
|
|
154
|
+
} = this.conf.output;
|
|
155
|
+
const favicons = this.prepareFavicons(favicon, faviconByEntries); // Only work when without setting `assetPrefix`.
|
|
156
|
+
// Setting `assetPrefix` means these resources should be uploaded to CDN.
|
|
157
|
+
|
|
158
|
+
const staticPathRegExp = new RegExp(`^/(static/|upload/|favicon.ico|icon.png${favicons.length > 0 ? `|${favicons.join('|')}` : ''})`);
|
|
151
159
|
this.staticFileHandler = (0, _serveFile.createStaticFileHandler)([{
|
|
152
|
-
path:
|
|
153
|
-
target:
|
|
154
|
-
}, {
|
|
155
|
-
path: '/upload/',
|
|
156
|
-
target: _path.default.join(distDir, 'upload')
|
|
160
|
+
path: staticPathRegExp,
|
|
161
|
+
target: distDir
|
|
157
162
|
}]);
|
|
158
163
|
this.routeRenderHandler = (0, _render.createRenderHandler)({
|
|
159
164
|
distDir,
|
|
@@ -224,13 +229,20 @@ class ModernServer {
|
|
|
224
229
|
async prepareFrameHandler() {
|
|
225
230
|
const {
|
|
226
231
|
workDir,
|
|
227
|
-
runner
|
|
232
|
+
runner,
|
|
233
|
+
conf
|
|
228
234
|
} = this; // inner tool, gather user inject
|
|
229
235
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
236
|
+
let userAPIExt = [];
|
|
237
|
+
let userWebExt = [];
|
|
238
|
+
|
|
239
|
+
if (!conf.server.disableUserExtension) {
|
|
240
|
+
({
|
|
241
|
+
api: userAPIExt,
|
|
242
|
+
web: userWebExt
|
|
243
|
+
} = (0, _serverUtils.gather)(workDir));
|
|
244
|
+
} // server hook, gather plugin inject
|
|
245
|
+
|
|
234
246
|
|
|
235
247
|
const _createMiddlewareColl = (0, _serverUtils.createMiddlewareCollecter)(),
|
|
236
248
|
{
|
|
@@ -310,6 +322,26 @@ class ModernServer {
|
|
|
310
322
|
this.addHandler(mid);
|
|
311
323
|
});
|
|
312
324
|
}
|
|
325
|
+
|
|
326
|
+
prepareFavicons(favicon, faviconByEntries) {
|
|
327
|
+
const faviconNames = [];
|
|
328
|
+
|
|
329
|
+
if (favicon) {
|
|
330
|
+
faviconNames.push(favicon.substring(favicon.lastIndexOf('/') + 1));
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (faviconByEntries) {
|
|
334
|
+
Object.keys(faviconByEntries).forEach(f => {
|
|
335
|
+
const curFavicon = faviconByEntries[f];
|
|
336
|
+
|
|
337
|
+
if (curFavicon) {
|
|
338
|
+
faviconNames.push(curFavicon.substring(curFavicon.lastIndexOf('/') + 1));
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return faviconNames;
|
|
344
|
+
}
|
|
313
345
|
/* —————————————————————— private function —————————————————————— */
|
|
314
346
|
// handler route.json, include api / csr / ssr
|
|
315
347
|
// eslint-disable-next-line max-statements
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Server } from 'http';
|
|
3
3
|
import ws from 'ws';
|
|
4
|
-
import type { Stats } from '
|
|
4
|
+
import type { Stats } from 'webpack';
|
|
5
5
|
import { DevServerOptions } from '../type';
|
|
6
6
|
export default class SocketServer {
|
|
7
7
|
private wsServer;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NextFunction } from '../type';
|
|
2
2
|
import { ModernServerContext } from './context';
|
|
3
3
|
declare type Rule = {
|
|
4
|
-
path: string;
|
|
4
|
+
path: string | RegExp;
|
|
5
5
|
target: string;
|
|
6
6
|
};
|
|
7
7
|
export declare const createStaticFileHandler: (rules: Rule[]) => (context: ModernServerContext, next: NextFunction) => Promise<void>;
|
|
@@ -51,6 +51,7 @@ export declare class ModernServer {
|
|
|
51
51
|
protected prepareAPIHandler(mode: ApiServerMode, extension: ReturnType<typeof mergeExtension>): Promise<Adapter>;
|
|
52
52
|
protected filterRoutes(routes: ModernRouteInterface[]): ModernRouteInterface[];
|
|
53
53
|
protected preServerInit(): Promise<void>;
|
|
54
|
+
private prepareFavicons;
|
|
54
55
|
private routeHandler;
|
|
55
56
|
private injectMicroFE;
|
|
56
57
|
private compose;
|
package/dist/types/type.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type Webpack from '
|
|
2
|
+
import type Webpack from 'webpack';
|
|
3
3
|
import { serverManager } from '@modern-js/server-plugin';
|
|
4
4
|
import type { NormalizedConfig } from '@modern-js/core';
|
|
5
5
|
import type { Measure, Logger, NextFunction } from '@modern-js/types/server';
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "0.0.0-
|
|
14
|
+
"version": "0.0.0-plugins-202111301002",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -26,16 +26,27 @@
|
|
|
26
26
|
"default": "./dist/js/treeshaking/index.js"
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"prepare": "pnpm build",
|
|
31
|
+
"prepublishOnly": "pnpm build --platform",
|
|
32
|
+
"new": "modern new",
|
|
33
|
+
"build": "modern build",
|
|
34
|
+
"dev": "modern build --watch",
|
|
35
|
+
"test": "modern test --passWithNoTests"
|
|
36
|
+
},
|
|
29
37
|
"dependencies": {
|
|
38
|
+
"@babel/core": "^7.15.0",
|
|
30
39
|
"@babel/compat-data": "^7.15.0",
|
|
40
|
+
"@babel/preset-env": "^7.15.0",
|
|
41
|
+
"@babel/preset-typescript": "^7.15.0",
|
|
42
|
+
"@babel/register": "^7.15.3",
|
|
31
43
|
"@babel/runtime": "^7",
|
|
32
|
-
"@modern-js/core": "
|
|
33
|
-
"@modern-js/hmr-client": "
|
|
34
|
-
"@modern-js/plugin
|
|
35
|
-
"@modern-js/server-
|
|
36
|
-
"@modern-js/
|
|
37
|
-
"@modern-js/
|
|
38
|
-
"@modern-js/utils": "0.0.0-bundle-deps-2021101244657",
|
|
44
|
+
"@modern-js/core": "^1.1.2",
|
|
45
|
+
"@modern-js/hmr-client": "^1.1.1",
|
|
46
|
+
"@modern-js/server-plugin": "^1.1.1",
|
|
47
|
+
"@modern-js/server-utils": "^1.1.1",
|
|
48
|
+
"@modern-js/bff-utils": "^1.1.1",
|
|
49
|
+
"@modern-js/utils": "^1.1.2",
|
|
39
50
|
"axios": "^0.21.4",
|
|
40
51
|
"babel-plugin-module-resolver": "^4.1.0",
|
|
41
52
|
"chokidar": "^3.5.2",
|
|
@@ -54,13 +65,13 @@
|
|
|
54
65
|
"serve-static": "^1.14.1",
|
|
55
66
|
"tsconfig-paths": "^3.11.0",
|
|
56
67
|
"ua-parser-js": "^0.7.28",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
68
|
+
"webpack-dev-middleware": "^5.0.0",
|
|
69
|
+
"ws": "^8.2.0"
|
|
59
70
|
},
|
|
60
71
|
"devDependencies": {
|
|
61
|
-
"@modern-js/module-tools": "^
|
|
62
|
-
"@modern-js/plugin-testing": "^
|
|
63
|
-
"@modern-js/types": "
|
|
72
|
+
"@modern-js/module-tools": "^1.1.1",
|
|
73
|
+
"@modern-js/plugin-testing": "^1.1.1",
|
|
74
|
+
"@modern-js/types": "^1.1.2",
|
|
64
75
|
"@types/jest": "^26",
|
|
65
76
|
"@types/lru-cache": "^5.1.1",
|
|
66
77
|
"@types/mime-types": "^2.1.0",
|
|
@@ -72,8 +83,13 @@
|
|
|
72
83
|
"@types/serialize-javascript": "^5.0.1",
|
|
73
84
|
"@types/serve-static": "^1.13.10",
|
|
74
85
|
"@types/ua-parser-js": "^0.7.36",
|
|
86
|
+
"@types/webpack-dev-middleware": "^5.0.2",
|
|
75
87
|
"@types/ws": "^7.4.7",
|
|
76
|
-
"typescript": "^4"
|
|
88
|
+
"typescript": "^4",
|
|
89
|
+
"webpack": "^5.54.0"
|
|
90
|
+
},
|
|
91
|
+
"peerDependencies": {
|
|
92
|
+
"webpack": "^5.54.0"
|
|
77
93
|
},
|
|
78
94
|
"sideEffects": false,
|
|
79
95
|
"modernConfig": {
|
|
@@ -84,11 +100,5 @@
|
|
|
84
100
|
"publishConfig": {
|
|
85
101
|
"registry": "https://registry.npmjs.org/",
|
|
86
102
|
"access": "public"
|
|
87
|
-
},
|
|
88
|
-
"scripts": {
|
|
89
|
-
"new": "modern new",
|
|
90
|
-
"build": "modern build",
|
|
91
|
-
"dev": "modern build --watch",
|
|
92
|
-
"test": "modern test --passWithNoTests"
|
|
93
103
|
}
|
|
94
|
-
}
|
|
104
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Webpack from '
|
|
1
|
+
import Webpack from 'webpack';
|
|
2
2
|
import { DevServerOptions } from '../type';
|
|
3
3
|
|
|
4
4
|
const { EntryPlugin } = Webpack;
|
|
@@ -20,9 +20,7 @@ export default class DevServerPlugin {
|
|
|
20
20
|
const clientEntry = `${require.resolve(
|
|
21
21
|
'@modern-js/hmr-client',
|
|
22
22
|
)}?${host}${path}${port}`;
|
|
23
|
-
const hotEntry = require.resolve(
|
|
24
|
-
'@modern-js/deps/compiled/webpack/hot/dev-server',
|
|
25
|
-
);
|
|
23
|
+
const hotEntry = require.resolve('webpack/hot/dev-server');
|
|
26
24
|
const additionalEntries = [clientEntry, hotEntry];
|
|
27
25
|
|
|
28
26
|
// use a hook to add entries if available
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Server } from 'http';
|
|
2
2
|
import { Socket } from 'net';
|
|
3
3
|
import ws from 'ws';
|
|
4
|
-
import type { Stats } from '
|
|
4
|
+
import type { Stats } from 'webpack';
|
|
5
5
|
import { logger } from '@modern-js/utils';
|
|
6
6
|
import { DevServerOptions } from '../type';
|
|
7
7
|
import { noop } from '@/utils';
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
import { ModernRoute, ModernRouteInterface } from './route';
|
|
9
9
|
|
|
10
10
|
// eslint-disable-next-line no-useless-escape
|
|
11
|
-
const regCharsDetector = /[^a-zA-Z\-_0-9
|
|
11
|
+
const regCharsDetector = /[^a-zA-Z\-_0-9\/\.]/;
|
|
12
12
|
export class RouteMatcher {
|
|
13
13
|
public spec: ModernRouteInterface;
|
|
14
14
|
|
package/src/libs/serve-file.ts
CHANGED
|
@@ -1,38 +1,34 @@
|
|
|
1
1
|
// Todo 看看是不是能 fork 一份,即使命中也返回
|
|
2
2
|
import serve from 'serve-static';
|
|
3
|
+
import { isString, isRegExp } from '@modern-js/utils';
|
|
3
4
|
import { NextFunction } from '../type';
|
|
4
5
|
import { ModernServerContext } from './context';
|
|
5
6
|
|
|
6
7
|
type Rule = {
|
|
7
|
-
path: string;
|
|
8
|
+
path: string | RegExp;
|
|
8
9
|
target: string;
|
|
9
10
|
};
|
|
10
11
|
|
|
11
|
-
export const createStaticFileHandler =
|
|
12
|
-
|
|
13
|
-
(map: Record<string, ReturnType<typeof serve>>, rule) => {
|
|
14
|
-
map[rule.path] = serve(rule.target);
|
|
15
|
-
return map;
|
|
16
|
-
},
|
|
17
|
-
{},
|
|
18
|
-
);
|
|
19
|
-
|
|
12
|
+
export const createStaticFileHandler =
|
|
13
|
+
(rules: Rule[]) =>
|
|
20
14
|
// eslint-disable-next-line consistent-return
|
|
21
|
-
|
|
15
|
+
async (context: ModernServerContext, next: NextFunction) => {
|
|
22
16
|
const { url: requestUrl, req, res } = context;
|
|
23
|
-
const hit = Object.keys(middlewares).find(u => requestUrl.startsWith(u));
|
|
24
17
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
const hitRule = rules.find(item => {
|
|
19
|
+
if (isString(item.path) && requestUrl.startsWith(item.path)) {
|
|
20
|
+
return true;
|
|
21
|
+
} else if (isRegExp(item.path) && item.path.test(requestUrl)) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (hitRule) {
|
|
28
|
+
serve(hitRule.target)(req, res, () => {
|
|
32
29
|
next();
|
|
33
30
|
});
|
|
34
31
|
} else {
|
|
35
32
|
return next();
|
|
36
33
|
}
|
|
37
34
|
};
|
|
38
|
-
};
|
package/src/server/dev-server.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import http, { Server } from 'http';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { HMR_SOCK_PATH } from '@modern-js/utils';
|
|
4
|
-
import type { MultiCompiler, Compiler } from '
|
|
4
|
+
import type { MultiCompiler, Compiler } from 'webpack';
|
|
5
5
|
import webpackDevMiddleware, {
|
|
6
6
|
WebpackDevMiddleware,
|
|
7
|
-
} from '
|
|
7
|
+
} from 'webpack-dev-middleware';
|
|
8
8
|
import { createMockHandler } from '../dev-tools/mock';
|
|
9
9
|
import { createProxyHandler, ProxyOptions } from '../libs/proxy';
|
|
10
10
|
import {
|
package/src/server/index.ts
CHANGED
|
@@ -6,14 +6,11 @@ import {
|
|
|
6
6
|
} from 'http';
|
|
7
7
|
import { createServer as createHttpsServer } from 'https';
|
|
8
8
|
import { serverManager } from '@modern-js/server-plugin';
|
|
9
|
-
import {
|
|
9
|
+
import { logger as defaultLogger } from '@modern-js/utils';
|
|
10
10
|
import { ModernServerOptions, ServerHookRunner, ReadyOptions } from '../type';
|
|
11
11
|
import { ModernServer } from './modern-server';
|
|
12
|
-
import { ModernDevServer } from './dev-server';
|
|
13
|
-
import { WebModernDevServer, WebModernServer } from './web-server';
|
|
14
|
-
import { APIModernDevServer, APIModernServer } from './api-server';
|
|
12
|
+
import type { ModernDevServer } from './dev-server';
|
|
15
13
|
import { measure as defaultMeasure } from '@/libs/measure';
|
|
16
|
-
import { genHttpsOptions } from '@/dev-tools/https';
|
|
17
14
|
|
|
18
15
|
export class Server {
|
|
19
16
|
public options: ModernServerOptions;
|
|
@@ -29,10 +26,6 @@ export class Server {
|
|
|
29
26
|
options.plugins?.forEach(p => {
|
|
30
27
|
serverManager.usePlugin(p);
|
|
31
28
|
});
|
|
32
|
-
|
|
33
|
-
if (options.config?.output?.polyfill === 'ua') {
|
|
34
|
-
serverManager.usePlugin(compatRequire('@modern-js/plugin-polyfill'));
|
|
35
|
-
}
|
|
36
29
|
}
|
|
37
30
|
|
|
38
31
|
public getRequestHandler() {
|
|
@@ -68,6 +61,7 @@ export class Server {
|
|
|
68
61
|
const devHttpsOption =
|
|
69
62
|
typeof options.dev === 'object' && options.dev.https;
|
|
70
63
|
if (devHttpsOption) {
|
|
64
|
+
const { genHttpsOptions } = require('@/dev-tools/https');
|
|
71
65
|
const httpsOptions = await genHttpsOptions(devHttpsOption);
|
|
72
66
|
this.app = createHttpsServer(httpsOptions, this.getRequestHandler());
|
|
73
67
|
} else {
|
|
@@ -109,8 +103,10 @@ export class Server {
|
|
|
109
103
|
const { options } = this;
|
|
110
104
|
|
|
111
105
|
if (options.apiOnly) {
|
|
106
|
+
const { APIModernServer } = require('./api-server');
|
|
112
107
|
return new APIModernServer(options, this.runner);
|
|
113
108
|
} else if (options.webOnly) {
|
|
109
|
+
const { WebModernServer } = require('./web-server');
|
|
114
110
|
return new WebModernServer(options, this.runner);
|
|
115
111
|
} else {
|
|
116
112
|
return new ModernServer(options, this.runner);
|
|
@@ -121,10 +117,13 @@ export class Server {
|
|
|
121
117
|
const { options } = this;
|
|
122
118
|
|
|
123
119
|
if (options.apiOnly) {
|
|
120
|
+
const { APIModernDevServer } = require('./api-server');
|
|
124
121
|
return new APIModernDevServer(options, this.runner);
|
|
125
122
|
} else if (options.webOnly) {
|
|
123
|
+
const { WebModernDevServer } = require('./web-server');
|
|
126
124
|
return new WebModernDevServer(options, this.runner);
|
|
127
125
|
} else {
|
|
126
|
+
const { ModernDevServer } = require('./dev-server');
|
|
128
127
|
return new ModernDevServer(options, this.runner);
|
|
129
128
|
}
|
|
130
129
|
}
|
|
@@ -154,14 +154,20 @@ export class ModernServer {
|
|
|
154
154
|
|
|
155
155
|
await this.prepareFrameHandler();
|
|
156
156
|
|
|
157
|
+
const { favicon, faviconByEntries } = this.conf.output;
|
|
158
|
+
const favicons = this.prepareFavicons(favicon, faviconByEntries);
|
|
159
|
+
// Only work when without setting `assetPrefix`.
|
|
160
|
+
// Setting `assetPrefix` means these resources should be uploaded to CDN.
|
|
161
|
+
const staticPathRegExp = new RegExp(
|
|
162
|
+
`^/(static/|upload/|favicon.ico|icon.png${
|
|
163
|
+
favicons.length > 0 ? `|${favicons.join('|')}` : ''
|
|
164
|
+
})`,
|
|
165
|
+
);
|
|
166
|
+
|
|
157
167
|
this.staticFileHandler = createStaticFileHandler([
|
|
158
168
|
{
|
|
159
|
-
path:
|
|
160
|
-
target:
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
path: '/upload/',
|
|
164
|
-
target: path.join(distDir, 'upload'),
|
|
169
|
+
path: staticPathRegExp,
|
|
170
|
+
target: distDir,
|
|
165
171
|
},
|
|
166
172
|
]);
|
|
167
173
|
|
|
@@ -233,10 +239,14 @@ export class ModernServer {
|
|
|
233
239
|
|
|
234
240
|
// gather frame extension and get framework handler
|
|
235
241
|
protected async prepareFrameHandler() {
|
|
236
|
-
const { workDir, runner } = this;
|
|
242
|
+
const { workDir, runner, conf } = this;
|
|
237
243
|
|
|
238
244
|
// inner tool, gather user inject
|
|
239
|
-
|
|
245
|
+
let userAPIExt = [];
|
|
246
|
+
let userWebExt = [];
|
|
247
|
+
if (!conf.server.disableUserExtension) {
|
|
248
|
+
({ api: userAPIExt, web: userWebExt } = gather(workDir));
|
|
249
|
+
}
|
|
240
250
|
|
|
241
251
|
// server hook, gather plugin inject
|
|
242
252
|
const { getMiddlewares, ...collector } = createMiddlewareCollecter();
|
|
@@ -315,6 +325,27 @@ export class ModernServer {
|
|
|
315
325
|
});
|
|
316
326
|
}
|
|
317
327
|
|
|
328
|
+
private prepareFavicons(
|
|
329
|
+
favicon: string | undefined,
|
|
330
|
+
faviconByEntries?: Record<string, string | undefined>,
|
|
331
|
+
) {
|
|
332
|
+
const faviconNames = [];
|
|
333
|
+
if (favicon) {
|
|
334
|
+
faviconNames.push(favicon.substring(favicon.lastIndexOf('/') + 1));
|
|
335
|
+
}
|
|
336
|
+
if (faviconByEntries) {
|
|
337
|
+
Object.keys(faviconByEntries).forEach(f => {
|
|
338
|
+
const curFavicon = faviconByEntries[f];
|
|
339
|
+
if (curFavicon) {
|
|
340
|
+
faviconNames.push(
|
|
341
|
+
curFavicon.substring(curFavicon.lastIndexOf('/') + 1),
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
return faviconNames;
|
|
347
|
+
}
|
|
348
|
+
|
|
318
349
|
/* —————————————————————— private function —————————————————————— */
|
|
319
350
|
|
|
320
351
|
// handler route.json, include api / csr / ssr
|
package/src/type.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
|
-
import type Webpack from '
|
|
2
|
+
import type Webpack from 'webpack';
|
|
3
3
|
import { serverManager } from '@modern-js/server-plugin';
|
|
4
4
|
import type { NormalizedConfig } from '@modern-js/core';
|
|
5
5
|
import type { Measure, Logger, NextFunction } from '@modern-js/types/server';
|