vue.config.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. const cdn = {
  21. css: [
  22. // '//unpkg.com/element-ui@2.10.1/lib/theme-chalk/index.css'
  23. ],
  24. js: [
  25. '//cdn-common.jianyu360.com/cdn/lib/vue/2.6.14/vue.min.js',
  26. '//cdn-common.jianyu360.com/cdn/lib/vue-router/3.1.5/vue-router.min.js',
  27. '//cdn-common.jianyu360.com/cdn/lib/vuex/3.4.0/vuex.min.js',
  28. '//cdn-common.jianyu360.com/cdn/lib/vant/2.8.2/lib/vant.min.js',
  29. '//cdn-common.jianyu360.com/cdn/lib/axios/0.19.2/axios.min.js',
  30. '//cdn-common.jianyu360.com/cdn/lib/js-cookie/2.2.1/js.cookie.min.js',
  31. '//cdn-common.jianyu360.com/cdn/lib/jquery/3.5.1/jquery.min.js',
  32. '//cdn-common.jianyu360.com/cdn/lib/moment/2.29.1/min/moment.min.js'
  33. // '//res.wx.qq.com/open/js/jweixin-1.6.0.js'
  34. ]
  35. }
  36. const s_version = process.env.npm_package_version.replace(/\./g, '')
  37. module.exports = {
  38. publicPath: process.env.BASE_URL,
  39. parallel: false,
  40. outputDir: 'page_entniche_new',
  41. productionSourceMap: false,
  42. devServer: {
  43. disableHostCheck: true,
  44. proxy: {
  45. '^/entbase': {
  46. // target: 'http://127.0.0.1:815',
  47. target: 'https://jybx-webtest.jydev.jianyu360.com',
  48. changeOrigin: true,
  49. logLevel: 'debug'
  50. },
  51. '^/jyapi': {
  52. // target: 'http://127.0.0.1:815',
  53. target: 'https://jybx-webtest.jydev.jianyu360.com',
  54. changeOrigin: true,
  55. logLevel: 'debug'
  56. },
  57. '^/entniche': {
  58. // target: 'http://127.0.0.1:812',
  59. target: 'https://jybx-webtest.jydev.jianyu360.com',
  60. changeOrigin: true,
  61. logLevel: 'debug'
  62. },
  63. '^/publicapply': {
  64. target: 'https://app5jytest.jydev.jianyu360.com/',
  65. changeOrigin: true,
  66. logLevel: 'debug'
  67. },
  68. '^/testServer': {
  69. target: 'https://jybx-webtest.jydev.jianyu360.com',
  70. changeOrigin: true,
  71. logLevel: 'debug',
  72. pathRewrite: {
  73. '/testServer': ''
  74. }
  75. },
  76. '^/jypay': {
  77. target: 'https://jybx-webtest.jydev.jianyu360.com',
  78. changeOrigin: true,
  79. logLevel: 'debug',
  80. pathRewrite: {
  81. '^/jypay': '/jypay'
  82. }
  83. },
  84. '^/bigmember': {
  85. target: 'https://jybx-webtest.jydev.jianyu360.com',
  86. changeOrigin: true,
  87. logLevel: 'debug',
  88. pathRewrite: {
  89. '^/bigmember': '/bigmember'
  90. }
  91. }
  92. }
  93. },
  94. css: {
  95. // extract: {
  96. // filename: 'css/[name].[contenthash:10].css?v=[contenthash:8]',
  97. // chunkFilename: 'css/[name].[contenthash:10].css?v=[contenthash:8]'
  98. // },
  99. loaderOptions: {
  100. sass: {
  101. prependData: '@import "@/style/_mixin.scss";@import "@/style/_variables.scss";' // 全局引入
  102. },
  103. postcss: {
  104. plugins: [
  105. autoprefixer(),
  106. pxtoviewport(({
  107. unitToConvert: 'px',
  108. viewportWidth: 375,
  109. unitPrecision: 5,
  110. propList: [
  111. '*'
  112. ],
  113. viewportUnit: 'vw',
  114. fontViewportUnit: 'vw',
  115. selectorBlackList: [],
  116. minPixelValue: 1,
  117. mediaQuery: false,
  118. replace: true,
  119. exclude: /(\/|\\)(node_modules)(\/|\\)/
  120. }))
  121. // pxtorem({
  122. // rootValue: 37.5,
  123. // propList: ['*']
  124. // })
  125. ]
  126. }
  127. }
  128. },
  129. chainWebpack: config => {
  130. // 防止多页面打包卡顿
  131. // eslint-disable-next-line no-unused-expressions
  132. // config.plugins.delete('named-chunks')
  133. if (process.env.NODE_ENV === 'production') {
  134. // config.output
  135. // .chunkFilename('js/[name].[contenthash:10].js?v=[contenthash:8]')
  136. // .filename('js/[name].[contenthash:10].js?v=[contenthash:8]')
  137. // 打包时需要执行,开发环境运行不需要执行
  138. config.externals(externals)
  139. config.plugin('html').tap(args => {
  140. // https://github.com/DanielRuf/html-minifier-terser#options-quick-reference
  141. // 禁止html压缩去空行
  142. // args[0].minify.collapseWhitespace = false
  143. // html中添加cdn
  144. args[0].cdn = cdn
  145. args[0].version = s_version
  146. args[0].assets = {
  147. version: Date.now()
  148. }
  149. return args
  150. })
  151. } else {
  152. // config.plugin('html').tap(args => {
  153. // // html中添加wxjsssk的cdn
  154. // args[0].cdn = {
  155. // js: [
  156. // cdn.js[cdn.js.length - 1]
  157. // ]
  158. // }
  159. // return args
  160. // })
  161. }
  162. // 分析静态资源
  163. if (process.env.use_analyzer) {
  164. config
  165. .plugin('webpack-bundle-analyzer')
  166. .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
  167. }
  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. // return config
  190. }
  191. }