首页 > webpack html-webpack-plugin minify:true

webpack html-webpack-plugin minify:true

自动生成html插件

html-webpack-plugin

new HtmlWebpackPlugin({
      title: 'React Title !',
      template: './template.html',
      minify:true,
      inject: 'body'
    }),

添加了 minify:true 参数后就会报错

ERROR in   TypeError: Cannot use 'in' operator to search for 'html5' in true

更多配置

var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  devtool: 'eval',
  entry: [
    'webpack-dev-server/client?http://localhost:3000',
    'webpack/hot/only-dev-server',
    './app/App.js'
  ],
  output: {
    pathinfo: true,
    path: path.resolve(__dirname, 'public'),
    filename: 'bundle.js',
    publicPath: '/'
  },
  plugins: [
    new HtmlWebpackPlugin({
      title: 'React Title !',
      template: './template.html',
      minify:true,
      inject: 'body'
    }),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        warnings: false
      }
    })
  ],
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        loaders: ['react-hot', 'babel']
      },
      {
        test: /\.styl$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'style!css?sourceMap&modules&importLoaders=1&localIdentName=[name]__[local]__[hash:base64:5]!postcss!stylus-loader'
      },
      {
        test: /.scss$/,
        exclude: /node_modules/,
        loaders: ["style", "css", "sass?config=otherSassLoaderConfig"]
      },
      {
        test: /\.(png|jpg|gif|svg)$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'url-loader?name=images/[name].[ext]&limit=8192'
      }
    ]
  },
  resolve: {
    root: path.join(__dirname, '..', 'app'),
    extensions: ['', '.js', '.jsx', '.json', '.css', '.styl', '.png', '.jpg', '.jpeg', '.gif', '.svg']
  },
  stylus: function () {
    return [rupture]
  },
  postcss: function () {
    return [autoprefixer];
  }
};

据说是现在htmlminify没有默认值了,需要你自己指定:

new HtmlWebpackPlugin({
      title: 'React Title !',
      template: './template.html',
      minify: { removeAttributeQuotes: true },
      inject: 'body'
    }),

这么来试试

【热门文章】
【热门文章】