vue.config.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. const {
  2. defineConfig
  3. } = require('@vue/cli-service')
  4. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  5. // 代码压缩
  6. const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
  7. const cdn = {
  8. js: [
  9. // `https://cdn.bootcdn.net/ajax/libs/vue/2.6.14/vue.min.js`,
  10. // `https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.14/index.min.js`,
  11. // `https://cdn.bootcdn.net/ajax/libs/axios/0.17.1/axios.min.js`,
  12. // `https://cdn.bootcdn.net/ajax/libs/vue-router/3.5.1/vue-router.min.js`,
  13. ]
  14. };
  15. module.exports = defineConfig({
  16. devServer:{
  17. host: '192.168.100.104',
  18. open:true
  19. },
  20. transpileDependencies: true,
  21. lintOnSave: false, //关闭eslint检查
  22. // 具体使用情况还需要看项目的配置
  23. publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
  24. assetsDir: 'static',
  25. configureWebpack: {
  26. externals: {
  27. // vue: 'Vue',
  28. // 'vue-router': 'VueRouter',
  29. // axios: 'axios',
  30. // 'element-ui': 'ELEMENT',
  31. },
  32. plugins: [
  33. new CompressionWebpackPlugin({
  34. algorithm: "gzip",
  35. test: /\.js$|\.html$|\.css$/, // 匹配文件名
  36. threshold: 10240, // 对超过10k的数据压缩
  37. deleteOriginalAssets: false, // 不删除源文件
  38. minRatio: 0.8 // 压缩比
  39. }),
  40. new UglifyJsPlugin({
  41. uglifyOptions: {
  42. compress: {
  43. drop_debugger: true,
  44. drop_console: true,
  45. pure_funcs: ['console.log']
  46. },
  47. output: {
  48. // 去掉注释内容
  49. comments: true
  50. }
  51. },
  52. sourceMap: false,
  53. parallel: true
  54. }),
  55. ],
  56. },
  57. chainWebpack: config => {
  58. config.plugin("html").tap(args => {
  59. args[0].cdn = cdn;
  60. return args;
  61. });
  62. }
  63. })