vue.config.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. // 静默 `legacy-js-api` 和 `@import` 警告
  88. sassOptions: {
  89. silenceDeprecations: ['legacy-js-api', 'import', 'global-builtin']
  90. },
  91. prependData: '@import "@/style/_mixin.scss";@import "@/style/_variables.scss";' // 全局引入
  92. },
  93. postcss: {
  94. plugins: [
  95. autoprefixer(),
  96. pxtoviewport(({
  97. unitToConvert: 'px',
  98. viewportWidth: 375,
  99. unitPrecision: 5,
  100. propList: [
  101. '*'
  102. ],
  103. viewportUnit: 'vw',
  104. fontViewportUnit: 'vw',
  105. selectorBlackList: [],
  106. minPixelValue: 1,
  107. mediaQuery: false,
  108. replace: true,
  109. exclude: /(\/|\\)(node_modules)(\/|\\)/
  110. }))
  111. ]
  112. }
  113. }
  114. },
  115. configureWebpack: {
  116. module: {
  117. rules: [
  118. {
  119. test: /\.mjs$/,
  120. include: /node_modules/,
  121. type: 'javascript/auto'
  122. }
  123. ]
  124. }
  125. },
  126. chainWebpack: config => {
  127. // 防止多页面打包卡顿
  128. // eslint-disable-next-line no-unused-expressions
  129. // config.plugins.delete('named-chunks')
  130. if (process.env.NODE_ENV === 'production') {
  131. config.output
  132. .chunkFilename('js/[name].[contenthash:10].js?v=[contenthash:8]')
  133. .filename('js/[name].[contenthash:10].js?v=[contenthash:8]')
  134. // 打包时需要执行,开发环境运行不需要执行
  135. config.externals(externals)
  136. // 如果使用多页面打包,使用vue inspect --plugins查看html是否在结果数组中
  137. config.plugin('html').tap(args => {
  138. // https://github.com/DanielRuf/html-minifier-terser#options-quick-reference
  139. // 禁止html压缩去空行
  140. // args[0].minify.collapseWhitespace = false
  141. // html中添加cdn
  142. args[0].cdn = cdn
  143. args[0].assets = {
  144. version: Date.now()
  145. }
  146. args[0].version = s_version
  147. return args
  148. })
  149. } else {
  150. config.plugin('html').tap(args => {
  151. // html中添加wxjsssk的cdn
  152. args[0].cdn = {
  153. js: [
  154. cdn.js[cdn.js.length - 1]
  155. ]
  156. }
  157. return args
  158. })
  159. }
  160. // 分析静态资源
  161. if (process.env.use_analyzer) {
  162. config
  163. .plugin('webpack-bundle-analyzer')
  164. .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
  165. }
  166. // 修复HMR
  167. config.resolve.symlinks(true)
  168. config.module
  169. .rule('ts')
  170. .use('ts-loader')
  171. .tap(options => {
  172. options = merge(options, {
  173. transpileOnly: true,
  174. getCustomTransformers: () => ({
  175. before: [
  176. tsImportPluginFactory({
  177. libraryName: 'vant',
  178. libraryDirectory: 'es',
  179. style: true
  180. })
  181. ]
  182. }),
  183. compilerOptions: {
  184. module: 'es2015'
  185. }
  186. })
  187. return options
  188. })
  189. }
  190. }