ucap-lg-desktop/config/webpack.config.js

81 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-03-27 08:45:48 +00:00
const path = require('path');
2020-03-27 09:04:12 +00:00
const webpack = require('webpack');
2020-03-27 08:45:48 +00:00
const webpackNodeExternals = require('webpack-node-externals');
2020-03-27 09:04:12 +00:00
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
2020-08-10 05:05:14 +00:00
const CopyWebpackPlugin = require('copy-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
2020-03-27 09:04:12 +00:00
const getEnviroment = require('./enviroment');
2020-03-27 08:45:48 +00:00
const rootPath = path.join(__dirname, '..');
2020-03-27 09:04:12 +00:00
const enviroment = getEnviroment();
2020-03-27 08:45:48 +00:00
2020-08-10 05:05:14 +00:00
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, {}))
];
2020-03-27 08:45:48 +00:00
module.exports = [
{
2020-08-10 05:05:14 +00:00
mode: IS_PRODUCTION ? 'production' : 'development',
2020-03-27 08:45:48 +00:00
entry: path.join(rootPath, 'src', 'main'),
2020-08-10 05:05:14 +00:00
node: {
__dirname: false
},
2020-03-27 09:04:12 +00:00
output: {
path: path.join(rootPath, 'dist'),
filename: 'electron-main.js'
},
2020-03-27 08:45:48 +00:00
target: 'electron-main',
2020-08-10 05:05:14 +00:00
devtool: IS_PRODUCTION ? undefined : 'source-map',
2020-03-27 08:45:48 +00:00
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/
}
]
},
2020-08-10 05:05:14 +00:00
optimization,
plugins
2020-03-27 08:45:48 +00:00
}
];