vue.config.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. // vue.config.js
  2. const path = require('path')
  3. // 包体积分析
  4. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
  5. const CompressionPlugin = require('compression-webpack-plugin')
  6. function resolve(dir) {
  7. return path.join(__dirname, dir)
  8. }
  9. // console.log('当前的env环境')
  10. // console.log(process.env.NODE_ENV)
  11. module.exports = {
  12. // 部署生产环境和开发环境下的URL。
  13. // 默认情况下,Vue CLI 会假设你的应用是被部署在一个域名的根路径上
  14. // 例如 https://www.my-app.com/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。
  15. // 例如,如果你的应用被部署在 https://www.my-app.com/my-app/,则设置 baseUrl 为 /my-app/。
  16. // baseUrl 从 Vue CLI 3.3 起已弃用,请使用publicPath
  17. // baseUrl: process.env.NODE_ENV === "production" ? "./" : "/",
  18. publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
  19. // outputDir: 在npm run build 或 yarn build 时 ,生成文件的目录名称(要和baseUrl的生产环境路径一致)
  20. outputDir: process.env.VUE_APP_OUTPUT_DIR, //打包后的目录名称
  21. // 用于放置生成的静态资源 (js、css、img、fonts) 的;(项目打包之后,静态资源会放在这个文件夹下)
  22. assetsDir: 'static', // 静态资源目录名称
  23. // 指定生成的 index.html 的输出路径 (打包之后,改变系统默认的index.html的文件名)
  24. // indexPath: "index.html",
  25. // 默认情况下,生成的静态资源在它们的文件名中包含了 hash 以便更好的控制缓存。
  26. // 你可以通过将这个选项设为 false 来关闭文件名哈希。(false的时候就是让原来的文件名不改变)
  27. filenameHashing: false,
  28. // lintOnSave:{ type:Boolean default:true } 问你是否使用eslint
  29. lintOnSave: true,
  30. // 如果你想要在生产构建时禁用 eslint-loader,你可以用如下配置
  31. // lintOnSave: process.env.NODE_ENV !== 'production',
  32. // 是否使用包含运行时编译器的 Vue 构建版本。
  33. // 设置为 true 后你就可以在 Vue 组件中使用 template 选项了,但是这会让你的应用额外增加 10kb 左右。(默认false)
  34. // runtimeCompiler: false,
  35. /**
  36. * 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
  37. * 打包之后发现map文件过大,项目文件体积很大,设置为false就可以不输出map文件
  38. * map文件的作用在于:项目打包后,代码都是经过压缩加密的,如果运行时报错,输出的错误信息无法准确得知是哪里的代码报错。
  39. * 有了map就可以像未加密的代码一样,准确的输出是哪一行哪一列有错。
  40. * */
  41. productionSourceMap: false,
  42. // 它支持webPack-dev-server的所有选项
  43. devServer: {
  44. host: 'localhost',
  45. port: 8090, // 端口号
  46. https: false, // https:{type:Boolean}
  47. open: false //配置自动启动浏览器
  48. // proxy: 'http://localhost:4000' // 配置跨域处理,只有一个代理
  49. // 配置多个代理
  50. // proxy: {
  51. // "/api": {
  52. // target: "http://localhost:3000/api/",// 要访问的接口域名
  53. // ws: true,// 是否启用websockets
  54. // //开启代理:在本地会创建一个虚拟服务端,然后发送请求的数据,并同时接收请求的数据,
  55. // // 这样服务端和服务端进行数据的交互就不会有跨域问题
  56. // changeOrigin: true,
  57. // pathRewrite: {
  58. // //这里理解成用'/api'代替target里面的地址,比如我要调用'http://40.00.100.100:3002/user/add',
  59. // // 直接写'/api/user/add'即可
  60. // '^/api': ''
  61. // }
  62. // }
  63. // }
  64. },
  65. chainWebpack: (config) => {
  66. config.resolve.alias
  67. .set('@', resolve('src'))
  68. .set('assets', resolve('src/assets'))
  69. .set('components', resolve('src/components'))
  70. },
  71. configureWebpack: (config) => {
  72. // 生产环境打包分析体积
  73. if (process.env.NODE_ENV === 'production') {
  74. return {
  75. plugins: [
  76. new BundleAnalyzerPlugin(),
  77. new CompressionPlugin({
  78. algorithm: 'gzip',
  79. test: /\.js$|\.html$|\.css/, // 匹配文件名
  80. // filename: '[path].gz[query]', // 压缩后的文件名(保持原文件名,后缀加.gz)
  81. threshold: 10240, // 对超过10k的数据压缩
  82. deleteOriginalAssets: false, // 不删除源文件
  83. minRatio: 0.8 // 压缩比
  84. })
  85. ]
  86. }
  87. } else {
  88. config.devtool = 'eval-source-map'
  89. }
  90. },
  91. // 向所有 Sass/Less 样式传入共享的全局变量
  92. css: {
  93. loaderOptions: {
  94. // 给 sass-loader 传递选项
  95. sass: {
  96. // @/ 是 src/ 的别名
  97. // 所以这里假设你有 `src/variables.sass` 这个文件
  98. // 注意:在 sass-loader v7 中,这个选项名是 "data"
  99. prependData: `
  100. @import "~@/styles/mixin.scss";
  101. @import "~@/styles/_var.scss";
  102. `
  103. },
  104. // 默认情况下 `sass` 选项会同时对 `sass` 和 `scss` 语法同时生效
  105. // 因为 `scss` 语法在内部也是由 sass-loader 处理的
  106. // 但是在配置 `data` 选项的时候
  107. // `scss` 语法会要求语句结尾必须有分号,`sass` 则要求必须没有分号
  108. // 在这种情况下,我们可以使用 `scss` 选项,对 `scss` 语法进行单独配置
  109. scss: {
  110. prependData: `
  111. @import "@/styles/mixin.scss";
  112. @import "@/styles/_var.scss";
  113. `
  114. }
  115. }
  116. },
  117. pluginOptions: {
  118. electronBuilder: {
  119. // chainWebpackMainProcess: config => {
  120. // // Chain webpack config for electron main process only
  121. // },
  122. // chainWebpackRendererProcess: config => {
  123. // // Chain webpack config for electron renderer process only
  124. // // The following example will set IS_ELECTRON to true in your app
  125. // // config.plugin('define').tap(args => {
  126. // // args[0]['IS_ELECTRON'] = true
  127. // // return args
  128. // // })
  129. // },
  130. // Use this to change the entrypoint of your app's main process
  131. // mainProcessFile: 'src/background.js',
  132. // Provide an array of files that, when changed, will recompile the main process and restart Electron
  133. // Your main process file will be added by default
  134. // mainProcessWatch: [],
  135. // [1.0.0-rc.4+] Provide a list of arguments that Electron will be launched with during "electron:serve",
  136. // which can be accessed from the main process (src/background.js).
  137. // Note that it is ignored when --debug flag is used with "electron:serve", as you must launch Electron yourself
  138. // Command line args (excluding --debug, --dashboard, and --headless) are passed to Electron as well
  139. // mainProcessArgs: ['--arg-name', 'arg-value']
  140. builderOptions: {
  141. appId: 'com.jubochat.workchat.app',
  142. // "productName": "juliao", // 项目名,也是生成的安装文件名,即aDemo.exe
  143. copyright: 'Copyright © 2019 juliao', // 版权信息
  144. // "directories": {
  145. // "output": "./dist_electron" // 输出文件路径
  146. // },
  147. // "asar": true,
  148. // "dmg": {
  149. // "contents": [
  150. // {
  151. // "x": 410,
  152. // "y": 150,
  153. // "type": "link",
  154. // "path": "/Applications"
  155. // },
  156. // {
  157. // "x": 130,
  158. // "y": 150,
  159. // "type": "file"
  160. // }
  161. // ]
  162. // },
  163. mac: {
  164. icon: './public/app.icns'
  165. },
  166. win: {
  167. // win相关配置
  168. icon: './public/app.ico' // 图标,当前图标在根目录下,注意这里有两个坑
  169. // "target": [
  170. // {
  171. // "target": "nsis", // 利用nsis制作安装程序
  172. // "arch": [
  173. // "x64", // 64位
  174. // "ia32" // 32位
  175. // ]
  176. // }
  177. // ]
  178. },
  179. nsis: {
  180. oneClick: false, // 是否一键安装
  181. allowElevation: true, // 允许请求提升。 如果为false,则用户必须使用提升的权限重新启动安装程序。
  182. allowToChangeInstallationDirectory: true, // 允许修改安装目录
  183. installerIcon: './public/app.ico', // 安装图标
  184. uninstallerIcon: './public/app.ico', //卸载图标
  185. installerHeaderIcon: './public/app.ico', // 安装时头部图标
  186. createDesktopShortcut: true, // 创建桌面图标
  187. createStartMenuShortcut: true, // 创建开始菜单图标
  188. shortcutName: '企聊客服系统' // 图标名称
  189. },
  190. extraResources: [
  191. // 拷贝dll等静态文件到指定位置
  192. // {
  193. // "from": "./public/screen/PrintScr.exe",
  194. // "to": "../", // ./是放在app同级,../就放在根目录底下
  195. // },
  196. {
  197. from: './public/screen/PrScrn.dll',
  198. to: '../' // ./是放在app同级,../就放在根目录底下
  199. }
  200. ]
  201. // "publish": [
  202. // {
  203. // "provider": "generic",
  204. // "url": "http://**.**.**.**:3001/download/",//隐藏版本服务器地址
  205. // }
  206. // ]
  207. }
  208. }
  209. },
  210. pwa: {
  211. // icons: [
  212. // {
  213. // 'src': 'icons/android-chrome-192x192.png',
  214. // 'sizes': '192x192',
  215. // 'type': 'image/png',
  216. // },
  217. // {
  218. // 'src': 'icons/android-chrome-512x512.png',
  219. // 'sizes': '512x512',
  220. // 'type': 'image/png',
  221. // },
  222. // ],
  223. iconPaths: {
  224. favicon32: 'favicon.ico',
  225. favicon16: 'favicon.ico',
  226. appleTouchIcon: 'favicon.ico',
  227. maskIcon: 'favicon.ico',
  228. msTileImage: 'favicon.ico'
  229. }
  230. }
  231. }