FreeTube/_scripts/webpack.main.config.js

70 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-02-16 19:30:00 +01:00
const path = require('path')
const webpack = require('webpack')
const CopyWebpackPlugin = require('copy-webpack-plugin')
2022-09-13 03:28:36 +02:00
const JsonMinimizerPlugin = require('json-minimizer-webpack-plugin')
2020-02-16 19:30:00 +01:00
const { productName } = require('../package.json')
2020-02-16 19:30:00 +01:00
const isDevMode = process.env.NODE_ENV === 'development'
const config = {
name: 'main',
mode: process.env.NODE_ENV,
2021-03-03 04:51:01 +01:00
devtool: isDevMode ? 'eval-cheap-module-source-map' : false,
2020-02-16 19:30:00 +01:00
entry: {
main: path.join(__dirname, '../src/main/index.js'),
},
module: {
rules: [
{
test: /\.js$/,
2021-03-03 04:51:01 +01:00
use: 'babel-loader',
2020-02-16 19:30:00 +01:00
exclude: /node_modules/,
},
],
},
2022-09-13 03:28:36 +02:00
// 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/
})
2022-09-13 03:28:36 +02:00
]
},
2020-02-16 19:30:00 +01:00
node: {
__dirname: isDevMode,
2022-11-09 13:34:40 +01:00
__filename: isDevMode
2020-02-16 19:30:00 +01:00
},
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) {
2020-02-16 19:30:00 +01:00
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/**'],
},
},
]
})
2020-02-16 19:30:00 +01:00
)
}
module.exports = config