Load Options
Install
npm i -D postcss-load-options copy
Usage
package.json
Create postcss section in your projects package.json .
App
|– client
|– public
|
|- package.json copy
{
"dependencies" : {
"sugarss" : "0.2.0"
},
"postcss" : {
"parser" : "sugarss" ,
"map" : false,
"from" : "path/to/src/file.css" ,
"to" : "path/to/dest/file.css"
}
} copy
.postcssrc
Create a .postcssrc file.
App
|– client
|– public
|
|- (.postcssrc|.postcssrc.json|.postcssrc.yaml)
|- package.json copy
JSON
{
"parser" : "sugarss" ,
"map" : false,
"from" : "path/to/src/file.css" ,
"to" : "path/to/dest/file.css"
} copy
YAML
parser : sugarss
map : false
from : "/path/to/src.sss"
to : "/path/to/dest.css" copy
postcss.config.js or .postcssrc.js
You may need some JavaScript logic to generate your config. For this case you can use a file named postcss.config.js or .postcssrc.js .
App
|– client
|– public
|
|- (postcss.config.js|.postcssrc.js)
|- package.json copy
module . exports = (ctx) => {
return {
parser: ctx.sugar ? 'sugarss' : false ,
map: ctx.env === 'development' ? ctx.map || false ,
from : 'path/to/src/file.css' ,
to: 'path/to/dest/file.css'
}
} copy
Options
parser :
syntax :
'syntax' : 'postcss-scss' copy
stringifier :
'stringifier' : 'midas' copy
map :
from :
from : 'path/to/dest/file.css' copy
to :
to : 'path/to/dest/file.css' copy
Context
When using a function (postcss.config.js), it is possible to pass context to postcss-load-options, which will be evaluated before loading your options. By default ctx.env (process.env.NODE_ENV) and ctx.cwd (process.cwd()) are available.
Example
const { readFileSync } = require ( 'fs' )
const postcss = require ( 'postcss' )
const optionsrc = require ( 'postcss-load-options' )
const sss = readFileSync ( 'index.sss' , 'utf8' )
const ctx = { sugar: true , map: 'inline' }
optionsrc (ctx). then ((options) => {
postcss ()
. process (sss, options)
. then (({ css }) => console. log (css))
})) copy
Maintainers