const path = require('path');
const htmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  mode: 'development',
  entry: './src/app.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, '../dist'),
  },
  node: {
    fs: 'empty',
    child_process: 'empty',
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, '../src'),
    }
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        use: 'babel-loader',
        exclude: '/node_modules/',
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader'],
      },
      {
        test: /\.less$/,
        exclude: /\.module\.less$/,
        loader: [
          'style-loader', 
          'css-loader',
          // 'css-loader?modules',
          'less-loader'
        ]
      },
      {
        test: /\.module\.less$/,
        loader: [
          'style-loader', 
          // 'css-loader',
          {
            loader: 'css-loader',
            options: {
              modules: {
                localIdentName: '[local]_[hash:base64:5]',
              }
            }
          },
          // 'css-loader?modules',
          'less-loader'
        ]
      },
      {
        test: /\.(mp3|mp4)$/,
        loader: 'url-loader',
        options: {
          name: '[name].[ext]',
        },
      },
    ],
  },
  devServer: {
    contentBase: './dist',
  },
  plugins: [
    new htmlWebpackPlugin({
      template: 'public/index.html',
    }),
  ],
};
