美文网首页
webpack最新配置

webpack最新配置

作者: 勿以浮沙筑高台 | 来源:发表于2017-04-21 11:18 被阅读56次
// webpack.config.js

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

module.exports = {
  devtool: 'eval-source-map',//配置生成Source Maps,选择合适的选项
  entry:  __dirname + "/src/main.js",//唯一入口文件
  output: {
    path: __dirname + "/public",//打包后的文件存放的地方
    filename: "[name]-[hash].js"//打包后输出文件的文件名
  },
  module: {//在配置文件里添加JSON loader
    loaders: [
      {
        test: /\.json$/,
        loader: "json"
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel-loader',//需要编写.babelrc文件
      },
      {
        test: /\.css$/,
        loader: 'style!css?modules!postcss'//添加对叠层样式表的处理
      }
    ]
  },
  plugins: [
    new webpack.LoaderOptionsPlugin({
      options: {
        postcss: function() {
          return [require('autoprefixer')]; 
        },
      }
    }),
    new HtmlWebpackPlugin({
      template: __dirname + "/index.tmpl.html"
    }),
    new webpack.optimize.UglifyJsPlugin(),
    new ExtractTextPlugin("[name]-[hash].css")
  ],
  devServer: {
    contentBase: "./public",//本地服务器所加载的页面所在的目录
    historyApiFallback: true,//不跳转
    inline: true,//实时刷新
    hot: true
  },
}
// .babelrc
{
  "presets": ["es2015"]
}

启动热加载的正确姿势:
$ webpack-dev-server --hot --inline --progress

相关文章

网友评论

      本文标题:webpack最新配置

      本文链接:https://www.haomeiwen.com/subject/uzcdzttx.html