text: 'use strict'
  const path = require('path')
  const webpack = require('webpack')
  const HtmlWebpackPlugin = require('html-webpack-plugin')
  const CopyWebpackPlugin = require('copy-webpack-plugin')
  const VueLoaderPlugin = require('vue-loader/lib/plugin')
  const config = require('./config')
  const _ = require('./utils')
  
  module.exports = {
    entry: {
      client: './client/index.js'
    },
    output: {
      path: _.outputPath,
      filename: '[name].js',
      publicPath: config.publicPath
    },
    performance: {
      hints: process.env.NODE_ENV === 'production' ? 'warning' : false
    },
    resolve: {
      extensions: ['.js', '.vue', '.css', '.json'],
      alias: {
        root: path.join(__dirname, '../client'),
        components: path.join(__dirname, '../client/components')
      },
      modules: [
        _.cwd('node_modules'),
        // this meanse you can get rid of dot hell
        // for example import 'components/Foo' instead of import '../../components/Foo'
        _.cwd('client')
      ]
    },
    module: {
      rules: [
        {
          test: /\.vue$/,
          loader: 'vue-loader',
          // options: {
          //   loaders: {
          //     js: [
          //       {
          //         loader: 'babel-loader',
          //         options: {
          //           presets: ['vue-app']
          //         }
          //       }
          //     ]
          //   }
          // }
        },
        {
          test: /\.js$/,
          include: [
            path.resolve(__dirname, '../client'),
            path.resolve(__dirname, '../node_modules/bootstrap/js/')
          ],
          use: {
            loader: 'babel-loader',
            options: {
              presets: ['@babel/preset-env'],
              plugins: ['@babel/plugin-syntax-dynamic-import']
            }
          }
        },
        {
          test: /\.es6$/,
          loaders: ['babel-loader']
        },
        {
          test: /\.(ico|jpg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,
          loader: 'file-loader',
          query: {
            name: 'static/media/[name].[hash:8].[ext]'
          }
        },
        {
          test: /\.svg$/,
          loader: 'raw-loader'
        }
      ]
    },
    plugins: [
      new HtmlWebpackPlugin({
        title: config.title,
        template: path.resolve(__dirname, 'index.html'),
        filename: _.outputIndexPath
      }),
      new VueLoaderPlugin(),
      // new webpack.LoaderOptionsPlugin(_.loadersOptions()),
      new CopyWebpackPlugin([
        {
          from: _.cwd('./static'),
          // to the roor of dist path
          to: './'
        }
      ]),
      new webpack.ProvidePlugin({   
        $: 'jquery',
        // jQuery: 'jquery',
        // 'window.jQuery': 'jquery',
        Popper: ['popper.js', 'default']
      })
    ],
    target: _.target
  }
  