const path = require('path');
const WebpackAssetsManifest = require('webpack-assets-manifest');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

const { NODE_ENV } = process.env;
const isProd = NODE_ENV === 'production';

module.exports = {
  mode: isProd ? 'production' : 'development',
  devtool: isProd ? false : 'source-map',
  entry: {
    application: [
      '@fortawesome/fontawesome-free/js/all.js',
      path.resolve(__dirname, 'front', 'index.scss'),
      path.resolve(__dirname, 'front', 'index.ts')
    ]
  },
  output: {
    path: path.resolve(__dirname, 'public', 'packs'),
    publicPath: isProd ? '/packs/' : '//localhost:8080/packs/',
    filename: isProd ? '[name]-[hash].js' : '[name].js'
  },
  resolve: {
    extensions: ['.tsx', '.ts', '.jsx', '.js']
  },
  module: {
    rules: [
      {
        test: /\.(tsx?|js)$/,
        use: 'babel-loader',
        include: path.resolve(__dirname, 'front')
      },
      {
        test: /\.(s?css)$/,
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader',
          'sass-loader'
        ]
      },
      {
        test: /\.(svg|png|gif|eot|ttf|woff2?)$/,
        use: [
          {
            loader: 'file-loader',
            options: {
              name: '[name]-[hash].[ext]'
            }
          }
        ]
      }
    ]
  },
  plugins: [
    new MiniCssExtractPlugin(),
    new WebpackAssetsManifest({
      publicPath: true,
      output: 'manifest.json',
      writeToDisk: true
    }),
    new CaseSensitivePathsPlugin()
  ],
  devServer: {
    contentBase: path.resolve(__dirname, 'public'),
    publicPath: '/packs/',
    port: 8080,
    disableHostCheck: true,
    headers: {
      'Access-Control-Allow-Origin': '*'
    }
  }
};

@@ -774,24 +774,31 @@
  ? '%5Bname%5D-%5B
+content
 hash%5D.js' : 
@@ -1348,16 +1348,25 @@
    name:
+ isProd ?
  '%5Bname%5D
@@ -1367,16 +1367,23 @@
 %5Bname%5D-%5B
+content
 hash%5D.%5Be
@@ -1386,16 +1386,34 @@
 %5D.%5Bext%5D'
+ : '%5Bname%5D.%5Bext%5D',
 %0A       
@@ -1469,24 +1469,24 @@
  plugins: %5B%0A
-
     new Mini
@@ -1502,16 +1502,91 @@
 tPlugin(
+%7B%0A      filename: isProd ? '%5Bname%5D-%5Bcontenthash%5D.css' : '%5Bname%5D.css',%0A    %7D
 ),%0A    n

use contenthash