vue.config.js 7.4 KB

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