vue.config.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. const timestamp = new Date().getTime();
  16. module.exports = defineConfig({
  17. devServer:{
  18. host: '192.168.100.104',
  19. open:true
  20. },
  21. transpileDependencies: true,
  22. lintOnSave: false, //关闭eslint检查
  23. // 具体使用情况还需要看项目的配置
  24. publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
  25. assetsDir: 'static',
  26. css: {
  27. extract: {
  28. filename: `assert/css/[name].${timestamp}.css`,
  29. chunkFilename: `assert/css/[name].${timestamp}.css`
  30. }
  31. },
  32. configureWebpack: {
  33. output: {
  34. filename: `assert/js/[name].${timestamp}.js`,
  35. chunkFilename: `assert/js/[name].${timestamp}.js`
  36. },
  37. externals: {
  38. // vue: 'Vue',
  39. // 'vue-router': 'VueRouter',
  40. // axios: 'axios',
  41. // 'element-ui': 'ELEMENT',
  42. },
  43. plugins: [
  44. new CompressionWebpackPlugin({
  45. algorithm: "gzip",
  46. test: /\.js$|\.html$|\.css$/, // 匹配文件名
  47. threshold: 10240, // 对超过10k的数据压缩
  48. deleteOriginalAssets: false, // 不删除源文件
  49. minRatio: 0.8 // 压缩比
  50. }),
  51. new UglifyJsPlugin({
  52. uglifyOptions: {
  53. compress: {
  54. drop_debugger: true,
  55. drop_console: true,
  56. pure_funcs: ['console.log']
  57. },
  58. output: {
  59. // 去掉注释内容
  60. comments: true
  61. }
  62. },
  63. sourceMap: false,
  64. parallel: true
  65. }),
  66. ],
  67. },
  68. chainWebpack: config => {
  69. config.plugin("html").tap(args => {
  70. args[0].cdn = cdn;
  71. return args;
  72. });
  73. }
  74. })