FreeTube/_scripts/webpack.main.config.js
2022-11-09 07:34:40 -05:00

70 lines
1.7 KiB
JavaScript

const path = require('path')
const webpack = require('webpack')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const JsonMinimizerPlugin = require('json-minimizer-webpack-plugin')
const { productName } = require('../package.json')
const isDevMode = process.env.NODE_ENV === 'development'
const config = {
name: 'main',
mode: process.env.NODE_ENV,
devtool: isDevMode ? 'eval-cheap-module-source-map' : false,
entry: {
main: path.join(__dirname, '../src/main/index.js'),
},
module: {
rules: [
{
test: /\.js$/,
use: 'babel-loader',
exclude: /node_modules/,
},
],
},
// webpack defaults to only optimising the production builds, so having this here is fine
optimization: {
minimizer: [
'...', // extend webpack's list instead of overwriting it
new JsonMinimizerPlugin({
exclude: /\/locales\/.*\.json/
})
]
},
node: {
__dirname: isDevMode,
__filename: isDevMode
},
plugins: [
new webpack.DefinePlugin({
'process.env.PRODUCT_NAME': JSON.stringify(productName),
}),
],
output: {
filename: '[name].js',
libraryTarget: 'commonjs2',
path: path.join(__dirname, '../dist'),
},
target: 'electron-main',
}
if (!isDevMode) {
config.plugins.push(
new CopyWebpackPlugin({
patterns: [
{
from: path.join(__dirname, '../static'),
to: path.join(__dirname, '../dist/static'),
globOptions: {
dot: true,
ignore: ['**/.*', '**/locales/**', '**/pwabuilder-sw.js', '**/dashFiles/**', '**/storyboards/**'],
},
},
]
})
)
}
module.exports = config