akfun 3.2.11 → 3.2.12
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/package.json +1 -1
- package/src/dev-server.js +39 -45
package/package.json
CHANGED
package/src/dev-server.js
CHANGED
|
@@ -5,6 +5,7 @@ const https = require('https');
|
|
|
5
5
|
const fs = require('fs');
|
|
6
6
|
const express = require('express');
|
|
7
7
|
const webpack = require('webpack');
|
|
8
|
+
const portfinder = require('portfinder');
|
|
8
9
|
const checkVersion = require('./check-versions');
|
|
9
10
|
const { createProxyMiddleware } = require('http-proxy-middleware');
|
|
10
11
|
const { resolve } = require('./utils/pathUtils');
|
|
@@ -95,52 +96,33 @@ module.exports = function (akfunConfig, _consoleTag) {
|
|
|
95
96
|
// handle fallback for HTML5 history API
|
|
96
97
|
app.use(require('connect-history-api-fallback')());
|
|
97
98
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const readyPromise = new Promise((resolve, reject) => {
|
|
101
|
-
_resolve = resolve;
|
|
102
|
-
_reject = reject;
|
|
103
|
-
});
|
|
99
|
+
const afterCreateServerAction = (isHttps, port) => {
|
|
100
|
+
spinner.succeed(`${consoleTag}调试模式已开启!`);
|
|
104
101
|
|
|
105
|
-
|
|
106
|
-
const portfinder = require('portfinder');
|
|
107
|
-
portfinder.basePort = port;
|
|
102
|
+
process.env.PORT = port;
|
|
108
103
|
|
|
109
|
-
|
|
104
|
+
const uri = isHttps
|
|
105
|
+
? `https://${config.dev.hostname}`
|
|
106
|
+
: `http://${config.dev.hostname}:${port}`;
|
|
110
107
|
|
|
111
|
-
|
|
108
|
+
console.log(`> Listening at ${uri}\n`);
|
|
112
109
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const projPath = `${uri}${webpackConfig.output.publicPath}`;
|
|
128
|
-
let entryConfig = webpackConfig.entry || {}; // 获取构建入口配置
|
|
129
|
-
const entryFiles = (entryConfig && Object.keys(entryConfig)) || [];
|
|
130
|
-
if (entryFiles.length > 0) {
|
|
131
|
-
// 获取第一个入口文件
|
|
132
|
-
const filename = entryFiles[0];
|
|
133
|
-
console.info(
|
|
134
|
-
`当前运行脚本:\n ${projPath}${filename}.js\n当前运行样式[可能不存在]:\n${projPath}${filename}.css`
|
|
135
|
-
);
|
|
136
|
-
// 是否自动打开浏览器并跳转到第一个入口页面
|
|
137
|
-
if (!config.dev.closeHtmlWebpackPlugin && autoOpenBrowser) {
|
|
138
|
-
open(`${projPath}${filename}.html`, { wait: true });
|
|
139
|
-
}
|
|
110
|
+
// 打印当前环境中的首个html和css地址
|
|
111
|
+
const projPath = `${uri}${webpackConfig.output.publicPath}`;
|
|
112
|
+
|
|
113
|
+
let entryConfig = webpackConfig.entry || {}; // 获取构建入口配置
|
|
114
|
+
const entryFiles = (entryConfig && Object.keys(entryConfig)) || [];
|
|
115
|
+
if (entryFiles.length > 0) {
|
|
116
|
+
// 获取第一个入口文件
|
|
117
|
+
const filename = entryFiles[0];
|
|
118
|
+
console.info(
|
|
119
|
+
`当前运行脚本:\n ${projPath}${filename}.js\n当前运行样式[可能不存在]:\n${projPath}${filename}.css`
|
|
120
|
+
);
|
|
121
|
+
// 是否自动打开浏览器并跳转到第一个入口页面
|
|
122
|
+
if (!config.dev.closeHtmlWebpackPlugin && autoOpenBrowser) {
|
|
123
|
+
open(`${projPath}${filename}.html`, { wait: true });
|
|
140
124
|
}
|
|
141
|
-
|
|
142
|
-
_resolve();
|
|
143
|
-
});
|
|
125
|
+
}
|
|
144
126
|
};
|
|
145
127
|
|
|
146
128
|
if (config.dev.https) {
|
|
@@ -153,11 +135,23 @@ module.exports = function (akfunConfig, _consoleTag) {
|
|
|
153
135
|
|
|
154
136
|
var httpsServer = https.createServer(sslOptions, app);
|
|
155
137
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
138
|
+
devMiddleware.waitUntilValid(() => {
|
|
139
|
+
httpsServer.listen(443, () => {
|
|
140
|
+
afterCreateServerAction(true, port);
|
|
141
|
+
});
|
|
159
142
|
});
|
|
160
143
|
} else {
|
|
161
|
-
|
|
144
|
+
portfinder.basePort = port;
|
|
145
|
+
devMiddleware.waitUntilValid(() => {
|
|
146
|
+
portfinder.getPort((err, port) => {
|
|
147
|
+
if (err) {
|
|
148
|
+
_reject(err);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
app.listen(port, () => {
|
|
152
|
+
afterCreateServerAction(false, port);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
});
|
|
162
156
|
}
|
|
163
157
|
};
|