vue.config.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. module.exports = {
  21. publicPath: process.env.BASE_URL,
  22. parallel: false,
  23. productionSourceMap: false,
  24. devServer: {
  25. proxy: {
  26. '^/testServer': {
  27. target: 'http://192.168.3.207:8181/',
  28. changeOrigin: true,
  29. logLevel: 'debug',
  30. pathRewrite: {
  31. '/testServer': ''
  32. }
  33. }
  34. }
  35. },
  36. css: {
  37. loaderOptions: {
  38. sass: {
  39. prependData: '@import "@/style/_mixin.scss";@import "@/style/_variables.scss";@import "@/style/base.scss";@import "@/style/common.scss";' // 全局引入
  40. },
  41. postcss: {
  42. plugins: [
  43. autoprefixer(),
  44. pxtoviewport(({
  45. unitToConvert: 'px',
  46. viewportWidth: 375,
  47. unitPrecision: 5,
  48. propList: [
  49. '*'
  50. ],
  51. viewportUnit: 'vw',
  52. fontViewportUnit: 'vw',
  53. selectorBlackList: [],
  54. minPixelValue: 1,
  55. mediaQuery: false,
  56. replace: true,
  57. exclude: /(\/|\\)(node_modules)(\/|\\)/
  58. }))
  59. // pxtorem({
  60. // rootValue: 37.5,
  61. // propList: ['*']
  62. // })
  63. ]
  64. }
  65. }
  66. },
  67. chainWebpack: config => {
  68. // 防止多页面打包卡顿
  69. // eslint-disable-next-line no-unused-expressions
  70. // config.plugins.delete('named-chunks')
  71. if (process.env.NODE_ENV === 'production') {
  72. // 打包时需要执行,开发环境运行不需要执行
  73. config.externals(externals)
  74. }
  75. if (process.env.use_analyzer) {
  76. config
  77. .plugin('webpack-bundle-analyzer')
  78. .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
  79. }
  80. config.module
  81. .rule('ts')
  82. .use('ts-loader')
  83. .tap(options => {
  84. options = merge(options, {
  85. transpileOnly: true,
  86. getCustomTransformers: () => ({
  87. before: [
  88. tsImportPluginFactory({
  89. libraryName: 'vant',
  90. libraryDirectory: 'es',
  91. style: true
  92. })
  93. ]
  94. }),
  95. compilerOptions: {
  96. module: 'es2015'
  97. }
  98. })
  99. return options
  100. })
  101. // return config
  102. }
  103. }