config.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. 'use strict';
  2. const path = require('path');
  3. const dayjs = require('dayjs');
  4. const storage = require('./storage');
  5. const config = {
  6. developmentMode: {
  7. default: 'vue',
  8. mode: {
  9. vue: {
  10. hostname: 'localhost',
  11. port: 8080
  12. },
  13. react: {
  14. hostname: 'localhost',
  15. port: 3000
  16. },
  17. ejs: {
  18. hostname: 'localhost',
  19. port: 7068 // The same as the egg port
  20. }
  21. }
  22. },
  23. log: {
  24. file: {
  25. fileName: path.normalize(storage.getStorageDir() + 'logs/electron-' + dayjs().format('YYYY-MM-DD') + '.log'),
  26. level: 'silly', // error, warn, info, verbose, debug, silly
  27. format: '[{y}-{m}-{d} {h}:{i}:{s}.{ms}] [{level}] {text}',
  28. maxSize: '1048576' // 1048576 (1mb) by default.
  29. }
  30. },
  31. windowsOption: {
  32. width: 980,
  33. height: 600,
  34. minWidth: 800,
  35. minHeight: 600,
  36. webPreferences: {
  37. //webSecurity: false,
  38. nodeIntegration: true,
  39. preload: path.join(__dirname, '../preload.js')
  40. },
  41. //frame: false,
  42. //titleBarStyle: 'hidden'
  43. },
  44. egg: {
  45. title: 'electron-egg',
  46. env: 'prod',
  47. port: 7068,
  48. hostname: 'localhost',
  49. workers: 1
  50. },
  51. autoUpdate: {
  52. windows: false, // windows可以开启;macOs 需要签名验证
  53. macOS: false,
  54. Linux: false,
  55. options: {
  56. provider: 'generic', // or github, s3, bintray
  57. url: 'https://raw.githubusercontent.com/wallace5303/electron-egg/master/' // resource dir
  58. }
  59. }
  60. }
  61. exports.get = function (flag = '', env = 'prod') {
  62. console.log('[config] [get] flag:', flag);
  63. if (flag === 'developmentMode') {
  64. return config.developmentMode;
  65. }
  66. if (flag === 'log') {
  67. return config.log;
  68. }
  69. if (flag === 'windowsOption') {
  70. return config.windowsOption;
  71. }
  72. if (flag === 'webEgg') {
  73. return config.egg;
  74. }
  75. if (flag === 'egg') {
  76. const eggConfig = storage.getEggConfig();
  77. if (env === 'prod' && eggConfig.port) {
  78. config.egg.port = eggConfig.port;
  79. }
  80. return config.egg;
  81. }
  82. if (flag === 'autoUpdate') {
  83. return config.autoUpdate;
  84. }
  85. return {};
  86. };
  87. exports = module.exports;