Skip to content

Commit 66c8dc8

Browse files
author
xylona.lxy
committed
fix: devServerConfig, localhost
1 parent bf0a6ac commit 66c8dc8

File tree

6 files changed

+31
-13
lines changed

6 files changed

+31
-13
lines changed

src/built-in-plugins/command-bundle/plugin/command-bundle.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const commandBundle = async (opts: IOpts = {}) => {
4444
mode: opts.mode ?? 'development',
4545
outFileName: pri.sourceConfig.bundleFileName,
4646
devServerPort: freePort,
47-
publicPath: `https://localhost:${freePort}`,
47+
publicPath: `https://${pri.sourceConfig.devHost || 'localhost'}:${freePort}`,
4848
jsOnly: true,
4949
entryPath: path.join(pri.sourceRoot, path.format(componentEntry)),
5050
pipeConfig: async config => {
@@ -66,7 +66,9 @@ export const commandBundle = async (opts: IOpts = {}) => {
6666
);
6767

6868
const dllHttpPath = urlJoin(
69-
`${globalState.sourceConfig.useHttps ? 'https' : 'http'}://localhost:${freePort}`,
69+
`${globalState.sourceConfig.useHttps ? 'https' : 'http'}://${
70+
pri.sourceConfig.devHost || 'localhost'
71+
}:${freePort}`,
7072
libraryStaticPath,
7173
);
7274

src/built-in-plugins/command-dev/plugin/dashboard/client/pages/layout.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react';
2+
import { componentEntry, pri } from '../../../../../../node';
23
import * as io from 'socket.io-client';
34
import { IProjectStatus } from '../../server/project-status-interface';
45
import { MainComponent } from './main/main';
@@ -23,7 +24,7 @@ export const LayoutComponent = React.memo(() => {
2324
const socket = React.useRef<SocketIOClient.Socket>(null);
2425

2526
React.useEffect(() => {
26-
socket.current = io(`//localhost:${(window as any).serverPort}`);
27+
socket.current = io(`//${pri.sourceConfig.devHost || 'localhost'}:${(window as any).serverPort}`);
2728

2829
// Get init project status
2930
socket.current.emit('getProjectStatus');

src/built-in-plugins/command-dev/plugin/project-dev.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ async function debugProject(options?: any) {
6969

7070
const pipeConfig = async (config: webpack.Configuration) => {
7171
const dllHttpPath = urlJoin(
72-
`${globalState.sourceConfig.useHttps ? 'https' : 'http'}://localhost:${freePort}`,
72+
`${globalState.sourceConfig.useHttps ? 'https' : 'http'}://${
73+
pri.sourceConfig.devHost || 'localhost'
74+
}:${freePort}`,
7375
libraryStaticPath,
7476
);
7577

@@ -280,7 +282,7 @@ function debugProjectPrepare(dashboardClientPort: number) {
280282
// Add dashboard iframe
281283
const dashboardIframe = document.createElement("iframe")
282284
dashboardIframe.id = "pri-help-iframe"
283-
dashboardIframe.src = "//localhost:${dashboardClientPort}"
285+
dashboardIframe.src = "//${pri.sourceConfig.devHost || 'localhost'}:${dashboardClientPort}"
284286
document.body.appendChild(dashboardIframe)
285287
286288
// Add dashboard button

src/built-in-plugins/command-docs/plugin/dev-docs.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ export async function devDocs() {
4242

4343
await runWebpackDevServer({
4444
mode: 'development',
45-
publicPath: `${pri.sourceConfig.useHttps ? 'https' : 'http'}://localhost:${freePort}`,
45+
publicPath: `${pri.sourceConfig.useHttps ? 'https' : 'http'}://${
46+
pri.sourceConfig.devHost || 'localhost'
47+
}:${freePort}`,
4648
autoOpenBrowser: true,
4749
hot: pri.sourceConfig.hotReload,
48-
devUrl: 'localhost',
50+
devUrl: pri.sourceConfig.devHost || 'localhost',
4951
entryPath: docsEntryPath,
5052
devServerPort: freePort,
5153
htmlTemplatePath: path.join(__dirname, '../../../../template-project.ejs'),

src/built-in-plugins/command-preview/plugin/run-preview.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ export const CommandPreview = async () => {
5757
} else {
5858
open(
5959
ensureEndWithSlash(
60-
urlJoin(`${pri.sourceConfig.useHttps ? 'https' : 'http'}://localhost:${freePort}`, pri.sourceConfig.baseHref),
60+
urlJoin(
61+
`${pri.sourceConfig.useHttps ? 'https' : 'http'}://${pri.sourceConfig.devHost || 'localhost'}:${freePort}`,
62+
pri.sourceConfig.baseHref,
63+
),
6164
),
6265
);
6366
}

src/utils/webpack-dev-server.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ import { globalState } from './global-state';
1616
import { tempPath } from './structor-config';
1717
import { logInfo } from './log';
1818
import { getWebpackConfig, IOptions } from './webpack-config';
19+
import { pri } from '../node';
1920

2021
const smp = new SpeedMeasurePlugin();
2122

2223
interface IExtraOptions {
2324
pipeConfig?: (config?: webpack.Configuration) => Promise<webpack.Configuration>;
25+
pipeDevServerConfig?: (config?: WebpackDevServer.Configuration) => Promise<webpack.Configuration>;
2426
devServerPort: number;
2527
publicPath: string;
2628
jsOnly?: boolean;
@@ -74,8 +76,8 @@ export const runWebpackDevServer = async (opts: IOptions<IExtraOptions>) => {
7476
);
7577
}
7678

77-
const webpackDevServerConfig: WebpackDevServer.Configuration = {
78-
host: 'localhost',
79+
let webpackDevServerConfig: WebpackDevServer.Configuration = {
80+
host: pri.sourceConfig.devHost || 'localhost',
7981
hot: opts.hot,
8082
hotOnly: opts.hot,
8183
publicPath: opts.publicPath,
@@ -113,6 +115,10 @@ export const runWebpackDevServer = async (opts: IOptions<IExtraOptions>) => {
113115
port: opts.devServerPort,
114116
} as any;
115117

118+
if (opts.pipeDevServerConfig) {
119+
webpackDevServerConfig = await opts.pipeDevServerConfig(webpackDevServerConfig);
120+
}
121+
116122
WebpackDevServer.addDevServerEntrypoints(webpackConfig as any, webpackDevServerConfig);
117123

118124
if (yargs.argv.measureSpeed) {
@@ -123,14 +129,16 @@ export const runWebpackDevServer = async (opts: IOptions<IExtraOptions>) => {
123129

124130
const devServer = new WebpackDevServer(compiler as any, webpackDevServerConfig);
125131

126-
devServer.listen(opts.devServerPort, 'localhost', () => {
132+
const host = pri.sourceConfig.devHost || webpackDevServerConfig.host || 'localhost';
133+
134+
devServer.listen(opts.devServerPort, host, () => {
127135
let devUrl: string = null;
128136
const localSuggestUrl = urlJoin(
129-
`${opts.https || globalState.sourceConfig.useHttps ? 'https' : 'http'}://localhost:${opts.devServerPort}`,
137+
`${opts.https || globalState.sourceConfig.useHttps ? 'https' : 'http'}://${host}:${opts.devServerPort}`,
130138
globalState.sourceConfig.baseHref,
131139
);
132140

133-
if (opts.devUrl === 'localhost') {
141+
if (opts.devUrl === host) {
134142
devUrl = localSuggestUrl;
135143
} else if (opts.devUrl !== undefined) {
136144
({ devUrl } = opts);

0 commit comments

Comments
 (0)