Webpack配置

const path = require(‘path‘);
const Webpack = require(‘webpack‘);
const HtmlWebpackPlugin = require(‘html-webpack-plugin‘);
const ManifestPlugin = require(‘webpack-manifest-plugin‘);
const UglifyJsPlugin = require(‘uglifyjs-webpack-plugin‘);

module.exports = {
  entry: path.resolve(__dirname, ‘../src/index.jsx‘),
  output: {
    filename: "[name].bundle.js",
    path: path.resolve(__dirname, ‘dist‘),
    publicPath: process.env === ‘production‘ ? ‘dist‘ : ‘/‘
  },
  devtool: ‘inline-source-map‘,
  devServer: {
    contentBase: ‘./dist‘,
    hot: true,
    inline: true,
    open: true,
    overlay: true,
    host: ‘0.0.0.0‘,
    proxy: {}
  },
  resolve: {
    extensions: [‘.less‘, ‘.jsx‘, ‘.js‘],
    alias: {
      ‘@‘: ‘src‘,
      ‘components‘: ‘src/components‘,
      ‘container‘: ‘src/container‘,
      ‘view‘: ‘src/view‘,
      ‘common‘: ‘src/common‘,
      ‘base‘: ‘src/base‘
    }
  },
  module: {
    rules: [
      { test: ‘/\.css$/‘, use: [‘css-loader‘, ‘style-loader‘] },
      { test: ‘/\.jsx/‘, use: [‘babel-loader‘] },
      { test: ‘/\.(png|jpg|svg|gif|woff|woff2|eot|ttf|otf)$/‘, use: [‘file-loader‘] }
    ]
  },
  plugins: [
    new ManifestPlugin(),
    new HtmlWebpackPlugin({
      title: "Webpack App"
    }),
    new UglifyJsPlugin({
      sourceMap: true
    }),
    new Webpack.optimize.CommonsChunkPlugin({
      name: ‘manifest‘
    }),
    new Webpack.HotModuleReplacementPlugin(),
    new Webpack.DefinePlugin({
      ‘process.env.NODE_ENV‘: JSON.stringify(‘production‘)
    }),
  ]
};

相关推荐