@@ -147,6 +147,8 @@ var Project = function () {
147
147
} , {
148
148
key : 'fixCss' ,
149
149
value : function fixCss ( ) {
150
+ var _this2 = this ;
151
+
150
152
var config = this . config . getConfig ( ) ,
151
153
entries = config . entry ,
152
154
cssExtNames = config . entryExtNames . css ,
@@ -173,11 +175,13 @@ var Project = function () {
173
175
174
176
entryItem . forEach ( function ( cssPath , i ) {
175
177
var originCssPath = sysPath . join ( config . context , cssPath ) ;
176
- fs . appendFileSync ( cacheFilePath , 'require("' + sysPath . relative ( sysPath . dirname ( cacheFilePath ) , originCssPath ) + '");' , 'utf-8' ) ;
178
+ var requiredPath = _this2 . _normalizePath ( sysPath . relative ( sysPath . dirname ( cacheFilePath ) , originCssPath ) ) ;
179
+ fs . appendFileSync ( cacheFilePath , 'require("' + requiredPath + '");' , 'utf-8' ) ;
177
180
} ) ;
178
181
} else {
179
182
var originCssPath = sysPath . join ( config . context , entry ) ;
180
- fs . writeFileSync ( cacheFilePath , 'require("' + sysPath . relative ( sysPath . dirname ( cacheFilePath ) , originCssPath ) + '");' , 'utf-8' ) ;
183
+ var requiredPath = _this2 . _normalizePath ( sysPath . relative ( sysPath . dirname ( cacheFilePath ) , originCssPath ) ) ;
184
+ fs . writeFileSync ( cacheFilePath , 'require("' + requiredPath + '");' , 'utf-8' ) ;
181
185
}
182
186
183
187
fps . push ( cacheFilePath ) ;
@@ -232,7 +236,7 @@ var Project = function () {
232
236
} , {
233
237
key : 'pack' ,
234
238
value : function pack ( opt , callback ) {
235
- var _this2 = this ;
239
+ var _this3 = this ;
236
240
237
241
var config = this . config . getConfig ( ) ;
238
242
@@ -249,7 +253,7 @@ var Project = function () {
249
253
config . output = config . output . dev ;
250
254
}
251
255
252
- _this2 . fixCss ( ) ;
256
+ _this3 . fixCss ( ) ;
253
257
254
258
if ( opt . sourcemap ) {
255
259
config . devtool = opt . sourcemap ;
@@ -294,7 +298,7 @@ var Project = function () {
294
298
}
295
299
} ) ;
296
300
info ( ) ;
297
- _this2 . packCallbacks . forEach ( function ( cb ) {
301
+ _this3 . packCallbacks . forEach ( function ( cb ) {
298
302
return cb ( opt , stats ) ;
299
303
} ) ;
300
304
}
@@ -305,9 +309,9 @@ var Project = function () {
305
309
306
310
if ( opt . lint ) {
307
311
async . series ( [ function ( callback ) {
308
- return _this2 . lint ( callback ) ;
312
+ return _this3 . lint ( callback ) ;
309
313
} , function ( callback ) {
310
- return _this2 . lintCss ( callback ) ;
314
+ return _this3 . lintCss ( callback ) ;
311
315
} ] , function ( err , results ) {
312
316
if ( ! err ) {
313
317
if ( results [ 0 ] && results [ 1 ] ) {
@@ -361,6 +365,18 @@ var Project = function () {
361
365
return sysPath . resolve ( context , lintPathItem ) ;
362
366
} ) ;
363
367
}
368
+ } , {
369
+ key : '_normalizePath' ,
370
+ value : function _normalizePath ( str , stripTrailing ) {
371
+ if ( typeof str !== 'string' ) {
372
+ throw new TypeError ( 'expected a string' ) ;
373
+ }
374
+ str = str . replace ( / [ \\ \/ ] + / g, '/' ) ;
375
+ if ( stripTrailing !== false ) {
376
+ str = str . replace ( / \/ $ / , '' ) ;
377
+ }
378
+ return str ;
379
+ }
364
380
} ] ) ;
365
381
366
382
return Project ;
0 commit comments