vue.config.js 6.9 KB

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