File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,9 +10,7 @@ var plugin = require("browserify-postcss")
1010
1111var tr = plugin (" fake.css" , {
1212 plugin: " postcss-simple-vars" ,
13- resolve: {
14- basedir: __dirname
15- }
13+ basedir: __dirname
1614})
1715tr .end (" $color: red; .fake { color: $color; }" )
1816tr .pipe (process .stdout )
@@ -37,17 +35,4 @@ Default: `null`
3735
3836postcss plugins used to transform the content
3937
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("..")
22
33var tr = plugin ( "fake.css" , {
44 plugin : "postcss-simple-vars" ,
5- resolve : {
6- basedir : __dirname
7- }
5+ basedir : __dirname
86} )
97tr . end ( "$color: red; .fake { color: $color; }" )
108tr . pipe ( process . stdout )
Original file line number Diff line number Diff line change 1- var Processor = require ( "postcss-processor" )
21var sink = require ( "sink-transform" )
2+ var resolve = require ( "resolve" )
3+ var postcss = require ( "postcss" )
34
45var processor
56module . exports = function ( file , opts ) {
67 opts = opts || { }
78 if ( ! processor ) {
8- processor = Processor ( opts . plugin , opts . options , opts . resolve )
9+ processor = getProcessor ( opts )
910 }
10- return sink . str ( function ( body , done ) {
11+ var stream = sink . str ( function ( body , done ) {
1112 var self = this
1213 processor . process ( body , { from : file } )
1314 . then ( function ( result ) {
1415 self . push ( result . css )
1516 done ( )
17+ } , function ( err ) {
18+ stream . emit ( "error" , err )
1619 } )
1720 } )
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+ ) )
1842}
Original file line number Diff line number Diff line change 2121 },
2222 "homepage" : " https://github.com/zoubin/browserify-postcss#readme" ,
2323 "dependencies" : {
24- "postcss-processor" : " ^0.1.0" ,
24+ "postcss" : " ^4.1.11" ,
25+ "resolve" : " ^1.1.6" ,
2526 "sink-transform" : " ^0.1.2"
2627 },
2728 "devDependencies" : {
Original file line number Diff line number Diff line change 1- var processor = require ( ".." )
1+ var plugin = require ( ".." )
22var sink = require ( "sink-transform" )
33var test = require ( "tape" )
44
55test ( 'transform' , function ( t ) {
66 t . plan ( 1 )
7- var tr = processor ( "fake.css" , {
7+ var tr = plugin ( "fake.css" , {
88 plugin : "postcss-simple-vars" ,
9- resolve : {
10- basedir : __dirname
11- }
9+ basedir : __dirname
1210 } )
1311 tr . end ( "$color: red; .fake { color: $color; }" )
1412 tr . pipe ( sink . str ( function ( body ) {
You can’t perform that action at this time.
0 commit comments