vue.config.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. const path = require('path')
  2. const package = require('./package.json')
  3. const timeTrans = require('./src/renderer/utils/timeTrans')
  4. const isDevelopment = process.env.NODE_ENV == "development"
  5. const fs = require('fs');
  6. const versionInfo = {
  7. "buildTime": timeTrans({}),
  8. "version": package.version
  9. }
  10. fs.writeFile("./src/renderer/pages/version/versionInfo.json", JSON.stringify(versionInfo),
  11. err => {console.log('project build: at ' + versionInfo.buildTime + "\r\n");}
  12. )
  13. function resolve(dir) {
  14. return path.join(__dirname, dir);
  15. }
  16. module.exports = {
  17. lintOnSave: false,
  18. runtimeCompiler: true,
  19. assetsDir: "public",
  20. publicPath: !isDevelopment ? "./" : "/",
  21. productionSourceMap: true,
  22. // webpack的相关配置
  23. configureWebpack: {
  24. entry: "./src/renderer/main.js",
  25. resolve: {
  26. extensions: [".js", ".vue", ".json", ".ts", ".less"],
  27. alias: {
  28. "@": resolve("src/renderer"),
  29. },
  30. },
  31. // 公共资源合并
  32. optimization: {
  33. splitChunks: {
  34. cacheGroups: {
  35. vendor: {
  36. chunks: "all",
  37. test: /node_modules/,
  38. name: "vendor",
  39. minChunks: 1,
  40. maxInitialRequests: 5,
  41. minSize: 0,
  42. priority: 100,
  43. },
  44. common: {
  45. chunks: "all",
  46. test: /[\\/]src[\\/]js[\\/]/,
  47. name: "common",
  48. minChunks: 2,
  49. maxInitialRequests: 5,
  50. minSize: 0,
  51. priority: 60,
  52. },
  53. styles: {
  54. name: "styles",
  55. test: /\.(sa|sc|le|c)ss$/,
  56. chunks: "all",
  57. enforce: true,
  58. },
  59. runtimeChunk: {
  60. name: "manifest",
  61. },
  62. },
  63. },
  64. },
  65. // 性能警告修改
  66. performance: {
  67. hints: "warning",
  68. // 入口起点的最大体积 整数类型(以字节为单位)
  69. maxEntrypointSize: 50000000,
  70. // 生成文件的最大体积 整数类型(以字节为单位 300k)
  71. maxAssetSize: 30000000,
  72. // 只给出 js 文件的性能提示
  73. assetFilter: function (assetFilename) {
  74. return assetFilename.endsWith(".js");
  75. },
  76. },
  77. },
  78. chainWebpack: (config) => {
  79. // 分析插件
  80. // config
  81. // .plugin("webpack-bundle-analyzer")
  82. // .use(require("webpack-bundle-analyzer").BundleAnalyzerPlugin)
  83. // .end();
  84. },
  85. // 打包输出路径
  86. outputDir: "dist/web",
  87. productionSourceMap: false,
  88. // 构建时开启多进程处理 babel 编译
  89. // parallel: require('os').cpus().length > 1,
  90. css: {
  91. // 是否使用css分离插件 ExtractTextPlugin
  92. extract: !isDevelopment,
  93. // 开启 CSS source maps?
  94. sourceMap: isDevelopment,
  95. // css预设器配置项
  96. loaderOptions: {
  97. less: {
  98. modifyVars: {
  99. "primary-color": "#c62f2f",
  100. "link-color": "#c62f2f",
  101. "border-radius-base": "4px",
  102. },
  103. javascriptEnabled: true,
  104. },
  105. },
  106. // 启用 CSS modules for all css / pre-processor files.
  107. requireModuleExtension: true,
  108. },
  109. // 开发服务器http代理
  110. devServer: {
  111. open: !process.argv.includes("electron:serve"),
  112. host: "localhost",
  113. port: 9080,
  114. https: false,
  115. hotOnly: false,
  116. },
  117. // 第三方插件配置
  118. pluginOptions: {
  119. // vue-cli-plugin-electron-builder配置
  120. electronBuilder: {
  121. nodeIntegration: true,
  122. builderOptions: {
  123. publish: {
  124. "provider": "generic",
  125. "url": "",
  126. },
  127. win: {
  128. icon: "build/electron-icon/icon.ico",
  129. // 图标路径 windows系统中icon需要256*256的ico格式图片,更换应用图标亦在此处
  130. target: [
  131. {
  132. // 打包成一个独立的 exe 安装程序
  133. target: "nsis",
  134. // 这个意思是打出来32 bit + 64 bit的包,但是要注意:这样打包出来的安装包体积比较大,所以建议直接打32的安装包。
  135. arch: [
  136. // "x64",
  137. 'ia32'
  138. ],
  139. },
  140. ],
  141. },
  142. dmg: {
  143. contents: [
  144. {
  145. x: 410,
  146. y: 150,
  147. type: "link",
  148. path: "/Applications",
  149. },
  150. {
  151. x: 130,
  152. y: 150,
  153. type: "file",
  154. },
  155. ],
  156. },
  157. linux: {
  158. icon: "build/electron-icon/icon.png",
  159. target: "AppImage",
  160. },
  161. // mac: {
  162. // icon: "build/electron-icon/icon.icns",
  163. // },
  164. files: ["**/*"],
  165. asar: true,
  166. nsis: {
  167. // 是否一键安装,建议为 false,可以让用户点击下一步、下一步、下一步的形式安装程序,如果为true,当用户双击构建好的程序,自动安装程序并打开,即:一键安装(one-click installer)
  168. oneClick: true,
  169. // 允许请求提升。 如果为false,则用户必须使用提升的权限重新启动安装程序。
  170. allowElevation: true,
  171. // 允许修改安装目录,建议为 true,是否允许用户改变安装目录,默认是不允许
  172. allowToChangeInstallationDirectory: false,
  173. // 安装图标
  174. installerIcon: "build/electron-icon/icon.ico",
  175. // 卸载图标
  176. uninstallerIcon: "build/electron-icon/icon.ico",
  177. // 安装时头部图标
  178. installerHeaderIcon: "build/electron-icon/icon.ico",
  179. // 创建桌面图标
  180. createDesktopShortcut: true,
  181. // 创建开始菜单图标
  182. createStartMenuShortcut: true,
  183. perMachine: false,
  184. artifactName: `${package.productName}-${package.version}${timeTrans({format:'YMDh'})}.exe`,
  185. // "deleteAppDataOnUninstall": true,
  186. // "runAfterFinish": true,
  187. // "differentialPackage": true
  188. },
  189. },
  190. chainWebpackMainProcess: (config) => {
  191. config.plugin("define").tap((args) => {
  192. args[0]["IS_ELECTRON"] = true;
  193. return args;
  194. });
  195. },
  196. chainWebpackRendererProcess: (config) => {
  197. config.plugin("define").tap((args) => {
  198. args[0]["IS_ELECTRON"] = true;
  199. return args;
  200. });
  201. },
  202. outputDir: "dist/electron",
  203. mainProcessFile: "src/main/main.js",
  204. mainProcessWatch: ["src/main"],
  205. },
  206. },
  207. };