Name |
Description |
cwd |
process.cwd() |
env |
process.env.NODE_ENV |
import postcssrc from 'postcss-load-config'
postcssrc(ctx, path)
.then((config) => console.log(config.plugins, config.options, config.file))
.catch((err) => console.log(err))
Name |
Description |
cwd |
process.cwd() |
env |
process.env.NODE_ENV |
file |
extname , dirname , basename (vinyl-like) |
options |
Custom Context |
module.exports = (ctx) => ({
parser: ctx.file.extname === '.sss' ? 'sugarss' : false
plugins: {
'postcss-import': { root: ctx.file.dirname }
'postcss-assets': ctx.options.assets
'cssnano': ctx.env === 'production' ? ctx.options.minify : false
}
})
postcss input.css -o output.css --ctx [options]
- Add
ctx.file
- Add
ctx.options
Name |
Description |
cwd |
process.cwd() |
env |
process.env.NODE_ENV |
file |
extname , dirname , basename (vinyl-like) |
options |
Custom Context |
module.exports = (ctx) => ({
parser: ctx.file.extname === '.sss' ? 'sugarss' : false
plugins: {
'postcss-import': { root: ctx.file.dirname }
'postcss-assets': ctx.options.assets
'cssnano': ctx.env === 'production' ? ctx.options.minify : false
}
})
{
test: /\.(css|sss}/
use: [
'style-loader',
'css-loader',
'postcss-loader'
]
}
module.exports = (ctx) => ({
parser: ctx.file.extname === '.sss' ? 'sugarss' : false
plugins: {
'postcss-import': { root: ctx.file.dirname }
'postcss-assets': ctx.options.assets
'cssnano': ctx.env === 'production' ? ctx.options.minify : false
}
})
gulp.task('css', () => {
const cxt = {}
gulp.src('*.{css|sss}')
.pipe(postcss(ctx))
.pipe(gulp.dest('dest'))
})