File tree Expand file tree Collapse file tree 5 files changed +35
-29
lines changed Expand file tree Collapse file tree 5 files changed +35
-29
lines changed Original file line number Diff line number Diff line change @@ -10,9 +10,7 @@ var plugin = require("browserify-postcss")
10
10
11
11
var tr = plugin (" fake.css" , {
12
12
plugin: " postcss-simple-vars" ,
13
- resolve: {
14
- basedir: __dirname
15
- }
13
+ basedir: __dirname
16
14
})
17
15
tr .end (" $color: red; .fake { color: $color; }" )
18
16
tr .pipe (process .stdout )
@@ -37,17 +35,4 @@ Default: `null`
37
35
38
36
postcss plugins used to transform the content
39
37
40
- #### options
41
-
42
- Type: ` Object `
43
- Default: ` null `
44
-
45
- options for postcss plugins specified by ` opts.plugin `
46
-
47
- #### resolve
48
-
49
- Type: ` Object|Function `
50
- Default: ` null `
51
-
52
- If ` Object ` , will be passed to [ resolve.sync] ( https://github.com/substack/node-resolve#resolvesyncid-opts ) to resolve the plugins.
53
- If ` Function ` , will be used instead of [ resolve.sync] ( https://github.com/substack/node-resolve#resolvesyncid-opts )
38
+ If ` Array ` , each element can be ` String ` , ` Function ` , or ` Array ` .
Original file line number Diff line number Diff line change @@ -2,9 +2,7 @@ var plugin = require("..")
2
2
3
3
var tr = plugin ( "fake.css" , {
4
4
plugin : "postcss-simple-vars" ,
5
- resolve : {
6
- basedir : __dirname
7
- }
5
+ basedir : __dirname
8
6
} )
9
7
tr . end ( "$color: red; .fake { color: $color; }" )
10
8
tr . pipe ( process . stdout )
Original file line number Diff line number Diff line change 1
- var Processor = require ( "postcss-processor" )
2
1
var sink = require ( "sink-transform" )
2
+ var resolve = require ( "resolve" )
3
+ var postcss = require ( "postcss" )
3
4
4
5
var processor
5
6
module . exports = function ( file , opts ) {
6
7
opts = opts || { }
7
8
if ( ! processor ) {
8
- processor = Processor ( opts . plugin , opts . options , opts . resolve )
9
+ processor = getProcessor ( opts )
9
10
}
10
- return sink . str ( function ( body , done ) {
11
+ var stream = sink . str ( function ( body , done ) {
11
12
var self = this
12
13
processor . process ( body , { from : file } )
13
14
. then ( function ( result ) {
14
15
self . push ( result . css )
15
16
done ( )
17
+ } , function ( err ) {
18
+ stream . emit ( "error" , err )
16
19
} )
17
20
} )
21
+ return stream
22
+ }
23
+
24
+ function getProcessor ( opts ) {
25
+ var plugins = [ ] . concat ( opts . plugin ) . filter ( Boolean )
26
+ plugins = plugins . map ( function ( p ) {
27
+ var op
28
+ if ( Array . isArray ( p ) ) {
29
+ op = p [ 1 ]
30
+ p = p [ 0 ]
31
+ }
32
+ if ( typeof p !== "function" ) {
33
+ var pfile = resolve . sync ( String ( p ) , { basedir : opts . basedir || process . cwd ( ) } )
34
+ p = require ( pfile )
35
+ }
36
+ return p ( op )
37
+ } )
38
+
39
+ return postcss ( plugins . concat (
40
+ opts . processor && opts . processor . plugins || [ ]
41
+ ) )
18
42
}
Original file line number Diff line number Diff line change 21
21
},
22
22
"homepage" : " https://github.com/zoubin/browserify-postcss#readme" ,
23
23
"dependencies" : {
24
- "postcss-processor" : " ^0.1.0" ,
24
+ "postcss" : " ^4.1.11" ,
25
+ "resolve" : " ^1.1.6" ,
25
26
"sink-transform" : " ^0.1.2"
26
27
},
27
28
"devDependencies" : {
Original file line number Diff line number Diff line change 1
- var processor = require ( ".." )
1
+ var plugin = require ( ".." )
2
2
var sink = require ( "sink-transform" )
3
3
var test = require ( "tape" )
4
4
5
5
test ( 'transform' , function ( t ) {
6
6
t . plan ( 1 )
7
- var tr = processor ( "fake.css" , {
7
+ var tr = plugin ( "fake.css" , {
8
8
plugin : "postcss-simple-vars" ,
9
- resolve : {
10
- basedir : __dirname
11
- }
9
+ basedir : __dirname
12
10
} )
13
11
tr . end ( "$color: red; .fake { color: $color; }" )
14
12
tr . pipe ( sink . str ( function ( body ) {
You can’t perform that action at this time.
0 commit comments