Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
172 lines (128 sloc) 3.79 KB

Installing PostCSS image-set() Function

PostCSS image-set() Function runs in all Node environments, with special instructions for:

Node PostCSS CLI Webpack Create React App Gulp Grunt

Node

Add PostCSS image-set() Function to your project:

npm install postcss-image-set-function --save-dev

Use PostCSS image-set() Function to process your CSS:

const postcssImageSetFunction = require('postcss-image-set-function');

postcssImageSetFunction.process(YOUR_CSS /*, processOptions, pluginOptions */);

Or use it as a PostCSS plugin:

const postcss = require('postcss');
const postcssImageSetFunction = require('postcss-image-set-function');

postcss([
  postcssImageSetFunction(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);

PostCSS CLI

Add PostCSS CLI to your project:

npm install postcss-cli --save-dev

Use PostCSS image-set() Function in your postcss.config.js configuration file:

const postcssImageSetFunction = require('postcss-image-set-function');

module.exports = {
  plugins: [
    postcssImageSetFunction(/* pluginOptions */)
  ]
}

Webpack

Add PostCSS Loader to your project:

npm install postcss-loader --save-dev

Use PostCSS image-set() Function in your Webpack configuration:

const postcssImageSetFunction = require('postcss-image-set-function');

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'style-loader',
          { loader: 'css-loader', options: { importLoaders: 1 } },
          { loader: 'postcss-loader', options: {
            ident: 'postcss',
            plugins: () => [
              postcssImageSetFunction(/* pluginOptions */)
            ]
          } }
        ]
      }
    ]
  }
}

Create React App

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 image-set() Function in your config-overrides.js file:

const reactAppRewirePostcss = require('react-app-rewire-postcss');
const postcssImageSetFunction = require('postcss-image-set-function');

module.exports = config => reactAppRewirePostcss(config, {
  plugins: () => [
    postcssImageSetFunction(/* pluginOptions */)
  ]
});

Gulp

Add Gulp PostCSS to your project:

npm install gulp-postcss --save-dev

Use PostCSS image-set() Function in your Gulpfile:

const postcss = require('gulp-postcss');
const postcssImageSetFunction = require('postcss-image-set-function');

gulp.task('css', () => gulp.src('./src/*.css').pipe(
  postcss([
    postcssImageSetFunction(/* pluginOptions */)
  ])
).pipe(
  gulp.dest('.')
));

Grunt

Add Grunt PostCSS to your project:

npm install grunt-postcss --save-dev

Use PostCSS image-set() Function in your Gruntfile:

const postcssImageSetFunction = require('postcss-image-set-function');

grunt.loadNpmTasks('grunt-postcss');

grunt.initConfig({
  postcss: {
    options: {
      use: [
       postcssImageSetFunction(/* pluginOptions */)
      ]
    },
    dist: {
      src: '*.css'
    }
  }
});
You can’t perform that action at this time.