text: const resolve = require('path').resolve
  const webpack = require('webpack')
  const HtmlWebpackPlugin = require('html-webpack-plugin')
  const url = require('url')
  const publicPath = ''
  
  module.exports = (options = {}) => ({
    entry: {
      vendor: './src/vendor', // 被公共使用的js,参考 https://segmentfault.com/q/1010000009070061
      index: './src/main.js' // 入口文件
    },
    output: {
      path: resolve(__dirname, 'dist'),
      filename: options.dev ? '[name].js' : '[name].js?[chunkhash]',
      chunkFilename: '[id].js?[chunkhash]',
      publicPath: options.dev ? '/assets/' : publicPath
    },
    module: {
      rules: [{
          test: /\.vue$/,
          use: ['vue-loader']
        },
        {
          test: /\.js$/,
          use: ['babel-loader'],
          exclude: /node_modules/
        },
        {
          test: /\.css$/,
          use: ['style-loader', 'css-loader', 'postcss-loader']
        },
        {
          test: /\.(png|jpg|jpeg|gif|eot|ttf|woff|woff2|svg|svgz)(\?.+)?$/,
          use: [{
            loader: 'url-loader',
            options: {
              limit: 10000
            }
          }]
        }
      ]
    },
    plugins: [
      // 提取公共chuck
      new webpack.optimize.CommonsChunkPlugin({
        names: ['vendor', 'manifest'] // webpack的运行文件会先被生成vendor.js，然后webpack的运行文件会被从vendor中再次抽出，生成一个manifest.js文件
      }),
      new HtmlWebpackPlugin({
        template: 'src/index.html'
      })
    ],
    resolve: {
      alias: {
        '~': resolve(__dirname, 'src')
      },
      extensions: ['.js', '.vue', '.json', '.css']
    },
    devServer: {
      host: '127.0.0.1',
      port: 8010,
      proxy: {
        '/api/': {
          target: 'http://127.0.0.1:8080',
          changeOrigin: true,
          pathRewrite: {
            '^/api': ''
          }
        }
      },
      historyApiFallback: {
        index: url.parse(options.dev ? '/assets/' : publicPath).pathname
      }
    },
    devtool: options.dev ? '#eval-source-map' : '#source-map'
  })
  