webpack.main.config.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. // enforce: 'pre',
  19. // exclude: /node_modules/,
  20. // use: {
  21. // loader: 'eslint-loader',
  22. // options: {
  23. // formatter: require('eslint-friendly-formatter')
  24. // }
  25. // }
  26. // },
  27. {
  28. test: /\.js$/,
  29. use: 'babel-loader',
  30. exclude: /node_modules/
  31. },
  32. {
  33. test: /\.node$/,
  34. use: 'node-loader'
  35. }
  36. ]
  37. },
  38. node: {
  39. __dirname: process.env.NODE_ENV !== 'production',
  40. __filename: process.env.NODE_ENV !== 'production'
  41. },
  42. output: {
  43. filename: '[name].js',
  44. libraryTarget: 'commonjs2',
  45. path: path.join(__dirname, '../dist/electron')
  46. },
  47. plugins: [
  48. new webpack.NoEmitOnErrorsPlugin()
  49. ],
  50. resolve: {
  51. extensions: ['.js', '.json', '.node']
  52. },
  53. target: 'electron-main'
  54. }
  55. /**
  56. * Adjust mainConfig for development settings
  57. */
  58. if (process.env.NODE_ENV !== 'production') {
  59. mainConfig.plugins.push(
  60. new webpack.DefinePlugin({
  61. '__static': `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"`
  62. })
  63. )
  64. }
  65. /**
  66. * Adjust mainConfig for production settings
  67. */
  68. if (process.env.NODE_ENV === 'production') {
  69. mainConfig.plugins.push(
  70. new MinifyPlugin(),
  71. new webpack.DefinePlugin({
  72. 'process.env.NODE_ENV': '"production"'
  73. })
  74. )
  75. }
  76. module.exports = mainConfig