config.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. 'use strict';
  2. const path = require('path');
  3. const dayjs = require('dayjs');
  4. const storage = require('./lib/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. contextIsolation: false, // 设置此项为false后,才可在渲染进程中使用electron api
  39. nodeIntegration: true,
  40. preload: path.join(__dirname, '../preload.js')
  41. },
  42. //frame: false,
  43. //titleBarStyle: 'hidden'
  44. },
  45. egg: {
  46. title: 'electron-egg', // 进程的title属性标识,无需改动
  47. env: 'prod',
  48. port: 7068,
  49. hostname: 'localhost',
  50. workers: 1
  51. },
  52. autoUpdate: {
  53. windows: false, // windows可以开启;macOs 需要签名验证
  54. macOS: false,
  55. Linux: false,
  56. options: {
  57. provider: 'generic', // or github, s3, bintray
  58. url: 'https://raw.githubusercontent.com/wallace5303/electron-egg/master/' // resource dir
  59. }
  60. }
  61. }
  62. exports.get = function (flag = '', env = 'prod') {
  63. console.log('[config] [get] flag:', flag);
  64. if (flag === 'developmentMode') {
  65. return config.developmentMode;
  66. }
  67. if (flag === 'log') {
  68. return config.log;
  69. }
  70. if (flag === 'windowsOption') {
  71. return config.windowsOption;
  72. }
  73. if (flag === 'webEgg') {
  74. return config.egg;
  75. }
  76. if (flag === 'egg') {
  77. const eggConfig = storage.getEggConfig();
  78. if (env === 'prod' && eggConfig.port) {
  79. config.egg.port = eggConfig.port;
  80. }
  81. return config.egg;
  82. }
  83. if (flag === 'autoUpdate') {
  84. return config.autoUpdate;
  85. }
  86. return {};
  87. };
  88. exports = module.exports;