webpack配置(使用react,es6的项目)

const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const eslintPath = path.join(__dirname, '.eslintrc.js');

const config = {
    entry: {
        index: path.resolve(__dirname, './app.jsx'),
        vendors: [
         'react',
            'react-dom',
         'react-color',
           'axios',
           'echarts',
           'babel-polyfill'
        ]
    },
    output: {
      path: path.resolve(__dirname, 'build'),
      chunkFilename: '[name].bundle.js',
      filename: '[name].bundle.js'
      // filename: '[name].bundle[chunkHash:5].js'
    },
    module: {
      rules: [
        // {
          // enforce: "pre",
          // test: /\.js$/,
          // exclude: /node_modules/,
          // loader: "eslint-loader",
          // options: {
          // configFile:path.join(__dirname, '.eslintrc.js'),
          // formatter: require("eslint-friendly-formatter"),
          // // eslintPath: path.join(__dirname, '.eslintrc.js'),
          // emitError: true
          // }
        // },
        {
          test: /\.jsx?$/,
          exclude: /node_modules/,
          loader: "babel-loader",
        },
        // {
          // test: /\.jsx?$/,
          // loader: ['babel-loader','eslint-loader'],
          // exclude: /node_modules/,
        // },
        {
         test: /(\.(png|jpg|ttf|woff|svg|eot)$)/,
         use: [{
          loader: 'file-loader',
          options: {
            name: '[path][name].[ext]',
            outputPath: 'resource/'
          }
           }]
        },
        {
          test: /\.css$/,
          use: ExtractTextPlugin.extract({
            fallback: "style-loader",
            use: "css-loader"
          })
        },

        ]
       },
    resolve: {
      extensions: ['.js', '.jsx'],
      alias:{
        'corejs': path.resolve('./corejs'),
       }
    },
    plugins: [
      new webpack.DefinePlugin({
        'process.env': {
        'NODE_ENV': JSON.stringify('development')
      }
    }),
    new ExtractTextPlugin("styles.css"),
    //生成模板
    new HtmlWebpackPlugin({
      template: './template.html',
      filename: 'index.html',
      inject: true,
      hash: false
    }),
    //添加代码标注
    new webpack.BannerPlugin('This file is created by xdataInsight group'),
    //提取合并共用js库
    // new webpack.optimize.CommonsChunkPlugin({ name: 'vendors', filename: 'vendors.[hash:8].min.js' }),
    ],
    devtool: 'eval-source-map',
    devServer: {
      contentBase: './',
      historyApiFallback: true,
      // hot: true,
      inline: true,
      disableHostCheck: true,
      proxy: {  //代理
        '/xdatainsight/*': {
          target: 'http://balabala:41116',
          secure: false,
          auth: 'admin:admin'
        }
      }
    }
};
module.exports = config;

posted @ 2018-04-19 15:16  大棒子  阅读(340)  评论(0编辑  收藏  举报