vue.config.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. const merge = require('webpack-merge')
  2. const tsImportPluginFactory = require('ts-import-plugin')
  3. const autoprefixer = require('autoprefixer')
  4. // const pxtorem = require('postcss-pxtorem')
  5. const pxtoviewport = require('postcss-px-to-viewport')
  6. const externals = {
  7. vue: 'Vue',
  8. 'vue-router': 'VueRouter',
  9. vuex: 'Vuex',
  10. axios: 'axios',
  11. 'js-cookie': 'Cookies',
  12. vant: 'vant',
  13. moment: 'moment'
  14. }
  15. // cdn地址获取访问(国外): https://www.jsdelivr.com/
  16. // cdn地址获取访问(国内): https://www.bootcdn.cn/
  17. const cdn = {
  18. css: [
  19. // '//unpkg.com/element-ui@2.10.1/lib/theme-chalk/index.css'
  20. ],
  21. js: [
  22. '//cdn-common.jianyu360.com/cdn/lib/vue/2.7.16/vue.min.js',
  23. '//cdn-common.jianyu360.com/cdn/lib/vue-router/3.1.5/vue-router.min.js',
  24. '//cdn-common.jianyu360.com/cdn/lib/vuex/3.4.0/vuex.min.js',
  25. '//cdn-common.jianyu360.com/cdn/lib/vant/2.8.2/lib/vant.min.js',
  26. '//cdn-common.jianyu360.com/cdn/lib/axios/0.19.2/axios.min.js',
  27. '//cdn-common.jianyu360.com/cdn/lib/js-cookie/2.2.1/js.cookie.min.js',
  28. '//cdn-common.jianyu360.com/cdn/lib/moment/2.29.1/min/moment.min.js',
  29. '//res.wx.qq.com/open/js/jweixin-1.6.0.js'
  30. ]
  31. }
  32. const s_version = process.env.npm_package_version.replace(/\./g, '')
  33. module.exports = {
  34. publicPath: process.env.BASE_URL,
  35. parallel: false,
  36. productionSourceMap: false,
  37. outputDir: 'page_docs_mobile',
  38. devServer: {
  39. port: '8080',
  40. open: false,
  41. disableHostCheck: true,
  42. proxy: {
  43. '^/jydocs': {
  44. // target: 'https://web2-jytest.jydev.jianyu360.com',
  45. target: 'https://jybx3-webtest.jydev.jianyu360.com/',
  46. // target: 'http://192.168.20.180:821',
  47. changeOrigin: true,
  48. logLevel: 'debug'
  49. },
  50. '^/jypay': {
  51. // target: 'https://web2-jytest.jydev.jianyu360.com',
  52. target: 'https://jybx3-webtest.jydev.jianyu360.com/',
  53. // target: 'http://192.168.20.180:86',
  54. changeOrigin: true,
  55. logLevel: 'debug'
  56. },
  57. '^/jyintegral': {
  58. // target: 'https://web2-jytest.jydev.jianyu360.com',
  59. target: 'https://jybx3-webtest.jydev.jianyu360.com/',
  60. // target: 'http://192.168.20.145:820',
  61. changeOrigin: true,
  62. logLevel: 'debug'
  63. },
  64. '^/publicapply': {
  65. // target: 'https://web2-jytest.jydev.jianyu360.com',
  66. target: 'https://jybx3-webtest.jydev.jianyu360.com/',
  67. // target: 'http://192.168.20.145:820',
  68. changeOrigin: true,
  69. logLevel: 'debug'
  70. },
  71. '^/bigmember' : {
  72. // target: 'https://web2-jytest.jydev.jianyu360.com',
  73. target: 'https://jybx3-webtest.jydev.jianyu360.com/',
  74. // target: 'http://192.168.20.145:820',
  75. changeOrigin: true,
  76. logLevel: 'debug'
  77. }
  78. }
  79. },
  80. css: {
  81. extract: {
  82. filename: 'css/[name].[contenthash:10].css?v=[contenthash:8]',
  83. chunkFilename: 'css/[name].[contenthash:10].css?v=[contenthash:8]'
  84. },
  85. loaderOptions: {
  86. sass: {
  87. prependData: '@import "@/style/_mixin.scss";@import "@/style/_variables.scss";' // 全局引入
  88. },
  89. postcss: {
  90. plugins: [
  91. autoprefixer(),
  92. pxtoviewport(({
  93. unitToConvert: 'px',
  94. viewportWidth: 375,
  95. unitPrecision: 5,
  96. propList: [
  97. '*'
  98. ],
  99. viewportUnit: 'vw',
  100. fontViewportUnit: 'vw',
  101. selectorBlackList: [],
  102. minPixelValue: 1,
  103. mediaQuery: false,
  104. replace: true,
  105. exclude: /(\/|\\)(node_modules)(\/|\\)/
  106. }))
  107. ]
  108. }
  109. }
  110. },
  111. chainWebpack: config => {
  112. // 防止多页面打包卡顿
  113. // eslint-disable-next-line no-unused-expressions
  114. // config.plugins.delete('named-chunks')
  115. if (process.env.NODE_ENV === 'production') {
  116. config.output
  117. .chunkFilename('js/[name].[contenthash:10].js?v=[contenthash:8]')
  118. .filename('js/[name].[contenthash:10].js?v=[contenthash:8]')
  119. // 打包时需要执行,开发环境运行不需要执行
  120. config.externals(externals)
  121. // 如果使用多页面打包,使用vue inspect --plugins查看html是否在结果数组中
  122. config.plugin('html').tap(args => {
  123. // https://github.com/DanielRuf/html-minifier-terser#options-quick-reference
  124. // 禁止html压缩去空行
  125. // args[0].minify.collapseWhitespace = false
  126. // html中添加cdn
  127. args[0].cdn = cdn
  128. args[0].assets = {
  129. version: Date.now()
  130. }
  131. args[0].version = s_version
  132. return args
  133. })
  134. } else {
  135. config.plugin('html').tap(args => {
  136. // html中添加wxjsssk的cdn
  137. args[0].cdn = {
  138. js: [
  139. cdn.js[cdn.js.length - 1]
  140. ]
  141. }
  142. return args
  143. })
  144. }
  145. // 分析静态资源
  146. if (process.env.use_analyzer) {
  147. config
  148. .plugin('webpack-bundle-analyzer')
  149. .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
  150. }
  151. // 修复HMR
  152. config.resolve.symlinks(true)
  153. config.module
  154. .rule('ts')
  155. .use('ts-loader')
  156. .tap(options => {
  157. options = merge(options, {
  158. transpileOnly: true,
  159. getCustomTransformers: () => ({
  160. before: [
  161. tsImportPluginFactory({
  162. libraryName: 'vant',
  163. libraryDirectory: 'es',
  164. style: true
  165. })
  166. ]
  167. }),
  168. compilerOptions: {
  169. module: 'es2015'
  170. }
  171. })
  172. return options
  173. })
  174. }
  175. }