A
A
Alex_872020-12-19 01:25:14
webpack
Alex_87, 2020-12-19 01:25:14

How to set up autoprefix in webpack?

Good evening! I want to slightly modify the existing webpack file by adding the autoprefix module to it.
I beg you to help me set up the file! Below, I will transfer my file and the code that I already found on the net that sets up the autoprefix. I just don't know how to connect them without breaking anything! Please help...
My webpack config file

const path = require('path')
const HTMLPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'js/bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  optimization: {
    minimizer: [
      new OptimizeCssAssetsPlugin({}),
      new UglifyJsPlugin({})
    ]
  },
  devServer: {
    contentBase: path.resolve(__dirname, 'dist'),
    port: 4200
  },
  plugins: [
    new HTMLPlugin({
      filename: 'index.html',
      template: './src/index.html'
    }),
    new MiniCssExtractPlugin({
      filename: 'css/style.css'
    })
  ],
  resolve: {
    extensions: ['.js', '.ts']
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [MiniCssExtractPlugin.loader, 'css-loader']
      },
      {
        test: /\.less$/,
        use: [MiniCssExtractPlugin.loader, 'css-loader', 'less-loader']
      },
   
      {
        test: /\.scss$/,
        use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader']
      },
      { 
        test: /\.(js|ts)$/, 
        exclude: /node_modules/, 
        loader: "babel-loader" 
      }
    ]
  }
}


Link where the required code is located (please pay attention to the insertion of the code where it is written about the module): https://medium.com/@realfrancisyan/scss-autoprefix...

Please change my module

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Russo2, 2020-12-21
@Russo2

npm i -D postcss postcss-loader autoprefixer
in rules:

{
  test:  /\.css$/i,
  use: [
    MiniCssExtractPlugin.loader,
    'postcss-loader',
    'css-loader'
  ]

}

in the same directory with webpack.config create a file postcss.config.js with the content:
module.exports = {
  plugins: [
    'autoprefixer'
  ]
};

https://www.npmjs.com/package/postcss-loader
https://www.npmjs.com/package/autoprefixer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question