@modern-js/server 1.15.1-beta.0 → 1.16.0-alpha.underfin.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/CHANGELOG.md +19 -0
- package/dist/js/modern/dev-tools/babel/register.js +19 -62
- package/dist/js/modern/dev-tools/dev-server-plugin.js +6 -7
- package/dist/js/modern/hmr-client/index.js +3 -4
- package/dist/js/modern/server/dev-server.js +19 -3
- package/dist/js/modern/types.js +0 -1
- package/dist/js/node/dev-tools/babel/register.js +19 -69
- package/dist/js/node/dev-tools/dev-server-plugin.js +6 -9
- package/dist/js/node/hmr-client/index.js +3 -4
- package/dist/js/node/server/dev-server.js +19 -3
- package/dist/js/node/types.js +0 -5
- package/dist/types/dev-tools/dev-server-plugin.d.ts +2 -2
- package/dist/types/dev-tools/socket-server.d.ts +2 -2
- package/dist/types/server/dev-server.d.ts +1 -0
- package/dist/types/types.d.ts +2 -2
- package/package.json +10 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @modern-js/server
|
|
2
2
|
|
|
3
|
+
## 1.16.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2808ff5a2: fix(dev-server): support enable hmr client by webpack target
|
|
8
|
+
|
|
9
|
+
fix(dev-server): 支持通过 webpack target 来判断是否启用 hmr client
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [641592f52]
|
|
12
|
+
- Updated dependencies [3904b30a5]
|
|
13
|
+
- Updated dependencies [1100dd58c]
|
|
14
|
+
- Updated dependencies [e04e6e76a]
|
|
15
|
+
- Updated dependencies [81c66e4a4]
|
|
16
|
+
- Updated dependencies [2c305b6f5]
|
|
17
|
+
- @modern-js/utils@1.16.0
|
|
18
|
+
- @modern-js/webpack@1.16.0
|
|
19
|
+
- @modern-js/server-utils@1.16.0
|
|
20
|
+
- @modern-js/prod-server@1.16.0
|
|
21
|
+
|
|
3
22
|
## 1.15.0
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
|
@@ -6,71 +6,28 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
6
6
|
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import { resolveBabelConfig } from '@modern-js/server-utils';
|
|
9
|
-
import { fs, getAlias } from '@modern-js/utils';
|
|
10
|
-
import * as tsNode from 'ts-node';
|
|
11
|
-
import * as tsConfigPaths from 'tsconfig-paths';
|
|
12
9
|
const registerDirs = ['./api', './server', './config/mock', './shared'];
|
|
13
|
-
export const enableRegister = (projectRoot, config
|
|
14
|
-
) => {
|
|
10
|
+
export const enableRegister = (projectRoot, config) => {
|
|
15
11
|
const TS_CONFIG_FILENAME = `tsconfig.json`;
|
|
16
12
|
const tsconfigPath = path.resolve(projectRoot, TS_CONFIG_FILENAME);
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
paths = {},
|
|
29
|
-
absoluteBaseUrl = './'
|
|
30
|
-
} = aliasOption;
|
|
31
|
-
const tsPaths = Object.keys(paths).reduce((o, key) => {
|
|
32
|
-
let tsPath = paths[key]; // 要不要把对 modern 的判断去掉
|
|
33
|
-
|
|
34
|
-
if (typeof tsPath === 'string' && path.isAbsolute(tsPath)) {
|
|
35
|
-
tsPath = path.relative(absoluteBaseUrl, tsPath);
|
|
13
|
+
const babelConfig = resolveBabelConfig(projectRoot, config, {
|
|
14
|
+
tsconfigPath,
|
|
15
|
+
syntax: 'es6+',
|
|
16
|
+
type: 'commonjs'
|
|
17
|
+
});
|
|
18
|
+
return require('@babel/register')(_objectSpread(_objectSpread({}, babelConfig), {}, {
|
|
19
|
+
only: [function (filePath) {
|
|
20
|
+
// TODO: wait params
|
|
21
|
+
// FIXME: 删除hardcode,根据 AppContext 中的 metaName 设置路径
|
|
22
|
+
if (filePath.includes(`node_modules${path.sep}.modern-js`)) {
|
|
23
|
+
return true;
|
|
36
24
|
}
|
|
37
25
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}, {});
|
|
46
|
-
tsConfigPaths.register({
|
|
47
|
-
baseUrl: absoluteBaseUrl || './',
|
|
48
|
-
paths: tsPaths
|
|
49
|
-
});
|
|
50
|
-
tsNode.register({
|
|
51
|
-
project: tsconfigPath,
|
|
52
|
-
transpileOnly: true
|
|
53
|
-
});
|
|
54
|
-
} else {
|
|
55
|
-
const babelConfig = resolveBabelConfig(projectRoot, config, {
|
|
56
|
-
tsconfigPath,
|
|
57
|
-
syntax: 'es6+',
|
|
58
|
-
type: 'commonjs'
|
|
59
|
-
});
|
|
60
|
-
return require('@babel/register')(_objectSpread(_objectSpread({}, babelConfig), {}, {
|
|
61
|
-
only: [function (filePath) {
|
|
62
|
-
// TODO: wait params
|
|
63
|
-
// FIXME: 删除hardcode,根据 AppContext 中的 metaName 设置路径
|
|
64
|
-
if (filePath.includes(`node_modules${path.sep}.modern-js`)) {
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return registerDirs.some(registerDir => filePath.startsWith(path.join(projectRoot, registerDir)));
|
|
69
|
-
}],
|
|
70
|
-
extensions: ['.js', '.ts'],
|
|
71
|
-
babelrc: false,
|
|
72
|
-
configFile: false,
|
|
73
|
-
root: projectRoot
|
|
74
|
-
}));
|
|
75
|
-
}
|
|
26
|
+
return registerDirs.some(registerDir => filePath.startsWith(path.join(projectRoot, registerDir)));
|
|
27
|
+
}],
|
|
28
|
+
extensions: ['.js', '.ts'],
|
|
29
|
+
babelrc: false,
|
|
30
|
+
configFile: false,
|
|
31
|
+
root: projectRoot
|
|
32
|
+
}));
|
|
76
33
|
};
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
2
|
|
|
3
|
-
import { webpack } from '@modern-js/webpack';
|
|
4
|
-
const {
|
|
5
|
-
EntryPlugin
|
|
6
|
-
} = webpack;
|
|
7
3
|
export default class DevServerPlugin {
|
|
8
4
|
constructor(options) {
|
|
9
5
|
_defineProperty(this, "options", void 0);
|
|
@@ -20,7 +16,7 @@ export default class DevServerPlugin {
|
|
|
20
16
|
const port = client.port ? `&port=${client.port}` : '';
|
|
21
17
|
const clientEntry = `${require.resolve("../hmr-client")}?${host}${path}${port}`; // use a hook to add entries if available
|
|
22
18
|
|
|
23
|
-
new EntryPlugin(compiler.context, clientEntry, {
|
|
19
|
+
new compiler.webpack.EntryPlugin(compiler.context, clientEntry, {
|
|
24
20
|
name: undefined
|
|
25
21
|
}).apply(compiler);
|
|
26
22
|
}
|
|
@@ -32,11 +28,14 @@ export default class DevServerPlugin {
|
|
|
32
28
|
|
|
33
29
|
|
|
34
30
|
const compilerOptions = compiler.options;
|
|
31
|
+
const {
|
|
32
|
+
HotModuleReplacementPlugin
|
|
33
|
+
} = compiler.webpack;
|
|
35
34
|
compilerOptions.plugins = compilerOptions.plugins || [];
|
|
36
35
|
|
|
37
|
-
if (!compilerOptions.plugins.find(p => p.constructor ===
|
|
36
|
+
if (!compilerOptions.plugins.find(p => p.constructor === HotModuleReplacementPlugin)) {
|
|
38
37
|
// apply the HMR plugin, if it didn't exist before.
|
|
39
|
-
const plugin = new
|
|
38
|
+
const plugin = new HotModuleReplacementPlugin();
|
|
40
39
|
plugin.apply(compiler);
|
|
41
40
|
}
|
|
42
41
|
}
|
|
@@ -8,6 +8,7 @@ import stripAnsi from '@modern-js/utils/strip-ansi';
|
|
|
8
8
|
import { formatWebpackMessages } from '@modern-js/utils/format';
|
|
9
9
|
import { createSocketUrl } from "./createSocketUrl"; // declare any to fix the type of `module.hot`
|
|
10
10
|
|
|
11
|
+
// TODO hadRuntimeError should be fixed.
|
|
11
12
|
// We need to keep track of if there has been a runtime error.
|
|
12
13
|
// Essentially, we cannot guarantee application state was not corrupted by the
|
|
13
14
|
// runtime error. To prevent confusing behavior, we forcibly reload the entire
|
|
@@ -171,11 +172,9 @@ function tryApplyUpdates() {
|
|
|
171
172
|
}
|
|
172
173
|
|
|
173
174
|
function handleApplyUpdates(err, updatedModules) {
|
|
174
|
-
|
|
175
|
-
const hasReactRefresh = process.env.FAST_REFRESH;
|
|
176
|
-
const wantsForcedReload = err || !updatedModules || hadRuntimeError; // React refresh can handle hot-reloading over errors.
|
|
175
|
+
const wantsForcedReload = err || !updatedModules || hadRuntimeError;
|
|
177
176
|
|
|
178
|
-
if (
|
|
177
|
+
if (wantsForcedReload) {
|
|
179
178
|
window.location.reload();
|
|
180
179
|
return;
|
|
181
180
|
}
|
|
@@ -8,7 +8,7 @@ import { createServer } from 'http';
|
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import { createServer as createHttpsServer } from 'https';
|
|
10
10
|
import { API_DIR, SERVER_DIR, SHARED_DIR } from '@modern-js/utils';
|
|
11
|
-
import webpackDevMiddleware from '@modern-js/
|
|
11
|
+
import webpackDevMiddleware from '@modern-js/utils/webpack-dev-middleware';
|
|
12
12
|
import { createProxyHandler, ModernServer, AGGRED_DIR } from '@modern-js/prod-server';
|
|
13
13
|
import { getDefaultDevOptions } from "../constants";
|
|
14
14
|
import { createMockHandler } from "../dev-tools/mock";
|
|
@@ -241,14 +241,30 @@ export class ModernDevServer extends ModernServer {
|
|
|
241
241
|
return this.setupDevMiddleware(compiler);
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
+
isClientCompiler(compiler) {
|
|
245
|
+
const {
|
|
246
|
+
target
|
|
247
|
+
} = compiler.options; // if target not contains `node`, it's a client compiler
|
|
248
|
+
|
|
249
|
+
if (target) {
|
|
250
|
+
if (Array.isArray(target)) {
|
|
251
|
+
return !target.includes('node');
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return target !== 'node';
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return compiler.name === 'client';
|
|
258
|
+
}
|
|
259
|
+
|
|
244
260
|
setupDevServerPlugin(compiler) {
|
|
245
261
|
const {
|
|
246
262
|
dev: devConf
|
|
247
|
-
} = this;
|
|
263
|
+
} = this; // apply dev server to client compiler, add hmr client to entry.
|
|
248
264
|
|
|
249
265
|
if (compiler.compilers) {
|
|
250
266
|
compiler.compilers.forEach(target => {
|
|
251
|
-
if (target
|
|
267
|
+
if (this.isClientCompiler(target)) {
|
|
252
268
|
new DevServerPlugin(devConf).apply(target);
|
|
253
269
|
}
|
|
254
270
|
});
|
package/dist/js/modern/types.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -9,16 +9,6 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
9
9
|
|
|
10
10
|
var _serverUtils = require("@modern-js/server-utils");
|
|
11
11
|
|
|
12
|
-
var _utils = require("@modern-js/utils");
|
|
13
|
-
|
|
14
|
-
var tsNode = _interopRequireWildcard(require("ts-node"));
|
|
15
|
-
|
|
16
|
-
var tsConfigPaths = _interopRequireWildcard(require("tsconfig-paths"));
|
|
17
|
-
|
|
18
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
-
|
|
20
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
-
|
|
22
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
13
|
|
|
24
14
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -29,71 +19,31 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
29
19
|
|
|
30
20
|
const registerDirs = ['./api', './server', './config/mock', './shared'];
|
|
31
21
|
|
|
32
|
-
const enableRegister = (projectRoot, config
|
|
33
|
-
) => {
|
|
22
|
+
const enableRegister = (projectRoot, config) => {
|
|
34
23
|
const TS_CONFIG_FILENAME = `tsconfig.json`;
|
|
35
24
|
|
|
36
25
|
const tsconfigPath = _path.default.resolve(projectRoot, TS_CONFIG_FILENAME);
|
|
37
26
|
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
paths = {},
|
|
50
|
-
absoluteBaseUrl = './'
|
|
51
|
-
} = aliasOption;
|
|
52
|
-
const tsPaths = Object.keys(paths).reduce((o, key) => {
|
|
53
|
-
let tsPath = paths[key]; // 要不要把对 modern 的判断去掉
|
|
54
|
-
|
|
55
|
-
if (typeof tsPath === 'string' && _path.default.isAbsolute(tsPath)) {
|
|
56
|
-
tsPath = _path.default.relative(absoluteBaseUrl, tsPath);
|
|
27
|
+
const babelConfig = (0, _serverUtils.resolveBabelConfig)(projectRoot, config, {
|
|
28
|
+
tsconfigPath,
|
|
29
|
+
syntax: 'es6+',
|
|
30
|
+
type: 'commonjs'
|
|
31
|
+
});
|
|
32
|
+
return require('@babel/register')(_objectSpread(_objectSpread({}, babelConfig), {}, {
|
|
33
|
+
only: [function (filePath) {
|
|
34
|
+
// TODO: wait params
|
|
35
|
+
// FIXME: 删除hardcode,根据 AppContext 中的 metaName 设置路径
|
|
36
|
+
if (filePath.includes(`node_modules${_path.default.sep}.modern-js`)) {
|
|
37
|
+
return true;
|
|
57
38
|
}
|
|
58
39
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}, {});
|
|
67
|
-
tsConfigPaths.register({
|
|
68
|
-
baseUrl: absoluteBaseUrl || './',
|
|
69
|
-
paths: tsPaths
|
|
70
|
-
});
|
|
71
|
-
tsNode.register({
|
|
72
|
-
project: tsconfigPath,
|
|
73
|
-
transpileOnly: true
|
|
74
|
-
});
|
|
75
|
-
} else {
|
|
76
|
-
const babelConfig = (0, _serverUtils.resolveBabelConfig)(projectRoot, config, {
|
|
77
|
-
tsconfigPath,
|
|
78
|
-
syntax: 'es6+',
|
|
79
|
-
type: 'commonjs'
|
|
80
|
-
});
|
|
81
|
-
return require('@babel/register')(_objectSpread(_objectSpread({}, babelConfig), {}, {
|
|
82
|
-
only: [function (filePath) {
|
|
83
|
-
// TODO: wait params
|
|
84
|
-
// FIXME: 删除hardcode,根据 AppContext 中的 metaName 设置路径
|
|
85
|
-
if (filePath.includes(`node_modules${_path.default.sep}.modern-js`)) {
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return registerDirs.some(registerDir => filePath.startsWith(_path.default.join(projectRoot, registerDir)));
|
|
90
|
-
}],
|
|
91
|
-
extensions: ['.js', '.ts'],
|
|
92
|
-
babelrc: false,
|
|
93
|
-
configFile: false,
|
|
94
|
-
root: projectRoot
|
|
95
|
-
}));
|
|
96
|
-
}
|
|
40
|
+
return registerDirs.some(registerDir => filePath.startsWith(_path.default.join(projectRoot, registerDir)));
|
|
41
|
+
}],
|
|
42
|
+
extensions: ['.js', '.ts'],
|
|
43
|
+
babelrc: false,
|
|
44
|
+
configFile: false,
|
|
45
|
+
root: projectRoot
|
|
46
|
+
}));
|
|
97
47
|
};
|
|
98
48
|
|
|
99
49
|
exports.enableRegister = enableRegister;
|
|
@@ -5,14 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _webpack = require("@modern-js/webpack");
|
|
9
|
-
|
|
10
8
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
9
|
|
|
12
|
-
const {
|
|
13
|
-
EntryPlugin
|
|
14
|
-
} = _webpack.webpack;
|
|
15
|
-
|
|
16
10
|
class DevServerPlugin {
|
|
17
11
|
constructor(options) {
|
|
18
12
|
_defineProperty(this, "options", void 0);
|
|
@@ -29,7 +23,7 @@ class DevServerPlugin {
|
|
|
29
23
|
const port = client.port ? `&port=${client.port}` : '';
|
|
30
24
|
const clientEntry = `${require.resolve("../hmr-client")}?${host}${path}${port}`; // use a hook to add entries if available
|
|
31
25
|
|
|
32
|
-
new EntryPlugin(compiler.context, clientEntry, {
|
|
26
|
+
new compiler.webpack.EntryPlugin(compiler.context, clientEntry, {
|
|
33
27
|
name: undefined
|
|
34
28
|
}).apply(compiler);
|
|
35
29
|
}
|
|
@@ -41,11 +35,14 @@ class DevServerPlugin {
|
|
|
41
35
|
|
|
42
36
|
|
|
43
37
|
const compilerOptions = compiler.options;
|
|
38
|
+
const {
|
|
39
|
+
HotModuleReplacementPlugin
|
|
40
|
+
} = compiler.webpack;
|
|
44
41
|
compilerOptions.plugins = compilerOptions.plugins || [];
|
|
45
42
|
|
|
46
|
-
if (!compilerOptions.plugins.find(p => p.constructor ===
|
|
43
|
+
if (!compilerOptions.plugins.find(p => p.constructor === HotModuleReplacementPlugin)) {
|
|
47
44
|
// apply the HMR plugin, if it didn't exist before.
|
|
48
|
-
const plugin = new
|
|
45
|
+
const plugin = new HotModuleReplacementPlugin();
|
|
49
46
|
plugin.apply(compiler);
|
|
50
47
|
}
|
|
51
48
|
}
|
|
@@ -14,6 +14,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
14
14
|
*
|
|
15
15
|
* Tips: this package will be bundled and running in the browser, do not import from the entry of @modern-js/utils.
|
|
16
16
|
*/
|
|
17
|
+
// TODO hadRuntimeError should be fixed.
|
|
17
18
|
// We need to keep track of if there has been a runtime error.
|
|
18
19
|
// Essentially, we cannot guarantee application state was not corrupted by the
|
|
19
20
|
// runtime error. To prevent confusing behavior, we forcibly reload the entire
|
|
@@ -177,11 +178,9 @@ function tryApplyUpdates() {
|
|
|
177
178
|
}
|
|
178
179
|
|
|
179
180
|
function handleApplyUpdates(err, updatedModules) {
|
|
180
|
-
|
|
181
|
-
const hasReactRefresh = process.env.FAST_REFRESH;
|
|
182
|
-
const wantsForcedReload = err || !updatedModules || hadRuntimeError; // React refresh can handle hot-reloading over errors.
|
|
181
|
+
const wantsForcedReload = err || !updatedModules || hadRuntimeError;
|
|
183
182
|
|
|
184
|
-
if (
|
|
183
|
+
if (wantsForcedReload) {
|
|
185
184
|
window.location.reload();
|
|
186
185
|
return;
|
|
187
186
|
}
|
|
@@ -13,7 +13,7 @@ var _https = require("https");
|
|
|
13
13
|
|
|
14
14
|
var _utils = require("@modern-js/utils");
|
|
15
15
|
|
|
16
|
-
var _webpackDevMiddleware = _interopRequireDefault(require("@modern-js/
|
|
16
|
+
var _webpackDevMiddleware = _interopRequireDefault(require("@modern-js/utils/webpack-dev-middleware"));
|
|
17
17
|
|
|
18
18
|
var _prodServer = require("@modern-js/prod-server");
|
|
19
19
|
|
|
@@ -268,14 +268,30 @@ class ModernDevServer extends _prodServer.ModernServer {
|
|
|
268
268
|
return this.setupDevMiddleware(compiler);
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
+
isClientCompiler(compiler) {
|
|
272
|
+
const {
|
|
273
|
+
target
|
|
274
|
+
} = compiler.options; // if target not contains `node`, it's a client compiler
|
|
275
|
+
|
|
276
|
+
if (target) {
|
|
277
|
+
if (Array.isArray(target)) {
|
|
278
|
+
return !target.includes('node');
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return target !== 'node';
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return compiler.name === 'client';
|
|
285
|
+
}
|
|
286
|
+
|
|
271
287
|
setupDevServerPlugin(compiler) {
|
|
272
288
|
const {
|
|
273
289
|
dev: devConf
|
|
274
|
-
} = this;
|
|
290
|
+
} = this; // apply dev server to client compiler, add hmr client to entry.
|
|
275
291
|
|
|
276
292
|
if (compiler.compilers) {
|
|
277
293
|
compiler.compilers.forEach(target => {
|
|
278
|
-
if (target
|
|
294
|
+
if (this.isClientCompiler(target)) {
|
|
279
295
|
new _devServerPlugin.default(devConf).apply(target);
|
|
280
296
|
}
|
|
281
297
|
});
|
package/dist/js/node/types.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { DevServerOptions } from '../types';
|
|
1
|
+
import type webpack from 'webpack';
|
|
2
|
+
import type { DevServerOptions } from '../types';
|
|
3
3
|
export default class DevServerPlugin {
|
|
4
4
|
private readonly options;
|
|
5
5
|
constructor(options: DevServerOptions);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Server } from 'http';
|
|
3
3
|
import ws from 'ws';
|
|
4
|
-
import type
|
|
5
|
-
import { DevServerOptions } from '../types';
|
|
4
|
+
import type webpack from 'webpack';
|
|
5
|
+
import type { DevServerOptions } from '../types';
|
|
6
6
|
export default class SocketServer {
|
|
7
7
|
private wsServer;
|
|
8
8
|
private readonly sockets;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
1
|
+
import type webpack from 'webpack';
|
|
2
|
+
import type { ModernServerOptions } from '@modern-js/prod-server';
|
|
3
3
|
export declare type DevServerOptions = {
|
|
4
4
|
client: {
|
|
5
5
|
path?: string;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.16.0-alpha.underfin.001",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -30,20 +30,18 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@babel/core": "^7.18.0",
|
|
32
32
|
"@babel/register": "^7.17.7",
|
|
33
|
-
"@modern-js/prod-server": "1.
|
|
34
|
-
"@modern-js/server-utils": "1.
|
|
35
|
-
"@modern-js/utils": "1.
|
|
36
|
-
"@modern-js/webpack": "1.15.0",
|
|
33
|
+
"@modern-js/prod-server": "1.16.0",
|
|
34
|
+
"@modern-js/server-utils": "1.16.0",
|
|
35
|
+
"@modern-js/utils": "1.16.0-alpha.underfin.001",
|
|
37
36
|
"devcert": "^1.2.2",
|
|
38
37
|
"minimatch": "^3.0.4",
|
|
39
38
|
"path-to-regexp": "^6.2.0",
|
|
40
|
-
"tsconfig-paths": "3.14.1",
|
|
41
39
|
"ws": "^8.2.0"
|
|
42
40
|
},
|
|
43
41
|
"devDependencies": {
|
|
44
|
-
"@modern-js/core": "1.
|
|
45
|
-
"@modern-js/server-core": "1.
|
|
46
|
-
"@modern-js/types": "1.
|
|
42
|
+
"@modern-js/core": "1.16.0",
|
|
43
|
+
"@modern-js/server-core": "1.16.0",
|
|
44
|
+
"@modern-js/types": "1.16.0",
|
|
47
45
|
"@scripts/build": "1.15.0",
|
|
48
46
|
"@scripts/jest-config": "1.15.0",
|
|
49
47
|
"@types/jest": "^27",
|
|
@@ -51,13 +49,9 @@
|
|
|
51
49
|
"@types/node": "^14",
|
|
52
50
|
"@types/ws": "^7.4.7",
|
|
53
51
|
"jest": "^27",
|
|
54
|
-
"ts-node": "^10.1.0",
|
|
55
52
|
"typescript": "^4",
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
},
|
|
59
|
-
"peerDependencies": {
|
|
60
|
-
"ts-node": "^10.1.0"
|
|
53
|
+
"websocket": "^1",
|
|
54
|
+
"webpack": "^5.71.0"
|
|
61
55
|
},
|
|
62
56
|
"sideEffects": false,
|
|
63
57
|
"modernConfig": {
|
|
@@ -67,8 +61,7 @@
|
|
|
67
61
|
},
|
|
68
62
|
"publishConfig": {
|
|
69
63
|
"registry": "https://registry.npmjs.org/",
|
|
70
|
-
"access": "public"
|
|
71
|
-
"types": "./dist/types/index.d.ts"
|
|
64
|
+
"access": "public"
|
|
72
65
|
},
|
|
73
66
|
"wireit": {
|
|
74
67
|
"build": {
|