File tree 3 files changed +61
-5
lines changed
3 files changed +61
-5
lines changed Original file line number Diff line number Diff line change 1
1
var cssnext = require ( "cssnext" )
2
2
var assign = require ( "object-assign" )
3
+ var loaderUtils = require ( "loader-utils" )
3
4
4
- function cssnextLoader ( contents ) {
5
+ function defaultOptions ( context , map ) {
6
+ var options = { }
7
+ options . from = loaderUtils . getRemainingRequest ( context )
8
+ options . to = loaderUtils . getRemainingRequest ( context )
9
+ if ( context . sourceMap ) {
10
+ options . map = {
11
+ inline : false ,
12
+ annotation : false ,
13
+ prev : map
14
+ }
15
+ }
16
+ options . compress = context . minimize
17
+ return options
18
+ }
19
+
20
+ function cssnextLoader ( contents , map ) {
5
21
this . cacheable ( )
6
- var options = assign ( { } , this . options . cssnext )
22
+ var options = assign ( { } , defaultOptions ( this , map ) , this . options . cssnext )
7
23
options . features = assign ( { } , this . options . cssnext ? this . options . cssnext . features : null )
8
24
options . features . import = assign ( { } , options . features . import || null )
9
25
options . features . import . onImport = function ( files ) {
10
26
files . forEach ( this . addDependency )
11
27
} . bind ( this )
12
28
try {
13
- return cssnext ( contents , options )
29
+ var result = cssnext ( contents , options )
30
+ if ( result . css ) {
31
+ this . callback ( null , result . css , result . map )
32
+ } else {
33
+ return result
34
+ }
14
35
} catch ( err ) {
15
36
this . emitError ( err )
16
37
}
Original file line number Diff line number Diff line change 4
4
"description" : " webpack loader for cssnext" ,
5
5
"main" : " index.js" ,
6
6
"scripts" : {
7
- "start" : " npm install && npm test" ,
7
+ "start" : " npm install && npm test" ,
8
8
"test" : " tape test/**.js"
9
9
},
10
10
"repository" : {
25
25
"homepage" : " https://github.com/cssnext/cssnext-loader" ,
26
26
"dependencies" : {
27
27
"cssnext" : " ^0.6.0" ,
28
+ "loader-utils" : " ^0.2.5" ,
28
29
"object-assign" : " ^2.0.0"
29
30
},
30
31
"devDependencies" : {
Original file line number Diff line number Diff line change @@ -24,8 +24,42 @@ tape("cssnext-loader", function(test){
24
24
file += chunk
25
25
} )
26
26
. on ( "end" , function ( ) {
27
- test . equal ( / c o l o r \s * : \s * r e d / . test ( file ) , true )
27
+ test . ok ( / c o l o r \s * : \s * r e d / . test ( file ) , "css transformed" )
28
+ test . notOk ( / # s o u r c e M a p p i n g U R L = .* \s * $ / . test ( file ) , "source map annotation not added" )
28
29
test . end ( )
29
30
} )
30
31
} )
31
32
} )
33
+
34
+ tape ( "cssnext-loader source maps" , function ( test ) {
35
+ webpack ( {
36
+ entry : "./test/fixtures/index.js" ,
37
+ output : {
38
+ path : "./test/output/" ,
39
+ filename : "bundle.js"
40
+ } ,
41
+ debug : true ,
42
+ devtool : 'source-map' ,
43
+ cssnext : {
44
+ features : {
45
+ import : {
46
+ path : [ "test/fixtures/" ]
47
+ }
48
+ }
49
+ }
50
+ } , function ( err , stat ) {
51
+ var file = ""
52
+ test . plan ( 3 )
53
+ fs . createReadStream ( "test/output/bundle.js" )
54
+ . on ( "data" , function ( chunk ) {
55
+ file += chunk
56
+ } )
57
+ . on ( "end" , function ( ) {
58
+ test . ok ( / c o l o r \s * : \s * r e d / . test ( file ) , "css transformed" )
59
+ test . ok ( / # s o u r c e M a p p i n g U R L = .* \s * $ / . test ( file ) , "source map annotation added" )
60
+ } )
61
+ fs . exists ( "test/output/bundle.js.map" , function ( exists ) {
62
+ test . ok ( exists , "source map exists" )
63
+ } )
64
+ } )
65
+ } )
You can’t perform that action at this time.
0 commit comments