vue.config.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. const webpack = require('webpack')
  2. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  3. const productionGzipExtensions = ['js', 'css']
  4. module.exports = {
  5. configureWebpack: {
  6. externals: {
  7. 'AMap': 'AMap' // 高德地图JS API
  8. },
  9. // 启用gzip
  10. plugins: [
  11. new CompressionWebpackPlugin({
  12. algorithm: 'gzip',
  13. test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
  14. threshold: 10240,
  15. minRatio: 0.8,
  16. deleteOriginalAssets: false // 是否删除源文件
  17. }),
  18. new webpack.optimize.LimitChunkCountPlugin({
  19. maxChunks: 5,
  20. minChunkSize: 100
  21. })
  22. ]
  23. },
  24. //路径前缀
  25. publicPath: "/",
  26. lintOnSave: true,
  27. productionSourceMap: false,
  28. chainWebpack: (config) => {
  29. //忽略的打包文件
  30. config.externals({
  31. 'vue': 'Vue',
  32. 'vue-router': 'VueRouter',
  33. 'vuex': 'Vuex',
  34. 'axios': 'axios',
  35. 'element-ui': 'ELEMENT',
  36. });
  37. const entry = config.entry('app');
  38. entry.add('babel-polyfill').end();
  39. entry.add('classlist-polyfill').end();
  40. entry.add('@/mock').end();
  41. },
  42. css: {
  43. extract: { ignoreOrder: true }
  44. },
  45. //开发模式反向代理配置,生产模式请使用Nginx部署并配置反向代理
  46. devServer: {
  47. port: 1024,
  48. proxy: {
  49. '/api': {
  50. //本地服务接口地址
  51. target: 'http://127.0.0.1:1080',
  52. ws: true,
  53. pathRewrite: {
  54. '^/api': '/'
  55. }
  56. }
  57. }
  58. }
  59. };