webpack.main.config.js 1.5 KB

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