vue.config.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. const webpack = require("webpack");
  2. const path = require("path");
  3. const CompressionWebpackPlugin = require("compression-webpack-plugin");
  4. let env = process.env.NODE_ENV;
  5. module.exports = {
  6. // 如果是hash模式
  7. publicPath: env !== "development" ? "./" : "/",
  8. // 如果是history模式
  9. // publicPath: env !== "development" ? "/" : "/",
  10. // 静态资源目录 (js, css, img, fonts)
  11. assetsDir: "assets",
  12. //关键点在这 原来的 Compiler 换成了 runtimeCompiler
  13. runtimeCompiler: true,
  14. //设置打包之后是否打包.map文件
  15. productionSourceMap: env !== "development" ? false : true,
  16. // 输出文件目录
  17. outputDir: "dist",
  18. // 让样式找到源
  19. css: {
  20. sourceMap: true
  21. },
  22. devServer: {
  23. port: 8083,
  24. host: "0.0.0.0",
  25. hot: true,
  26. open: false,
  27. disableHostCheck: true,
  28. proxy: {
  29. "/api": {
  30. target: "127.0.0.1", //对应跨域的接口
  31. changeOrigin: true,
  32. ws: false,
  33. pathRewrite: {
  34. "^/api": ""
  35. }
  36. }
  37. }
  38. },
  39. chainWebpack: config => {
  40. config.resolve.alias.set("@", path.resolve(__dirname, "./src"));
  41. },
  42. configureWebpack: config => {
  43. if (env !== "development") {
  44. // 配置打包 压缩js
  45. config.plugins.push(
  46. new CompressionWebpackPlugin({
  47. algorithm: "gzip",
  48. test: /\.js$|\.html$|.\css/, //匹配文件名
  49. threshold: 10240, //对超过10k的数据压缩
  50. deleteOriginalAssets: false, //不删除源文件
  51. minRatio: 0.8
  52. })
  53. );
  54. }
  55. }
  56. };