Skip to content

Commit 8fc1ccc

Browse files
committed
fix(server): modify publicPath replacing to shutdown
1 parent 1eca064 commit 8fc1ccc

File tree

2 files changed

+36
-36
lines changed

2 files changed

+36
-36
lines changed

lib/commands/server.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -203,27 +203,27 @@ exports.run = function (options) {
203203
return;
204204
}
205205

206-
// 修改 publicPath 为当前服务
207-
if (project.config.replacingPublicPath !== false) {
208-
var localPublicPath = wpConfig.output.local.publicPath;
209-
var hostReg = /(http:|https:)?(\/\/)([^\/]+)/i;
210-
if (localPublicPath && localPublicPath.match(hostReg).length === 4) {
211-
localPublicPath = '/' + UtilPath.normalize(localPublicPath, false);
212-
localPublicPath = localPublicPath.replace(hostReg, function (matches, httpStr, splitStr, host) {
213-
httpStr = httpStr || '';
214-
return httpStr + '//' + '127.0.0.1:' + port;
215-
});
206+
// hot reload
207+
if (hot) {
208+
// 修改 publicPath 为当前服务
209+
if (project.config.replacingPublicPath !== false) {
210+
var localPublicPath = wpConfig.output.local.publicPath;
211+
var hostReg = /(http:|https:)?(\/\/)([^\/]+)/i;
212+
if (localPublicPath && localPublicPath.match(hostReg).length === 4) {
213+
localPublicPath = '/' + UtilPath.normalize(localPublicPath, false);
214+
localPublicPath = localPublicPath.replace(hostReg, function (matches, httpStr, splitStr, host) {
215+
httpStr = httpStr || '';
216+
return httpStr + '//' + '127.0.0.1:' + port;
217+
});
216218

217-
wpConfig.output.local.publicPath = localPublicPath;
218-
} else {
219-
// hot 且 未指定 publicPath 需要手动设置方式 hot.json 404
220-
var relativePath = sysPath.relative(projectCwd, wpConfig.output.local.path);
221-
wpConfig.output.local.publicPath = '/' + projectName + '/' + relativePath + '/';
219+
wpConfig.output.local.publicPath = localPublicPath;
220+
} else {
221+
// hot 且 未指定 publicPath 需要手动设置方式 hot.json 404
222+
var relativePath = sysPath.relative(projectCwd, wpConfig.output.local.path);
223+
wpConfig.output.local.publicPath = '/' + projectName + '/' + relativePath + '/';
224+
}
222225
}
223-
}
224226

225-
// hot reload
226-
if (hot) {
227227
wpConfig.plugins.push(new webpack.HotModuleReplacementPlugin());
228228

229229
if (!usingHotServer) {

src/commands/server.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -199,27 +199,27 @@ exports.run = (options) => {
199199
return;
200200
}
201201

202-
// 修改 publicPath 为当前服务
203-
if(project.config.replacingPublicPath !== false) {
204-
let localPublicPath = wpConfig.output.local.publicPath;
205-
const hostReg = /(http:|https:)?(\/\/)([^\/]+)/i;
206-
if(localPublicPath && localPublicPath.match(hostReg).length === 4) {
207-
localPublicPath = '/' + UtilPath.normalize(localPublicPath, false);
208-
localPublicPath = localPublicPath.replace(hostReg, (matches, httpStr, splitStr, host) => {
209-
httpStr = httpStr || '';
210-
return httpStr + '//' + '127.0.0.1:' + port;
211-
});
202+
// hot reload
203+
if(hot) {
204+
// 修改 publicPath 为当前服务
205+
if(project.config.replacingPublicPath !== false) {
206+
let localPublicPath = wpConfig.output.local.publicPath;
207+
const hostReg = /(http:|https:)?(\/\/)([^\/]+)/i;
208+
if(localPublicPath && localPublicPath.match(hostReg).length === 4) {
209+
localPublicPath = '/' + UtilPath.normalize(localPublicPath, false);
210+
localPublicPath = localPublicPath.replace(hostReg, (matches, httpStr, splitStr, host) => {
211+
httpStr = httpStr || '';
212+
return httpStr + '//' + '127.0.0.1:' + port;
213+
});
212214

213-
wpConfig.output.local.publicPath = localPublicPath;
214-
} else {
215-
// hot 且 未指定 publicPath 需要手动设置方式 hot.json 404
216-
const relativePath = sysPath.relative(projectCwd, wpConfig.output.local.path);
217-
wpConfig.output.local.publicPath = `/${projectName}/${relativePath}/`;
215+
wpConfig.output.local.publicPath = localPublicPath;
216+
} else {
217+
// hot 且 未指定 publicPath 需要手动设置方式 hot.json 404
218+
const relativePath = sysPath.relative(projectCwd, wpConfig.output.local.path);
219+
wpConfig.output.local.publicPath = `/${projectName}/${relativePath}/`;
220+
}
218221
}
219-
}
220222

221-
// hot reload
222-
if(hot) {
223223
wpConfig.plugins.push(new webpack.HotModuleReplacementPlugin());
224224

225225
if(!usingHotServer) {

0 commit comments

Comments
 (0)