vue.config.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. const path = require('path')
  2. function resolve (dir) {
  3. return path.join(__dirname, dir)
  4. }
  5. console.log('环境', process.env.NODE_ENV, require('./package.json').version)
  6. const pagesObject = {
  7. index: {
  8. title: process.env.VUE_APP_PROJECT_NAME,
  9. entry: 'src/main.js', // entry for the public page
  10. template: 'public/index.html', // source template
  11. filename: 'index.html' // output as dist/*
  12. },
  13. worker: {
  14. entry: 'src/worker.js',
  15. template: 'public/worker.html',
  16. filename: 'worker.html'
  17. }
  18. }
  19. module.exports = {
  20. pages: pagesObject,
  21. transpileDependencies: [
  22. 'vue-echarts',
  23. 'resize-detector'
  24. ],
  25. productionSourceMap: true,
  26. // vue.config.js里在开发时关闭sourcemap
  27. // 通过关闭8.x分支开发时的sourcemap,可以极大减少内存使用,从1G左右降到500MB。
  28. // 关闭sourcemap以后,8.x分支热更新不再堆内存溢出,报JavaScript heap out of memory这种错。
  29. // 相关issue链接:https://github.com/vuejs/vue-cli/issues/1453#issuecomment-396811585
  30. // yyx990803 commented on Jun 13, 2018:
  31. // @octref we can do that for now. Although in the long run we probably want to see if there's anything we can do to reduce the heap usage.
  32. // I think it's because a single Vue file actually involves multiple source maps being passed and merged.
  33. // 关键词:vue-cli-service electron:serve JavaScript heap out of memory
  34. configureWebpack: {
  35. devtool: 'none'
  36. },
  37. css: {
  38. // 注入全局样式变量
  39. loaderOptions: {
  40. sass: {
  41. data: `
  42. @import "@/assets/scss/variables.scss";
  43. `
  44. }
  45. }
  46. },
  47. chainWebpack: (config) => {
  48. config.resolve.alias
  49. .set('@', resolve('src'))
  50. .set('imgs', resolve('src/assets/imgs'))
  51. config.module.rules.delete('svg')
  52. config.module
  53. .rule('svg-smart')
  54. .test(/\.svg$/)
  55. .include
  56. .add(resolve('src/icons'))
  57. .end()
  58. .use('svg-sprite-loader')
  59. .loader('svg-sprite-loader')
  60. .options({
  61. symbolId: 'icon-[name]'
  62. })
  63. Object.keys(pagesObject).forEach(page => {
  64. config.plugins.delete(`preload-${page}`)
  65. config.plugins.delete(`prefetch-${page}`)
  66. })
  67. },
  68. pluginOptions: {
  69. electronBuilder: {
  70. externals: ['ffi', 'ref', 'ref-struct', 'ref-array', 'buffertrim'],
  71. // If you are using Yarn Workspaces, you may have multiple node_modules folders
  72. // List them all here so that VCP Electron Builder can find them
  73. nodeModulesPath: ['../../node_modules', './node_modules'],
  74. builderOptions: {
  75. productName: process.env.VUE_APP_PROJECT_NAME,
  76. appId: 'org.clearticket_new.cleartv',
  77. win: {
  78. icon: `build/${process.env.VUE_APP_LOGO ? process.env.VUE_APP_LOGO : 'icons'}/icon.ico`
  79. },
  80. nsis: {
  81. installerIcon: `build/${process.env.VUE_APP_LOGO ? process.env.VUE_APP_LOGO : 'icons'}/icon.ico`,
  82. installerHeaderIcon: `build/${process.env.VUE_APP_LOGO ? process.env.VUE_APP_LOGO : 'icons'}/icon.ico`,
  83. // eslint-disable-next-line no-template-curly-in-string
  84. artifactName: '${productName}_Setup_${version}.${ext}'
  85. },
  86. publish: [
  87. {
  88. provider: 'generic',
  89. url: 'http://127.0.0.1:8080'
  90. }
  91. ],
  92. asar: true,
  93. asarUnpack: [
  94. 'public/pos',
  95. 'public/iccard',
  96. 'public/donsee'
  97. ],
  98. extraFiles: [{
  99. from: 'public/pos',
  100. to: './resources/app.asar.unpacked/pos/'
  101. },
  102. {
  103. from: 'public/desheng',
  104. to: './resources/app.asar.unpacked/desheng/'
  105. },
  106. {
  107. from: 'public/iccard',
  108. to: './resources/app.asar.unpacked/iccard/'
  109. },
  110. {
  111. from: 'public/donsee',
  112. to: './resources/app.asar.unpacked/donsee/'
  113. }],
  114. directories: {
  115. output: `dist_electron/${process.env.VUE_APP_PROJECT}/${require('./package.json').version}`
  116. }
  117. }
  118. }
  119. }
  120. }