@@ -56,9 +56,9 @@ exports.run = (options) => {
56
56
app . use ( ( req , res , next ) => {
57
57
const extName = sysPath . extname ( req . url ) ;
58
58
59
- if ( extName === '.js' ) {
59
+ if ( extName === '.js' ) {
60
60
res . setHeader ( 'Content-Type' , 'application/javascript' ) ;
61
- } else if ( extName === '.css' ) {
61
+ } else if ( extName === '.css' ) {
62
62
res . setHeader ( 'Content-Type' , 'text/css; charset=UTF-8' ) ;
63
63
}
64
64
@@ -168,13 +168,15 @@ exports.run = (options) => {
168
168
169
169
// 处理prd资源
170
170
if ( keys [ 2 ] === 'prd' ) {
171
+ const rquery = / \? .+ $ / ;
172
+ const rversion = / @ [ \d \w ] + (? = \. \w + $ ) / ;
171
173
// 去掉 query & 版本号
172
- const requestUrl = keys . slice ( 3 ) . join ( '/' ) . replace ( / \? [ \w = & ] + $ / , '' ) . replace ( '.map' , '' ) ;
174
+ const requestUrl = keys . slice ( 3 ) . join ( '/' ) . replace ( rquery , '' ) . replace ( '.map' , '' ) ;
173
175
174
176
// 只编译所请求的资源
175
177
if ( ! isCompilingAll ) {
176
178
177
- let requestUrlNoVer = requestUrl . replace ( / @ [ \d \w ] + (? = \. \w + $ ) / , '' ) ;
179
+ let requestUrlNoVer = requestUrl . replace ( rversion , '' ) ;
178
180
179
181
// 从编译 cache 中取,map 文件不必生成重复 compiler TODO
180
182
const cacheId = sysPath . join ( projectName , requestUrlNoVer ) ;
@@ -219,7 +221,7 @@ exports.run = (options) => {
219
221
if ( sysPath . normalize ( entryPath ) === sysPath . normalize ( requestUrl ) ) {
220
222
isRequestingEntry = true ;
221
223
} else if ( sysPath . normalize ( entryPath ) === sysPath . normalize ( requestUrlNoVer ) ) {
222
- req . url = req . url . replace ( / @ [ \d \w ] + (? = \. \w + $ ) / , '' ) ;
224
+ req . url = req . url . replace ( rversion , '' ) ;
223
225
isRequestingEntry = true ;
224
226
}
225
227
@@ -242,7 +244,7 @@ exports.run = (options) => {
242
244
if ( promiseCache [ projectName ] ) {
243
245
Promise . all ( promiseCache [ projectName ] ) . then ( function ( ) {
244
246
// 统一去掉版本号
245
- req . url = req . url . replace ( / @ [ \d \w ] + (? = \. \w + $ ) / , '' ) ;
247
+ req . url = req . url . replace ( rquery , '' ) . replace ( rversion , '' ) ;
246
248
next ( ) ;
247
249
} ) ;
248
250
} else {
@@ -251,6 +253,7 @@ exports.run = (options) => {
251
253
}
252
254
} , 100 ) ;
253
255
} else {
256
+ req . url = req . url . replace ( rquery , '' ) . replace ( rversion , '' ) ;
254
257
// 生成该请求的 promiseCache
255
258
let resolve = null ;
256
259
let reject = null ;
@@ -369,11 +372,11 @@ exports.run = (options) => {
369
372
370
373
let servers = [ ] ;
371
374
372
- servers . push ( extend ( http . createServer ( app ) , { _port : port } ) ) ;
375
+ servers . push ( extend ( http . createServer ( app ) , { _port : port } ) ) ;
373
376
if ( isHttps ) {
374
- const globalConfig = JSON . parse ( fs . readFileSync ( YKIT_RC , { encoding : 'utf8' } ) ) ;
377
+ const globalConfig = JSON . parse ( fs . readFileSync ( YKIT_RC , { encoding : 'utf8' } ) ) ;
375
378
376
- if ( ! globalConfig [ 'https-key' ] || ! globalConfig [ 'https-crt' ] ) {
379
+ if ( ! globalConfig [ 'https-key' ] || ! globalConfig [ 'https-crt' ] ) {
377
380
warn ( '缺少 https 证书/秘钥配置,请使用以下命令设置:' ) ;
378
381
! globalConfig [ 'https-key' ] && warn ( 'ykit config set https-key <path-to-your-key>' ) ;
379
382
! globalConfig [ 'https-crt' ] && warn ( 'ykit config set https-crt <path-to-your-crt>' ) ;
@@ -384,7 +387,7 @@ exports.run = (options) => {
384
387
key : fs . readFileSync ( globalConfig [ 'https-key' ] ) ,
385
388
cert : fs . readFileSync ( globalConfig [ 'https-crt' ] )
386
389
} ;
387
- servers . push ( extend ( https . createServer ( httpsOpts , app ) , { _port : '443' , _isHttps : true } ) ) ;
390
+ servers . push ( extend ( https . createServer ( httpsOpts , app ) , { _port : '443' , _isHttps : true } ) ) ;
388
391
}
389
392
390
393
servers . forEach ( ( server ) => {
@@ -398,8 +401,8 @@ exports.run = (options) => {
398
401
} ) ;
399
402
server . listen ( server . _port , ( ) => {
400
403
const serverUrl = ( server . _isHttps ? 'https' : 'http' )
401
- + '://127.0.0.1:'
402
- + server . _port ;
404
+ + '://127.0.0.1:'
405
+ + server . _port ;
403
406
404
407
! server . _isHttps && log ( 'Starting up server, serving at: ' + options . cwd ) ;
405
408
log ( 'Available on: ' + serverUrl . underline ) ;
0 commit comments