const webpack = require('webpack')
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')

const config =
{
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'bundle.js',
    globalObject: 'this'
  },
  module: {
    rules: [
      {
        test: /\.worker\.js$/, //以.worker.js结尾的文件将被worker-loader加载
        use: { loader: 'worker-loader' }
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader'
        }
      },
      {
        test: /\.css$/,
        use: [
          {loader: 'style-loader'},
          {loader: 'css-loader'},
          {
            loader: 'postcss-loader',
            options: {
              plugins: [require('autoprefixer')]
            }
          }
        ]
      },
      {
        test: /\.(png|jpg|gif|woff|eot|ttf|svg)$/,
        use: {
          loader: 'url-loader',
          options: {
            limit: 8192,
            name: "assets/[name].[ext]"
          }
        }
      }
    ]
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new HtmlWebpackPlugin({
      template: path.join(__dirname, 'src/index.html'),
      minify: {
        removeComments: false,
        collapseWhitespace: false
      }
    })
  ]
  // ,
  // devServer: {
  //   contentBase: path.join(__dirname, "dist"),
  //   port: 8000,
  //   hot: true
  // }
}

module.exports = config