config.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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('./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. enable: false,
  53. options: {
  54. provider: 'generic', // or github, s3, bintray
  55. url: 'https://raw.githubusercontent.com/wallace5303/electron-egg/master/' // resource dir
  56. }
  57. }
  58. }
  59. exports.get = function (flag = '', env = 'prod') {
  60. console.log('[config] [get] flag:', flag);
  61. if (flag === 'developmentMode') {
  62. return config.developmentMode;
  63. }
  64. if (flag === 'log') {
  65. return config.log;
  66. }
  67. if (flag === 'windowsOption') {
  68. return config.windowsOption;
  69. }
  70. if (flag === 'webEgg') {
  71. return config.egg;
  72. }
  73. if (flag === 'egg') {
  74. const eggConfig = storage.getEggConfig();
  75. if (env === 'prod' && eggConfig.port) {
  76. config.egg.port = eggConfig.port;
  77. }
  78. return config.egg;
  79. }
  80. if (flag === 'autoUpdate') {
  81. return config.autoUpdate;
  82. }
  83. return {};
  84. };
  85. exports = module.exports;