FreeTube/_scripts/webpack.main.config.js

68 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-02-16 19:30:00 +01:00
const path = require('path')
const webpack = require('webpack')
2020-02-16 19:30:00 +01:00
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 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.IS_ELECTRON_MAIN': true
})
],
2020-02-16 19:30:00 +01:00
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