webpack.main.config.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. 'use strict'
  2. process.env.BABEL_ENV = 'main'
  3. const path = require('path')
  4. const { dependencies } = require('../package.json')
  5. const webpack = require('webpack')
  6. const MinifyPlugin = require("babel-minify-webpack-plugin")
  7. const CopyWebpackPlugin = require('copy-webpack-plugin')
  8. let mainConfig = {
  9. entry: {
  10. main: path.join(__dirname, '../src/main/index.js')
  11. },
  12. externals: [
  13. ...Object.keys(dependencies || {})
  14. ],
  15. module: {
  16. rules: [
  17. {
  18. test: /\.js$/,
  19. use: 'babel-loader',
  20. exclude: /node_modules/
  21. },
  22. {
  23. test: /\.node$/,
  24. use: 'node-loader'
  25. }
  26. ]
  27. },
  28. node: {
  29. __dirname: process.env.NODE_ENV !== 'production',
  30. __filename: process.env.NODE_ENV !== 'production'
  31. },
  32. output: {
  33. filename: '[name].js',
  34. libraryTarget: 'commonjs2',
  35. path: path.join(__dirname, '../dist/electron')
  36. },
  37. plugins: [
  38. new webpack.NoEmitOnErrorsPlugin(),
  39. new CopyWebpackPlugin([
  40. {
  41. from: path.resolve(__dirname, '../static'),
  42. to: 'static',
  43. ignore: ['.*']
  44. }
  45. ])
  46. ],
  47. resolve: {
  48. extensions: ['.js', '.json', '.node'],
  49. modules: [path.resolve('node_modules'), 'node_modules'],
  50. },
  51. target: 'electron-main',
  52. }
  53. /**
  54. * Adjust mainConfig for development settings
  55. */
  56. if (process.env.NODE_ENV !== 'production') {
  57. mainConfig.plugins.push(
  58. new webpack.DefinePlugin({
  59. '__static': `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"`
  60. })
  61. )
  62. }
  63. /**
  64. * Adjust mainConfig for production settings
  65. */
  66. if (process.env.NODE_ENV === 'production') {
  67. mainConfig.plugins.push(
  68. new MinifyPlugin(),
  69. new webpack.DefinePlugin({
  70. 'process.env.NODE_ENV': '"production"'
  71. })
  72. )
  73. }
  74. module.exports = mainConfig