const path = require('path'); const webpack = require('webpack'); const webpackNodeExternals = require('webpack-node-externals'); const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const CopyWebpackPlugin = require('copy-webpack-plugin'); const TerserPlugin = require('terser-webpack-plugin'); const getEnviroment = require('./enviroment'); const rootPath = path.join(__dirname, '..'); const enviroment = getEnviroment(); const IS_PRODUCTION = !!process.env.NODE_ENV && 'production' === process.env.NODE_ENV; let optimization = undefined; let copyPluginOptions = [ { from: '**/*', to: path.resolve(__dirname, '..', 'dist/assets'), context: 'src/assets' } ]; if (IS_PRODUCTION) { optimization = { minimize: true, minimizer: [new TerserPlugin()] }; copyPluginOptions.push({ from: '**/*', to: path.resolve(__dirname, '..', 'dist/'), context: 'dist-resources/ucap-lg-renderer' }); } const plugins = [ new CleanWebpackPlugin({ verbose: false }), new CopyWebpackPlugin(copyPluginOptions), new webpack.DefinePlugin(Object.assign({}, enviroment, {})) ]; module.exports = [ { mode: IS_PRODUCTION ? 'production' : 'development', entry: path.join(rootPath, 'src', 'main'), node: { __dirname: false }, output: { path: path.join(rootPath, 'dist'), filename: 'electron-main.js' }, target: 'electron-main', devtool: IS_PRODUCTION ? undefined : 'source-map', externals: [webpackNodeExternals()], resolve: { extensions: ['.ts', '.js'] }, module: { rules: [ { test: /\.ts$/, use: [ { loader: 'ts-loader', options: { configFile: path.join(rootPath, 'tsconfig.app.json') } } ], exclude: /node_modules/ } ] }, optimization, plugins } ];