vue.config.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. module.exports = {
  2. configureWebpack: {
  3. externals: {
  4. 'AMap': 'AMap' // 高德地图JS API
  5. }
  6. },
  7. //路径前缀
  8. publicPath: "/",
  9. lintOnSave: true,
  10. productionSourceMap: false,
  11. chainWebpack: (config) => {
  12. //gzip压缩
  13. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  14. if (process.env.NODE_ENV === 'production') {
  15. config.plugin('CompressionPlugin').use(
  16. new CompressionWebpackPlugin({
  17. filename: '[path][base].gz[query]', // 压缩后的文件名(保持原文件名,后缀加.gz)
  18. algorithm: 'gzip', // 使用gzip压缩
  19. test: /\.js$|\.css$/, // 匹配文件名
  20. threshold: 10240, // 对超过10k的数据压缩
  21. minRatio: 0.8, // 压缩率小于1才会压缩
  22. deleteOriginalAssets: false // 是否删除未压缩的源文件,谨慎设置,如果希望提供非gzip的资源,可不设置或者设置为false(比如删除打包后的gz后还可以加载到原始资源文件)
  23. })
  24. )
  25. }
  26. // 开启压缩js代码
  27. config.optimization.minimize(true)
  28. // 开启代码分割
  29. config.optimization.splitChunks({
  30. chunks: 'all',
  31. });
  32. //忽略的打包文件
  33. config.externals({
  34. 'vue': 'Vue',
  35. 'vue-router': 'VueRouter',
  36. 'vuex': 'Vuex',
  37. 'axios': 'axios',
  38. 'element-ui': 'ELEMENT',
  39. });
  40. const entry = config.entry('app');
  41. entry.add('babel-polyfill').end();
  42. entry.add('classlist-polyfill').end();
  43. entry.add('@/mock').end();
  44. },
  45. css: {
  46. extract: { ignoreOrder: true }
  47. },
  48. //开发模式反向代理配置,生产模式请使用Nginx部署并配置反向代理
  49. devServer: {
  50. port: 1024,
  51. proxy: {
  52. '/api': {
  53. //本地服务接口地址
  54. // target: 'http://192.168.3.64:1080',
  55. // target: 'http://192.168.8.106:1080',
  56. target: 'http://127.0.0.1:1080',
  57. // 打包地址
  58. // target: 'http://121.37.83.47:10004',//服务器ip
  59. // target: 'http://trade.tubaosoft.com:10004',//服务器域名
  60. ws: true,
  61. pathRewrite: {
  62. '^/api': '/'
  63. }
  64. }
  65. }
  66. }
  67. };