vue.config.js 5.5 KB

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