vue.config.js 7.6 KB

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