webpack.main.config.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. let mainConfig = {
  8. entry: {
  9. main: path.join(__dirname, '../src/main/index.js')
  10. },
  11. externals: [
  12. ...Object.keys(dependencies || {})
  13. ],
  14. module: {
  15. rules: [
  16. {
  17. test: /\.js$/,
  18. use: 'babel-loader',
  19. exclude: /node_modules/
  20. },
  21. {
  22. test: /\.node$/,
  23. use: 'node-loader'
  24. }
  25. ]
  26. },
  27. node: {
  28. __dirname: process.env.NODE_ENV !== 'production',
  29. __filename: process.env.NODE_ENV !== 'production'
  30. },
  31. output: {
  32. filename: '[name].js',
  33. libraryTarget: 'commonjs2',
  34. path: path.join(__dirname, '../dist/electron')
  35. },
  36. plugins: [
  37. new webpack.NoEmitOnErrorsPlugin()
  38. ],
  39. resolve: {
  40. extensions: ['.js', '.json', '.node']
  41. },
  42. target: 'electron-main'
  43. }
  44. /**
  45. * Adjust mainConfig for development settings
  46. */
  47. if (process.env.NODE_ENV !== 'production') {
  48. mainConfig.plugins.push(
  49. new webpack.DefinePlugin({
  50. '__static': `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"`
  51. })
  52. )
  53. }
  54. /**
  55. * Adjust mainConfig for production settings
  56. */
  57. if (process.env.NODE_ENV === 'production') {
  58. mainConfig.plugins.push(
  59. new MinifyPlugin(),
  60. new webpack.DefinePlugin({
  61. 'process.env.NODE_ENV': '"production"'
  62. })
  63. )
  64. }
  65. module.exports = mainConfig