PostCSS Custom Media runs in all Node environments, with special instructions for:
Node | PostCSS CLI | Webpack | Create React App | Gulp | Grunt |
---|
Add PostCSS Custom Media to your project:
npm install postcss-custom-media --save-dev
Use PostCSS Custom Media to process your CSS:
const postcssCustomMedia = require('postcss-custom-media');
postcssCustomMedia.process(YOUR_CSS /*, processOptions, pluginOptions */);
Or use it as a PostCSS plugin:
const postcss = require('postcss');
const postcssCustomMedia = require('postcss-custom-media');
postcss([
postcssCustomMedia(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);
Add PostCSS CLI to your project:
npm install postcss-cli --save-dev
Use PostCSS Custom Media in your postcss.config.js
configuration file:
const postcssCustomMedia = require('postcss-custom-media');
module.exports = {
plugins: [
postcssCustomMedia(/* pluginOptions */)
]
}
Add PostCSS Loader to your project:
npm install postcss-loader --save-dev
Use PostCSS Custom Media in your Webpack configuration:
const postcssCustomMedia = require('postcss-custom-media');
module.exports = {
module: {
rules: [
{
test: /\.css$/,
use: [
'style-loader',
{ loader: 'css-loader', options: { importLoaders: 1 } },
{ loader: 'postcss-loader', options: {
ident: 'postcss',
plugins: () => [
postcssCustomMedia(/* pluginOptions */)
]
} }
]
}
]
}
}
Add React App Rewired and React App Rewire PostCSS to your project:
npm install react-app-rewired react-app-rewire-postcss --save-dev
Use React App Rewire PostCSS and PostCSS Custom Media in your
config-overrides.js
file:
const reactAppRewirePostcss = require('react-app-rewire-postcss');
const postcssCustomMedia = require('postcss-custom-media');
module.exports = config => reactAppRewirePostcss(config, {
plugins: () => [
postcssCustomMedia(/* pluginOptions */)
]
});
Add Gulp PostCSS to your project:
npm install gulp-postcss --save-dev
Use PostCSS Custom Media in your Gulpfile:
const postcss = require('gulp-postcss');
const postcssCustomMedia = require('postcss-custom-media');
gulp.task('css', () => gulp.src('./src/*.css').pipe(
postcss([
postcssCustomMedia(/* pluginOptions */)
])
).pipe(
gulp.dest('.')
));
Add Grunt PostCSS to your project:
npm install grunt-postcss --save-dev
Use PostCSS Custom Media in your Gruntfile:
const postcssCustomMedia = require('postcss-custom-media');
grunt.loadNpmTasks('grunt-postcss');
grunt.initConfig({
postcss: {
options: {
use: [
postcssCustomMedia(/* pluginOptions */)
]
},
dist: {
src: '*.css'
}
}
});