【问题标题】:No autoprefix with webpack configwebpack 配置没有自动前缀
【发布时间】:2016-12-29 05:31:28
【问题描述】:

这些设置没有前缀。 Cssnano 和写入 style.css 工作正常,但没有从我的 sass 添加到 css 的前缀。

我刚开始使用 webpack,所以也许我只是不明白。

配置:

var development = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
var path = require('path');
var precss       = require('precss');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var cssnano = require('cssnano');
var autoprefixer = require('autoprefixer');


var extractCSS = new ExtractTextPlugin('style.css');


module.exports = [
  {
  name: 'app-bundle',
  entry: "./src/js/main.js",
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel-loader',
      },
    ]
  },
  output: {
    path: "",
    filename: "bundle.min.js"
  },
  plugins: development ? [
  ]: [
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
  ],
},


{
  name: 'css/scss',
  entry:  './src/sass/style.scss',
  module: {
  loaders:
    [
      {
      test: /\.scss$/,
      loader: extractCSS.extract('style', 'css!postcss!sass')
      }
    ]
  },
  postcss: function(webpack)
    {
    return [
      cssnano({
         autoprefixer: {
           add: true,
           remove: false,
           browsers: [
            'last 2 versions',
            'ie >= 9'
          ]
         },
         discardComments: {
           removeAll: true
         },
         discardUnused: false,
         mergeIdents: false,
         reduceIdents: false,
         safe: true,
         sourcemap: true
     })
   ]
 },
  output: {
    path: "",
    filename: "style.css"
  },
  plugins: development ? [
    extractCSS
  ] : []
}
];

【问题讨论】:

    标签: sass webpack autoprefixer postcss


    【解决方案1】:

    你的 postcss 插件声明有问题

     postcss: function(webpack)
    {
    return [
      autoprefixer(), // Should be a function call and not reside inside cssnano config
      cssnano({
         discardComments: {
           removeAll: true
         },
         discardUnused: false,
         mergeIdents: false,
         reduceIdents: false,
         safe: true,
         sourcemap: true
     }),
    

    ] },

    【讨论】:

      猜你喜欢
      • 2017-03-03
      • 2023-03-26
      • 2019-06-08
      • 2018-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-17
      • 2018-05-20
      相关资源
      最近更新 更多