解决PostCSS配置

webpack.config.js:

const path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
    entry: { index: './src/index.js' },
    output: {
        filename: '[name].js',
        path: path.resolve(__dirname, 'dist')
    },
    devServer: {
        contentBase: './dist',
        port: '1217',
        open: true,//自动拉起浏览器
        hot: true,//热加载
        host: '127.0.0.1',
    },
    plugins: [
        new CleanWebpackPlugin(),
        new HtmlWebpackPlugin({
            template: 'index.html',
            filename: 'index.html'
        })
    ],
    module: {
        rules: [
            {
                test: /\.(scss|css)$/,    //打包css、sass文件
                use: [
                    {
                        loader: 'style-loader'
                    },
                    {
                        loader: 'css-loader',
                    },
                    {
                        loader: 'sass-loader'
                    },
                    {
                        loader: 'postcss-loader'
                    }
                ]
            },
        ],
    },
};

因为postCss版本更新,之前版本的配置已无效postcss.config.js

module.exports = {
  plugins: [
    require('autoprefixer')({
      browsers: ['last 100 versions']
    })// 自动添加css前缀
  ]
}

更换为:

module.exports = {
  plugins: [
    require('autoprefixer')({overrideBrowserslist: ['> 0.15% in CN']})// 自动添加css前缀
  ]
}

即可解决

发布了270 篇原创文章 · 获赞 102 · 访问量 50万+

猜你喜欢

转载自blog.csdn.net/hahahhahahahha123456/article/details/104014250