2020-02-16 18:30:00 +00:00
|
|
|
const path = require('path')
|
|
|
|
const webpack = require('webpack')
|
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin')
|
|
|
|
|
|
|
|
const {
|
|
|
|
dependencies,
|
|
|
|
devDependencies,
|
|
|
|
productName,
|
|
|
|
} = require('../package.json')
|
|
|
|
|
|
|
|
const externals = Object.keys(dependencies).concat(Object.keys(devDependencies))
|
|
|
|
const isDevMode = process.env.NODE_ENV === 'development'
|
|
|
|
const whiteListedModules = []
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
name: 'main',
|
|
|
|
mode: process.env.NODE_ENV,
|
2021-03-03 03:51:01 +00:00
|
|
|
devtool: isDevMode ? 'eval-cheap-module-source-map' : false,
|
2020-02-16 18:30:00 +00:00
|
|
|
entry: {
|
|
|
|
main: path.join(__dirname, '../src/main/index.js'),
|
|
|
|
},
|
|
|
|
externals: externals.filter(d => !whiteListedModules.includes(d)),
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2022-07-14 14:43:07 +00:00
|
|
|
test: /\.js$/,
|
2021-03-03 03:51:01 +00:00
|
|
|
use: 'babel-loader',
|
2020-02-16 18:30:00 +00:00
|
|
|
exclude: /node_modules/,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.node$/,
|
2021-03-03 03:51:01 +00:00
|
|
|
loader: 'node-loader',
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
node: {
|
|
|
|
__dirname: isDevMode,
|
|
|
|
__filename: isDevMode,
|
2021-03-03 03:51:01 +00:00
|
|
|
global: isDevMode,
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env.PRODUCT_NAME': JSON.stringify(productName),
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
output: {
|
|
|
|
filename: '[name].js',
|
|
|
|
libraryTarget: 'commonjs2',
|
|
|
|
path: path.join(__dirname, '../dist'),
|
|
|
|
},
|
|
|
|
resolve: {
|
2022-05-31 20:15:44 +00:00
|
|
|
extensions: ['.js', '.json'],
|
2020-02-16 18:30:00 +00:00
|
|
|
alias: {
|
|
|
|
'@': path.join(__dirname, '../src/'),
|
|
|
|
src: path.join(__dirname, '../src/'),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
target: 'electron-main',
|
|
|
|
}
|
|
|
|
|
2020-03-24 13:22:29 +00:00
|
|
|
if (isDevMode) {
|
|
|
|
config.plugins.push(
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
__static: `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"`,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
} else {
|
2020-02-16 18:30:00 +00:00
|
|
|
config.plugins.push(
|
2020-05-23 21:29:42 +00:00
|
|
|
new CopyWebpackPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
from: path.join(__dirname, '../static/pwabuilder-sw.js'),
|
|
|
|
to: path.join(__dirname, '../dist/web/pwabuilder-sw.js'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
from: path.join(__dirname, '../static'),
|
|
|
|
to: path.join(__dirname, '../dist/web/static'),
|
|
|
|
globOptions: {
|
2022-07-14 14:43:07 +00:00
|
|
|
dot: true,
|
|
|
|
ignore: ['**/.*', '**/pwabuilder-sw.js', '**/dashFiles/**', '**/storyboards/**'],
|
2020-05-23 21:29:42 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
from: path.join(__dirname, '../_icons'),
|
2020-05-28 02:48:41 +00:00
|
|
|
to: path.join(__dirname, '../dist/_icons'),
|
2020-05-23 21:29:42 +00:00
|
|
|
globOptions: {
|
2022-07-14 14:43:07 +00:00
|
|
|
dot: true,
|
|
|
|
ignore: ['**/.*'],
|
2020-05-23 21:29:42 +00:00
|
|
|
},
|
|
|
|
},
|
2020-07-11 22:36:42 +00:00
|
|
|
{
|
|
|
|
from: path.join(__dirname, '../src/renderer/assets/img'),
|
|
|
|
to: path.join(__dirname, '../dist/images'),
|
|
|
|
globOptions: {
|
2022-07-14 14:43:07 +00:00
|
|
|
dot: true,
|
|
|
|
ignore: ['**/.*'],
|
2020-07-11 22:36:42 +00:00
|
|
|
},
|
|
|
|
},
|
2020-05-23 21:29:42 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
),
|
2020-03-24 13:22:29 +00:00
|
|
|
new webpack.LoaderOptionsPlugin({
|
|
|
|
minimize: true,
|
|
|
|
})
|
2020-02-16 18:30:00 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = config
|