const webpack = require('webpack');
const { getConfig, dev } = require('./webpack.config.base');
const { join } = require('path');
const { execSync } = require('child_process');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');

const PORT = 4444;

const config = {
  target: 'electron-renderer',
  plugins: [],
  output: {},
};

if (dev) {
  config.devServer = {
    contentBase: join(__dirname, 'dist'),
    port: PORT,
    hot: true,
    inline: true,
    historyApiFallback: {
      verbose: true,
      disableDotRule: false,
    },
  };

  config.output.publicPath = `http://localhost:${PORT}/`;

  config.plugins.push(new webpack.HotModuleReplacementPlugin());
}

const appConfig = getConfig(config, {
  entry: {
    app: ['./src/renderer/views/app'],
  },

  plugins: [
    new HtmlWebpackPlugin({
      title: 'Wexond',
      template: 'static/pages/app.html',
      filename: 'app.html',
    }),
    new HardSourceWebpackPlugin(),
  ],
});

if (dev) {
  appConfig.entry.app.unshift('react-hot-loader/patch');
}

module.exports = [appConfig];

@@ -831,16 +831,376 @@
 /app'%5D,%0A
+    vendor: %5B%0A      'react',%0A      'react-dom',%0A      'mobx',%0A      'mobx-react-lite',%0A      'styled-components',%0A    %5D,%0A  %7D,%0A%0A  optimization: %7B%0A    splitChunks: %7B%0A      cacheGroups: %7B%0A        vendor: %7B%0A          chunks: 'initial',%0A          name: 'vendor',%0A          test: 'vendor',%0A          enforce: true,%0A        %7D,%0A      %7D,%0A    %7D,%0A    runtimeChunk: true,%0A
   %7D,%0A%0A  

create vendor bundle