vue.config.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-11-28 01:41:11
  4. * @LastEditTime: 2022-05-08 20:02:12
  5. * @LastEditors: 张祥 17839092765@163.com
  6. * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  7. * @FilePath: \vue3ts\vue3\vue.config.js
  8. */
  9. const title = "鹤山工业城可视化平台";
  10. module.exports = {
  11. publicPath: "/",
  12. devServer: {
  13. // 配置服务器
  14. open: true,
  15. // 项目运行时候的端口号
  16. port: 8080,
  17. // https: false,
  18. disableHostCheck: true,
  19. overlay: {
  20. warnings: true,
  21. errors: true,
  22. },
  23. proxy: {
  24. "/api": {
  25. target: "http://127.0.0.1:8084/",
  26. changeOrigin: true,
  27. pathRewrite: {
  28. "^/api": "",
  29. },
  30. },
  31. "/restapi": {
  32. target: "https://restapi.amap.com/",
  33. changeOrigin: true,
  34. pathRewrite: {
  35. "^/restapi": "",
  36. },
  37. },
  38. },
  39. },
  40. css: {
  41. sourceMap: true, // 开启 CSS source maps
  42. loaderOptions: {
  43. sass: {
  44. prependData: "@import '@/styles/common.scss';",
  45. },
  46. },
  47. },
  48. chainWebpack: (config) => {
  49. config.plugin("html").tap((args) => {
  50. args[0].title = title;
  51. return args;
  52. });
  53. if (process.env.NODE_ENV === "production") {
  54. //生产包取消console debugger打印
  55. config.optimization.minimizer("terser").tap((args) => {
  56. args[0].terserOptions.compress.drop_console = true;
  57. args[0].terserOptions.compress.drop_debugger = true;
  58. args[0].terserOptions.compress.pure_funcs = ["console.log"];
  59. args[0].terserOptions.output = {
  60. comments: false,
  61. };
  62. return args;
  63. });
  64. }
  65. // 分析打包大小
  66. if (process.env.npm_config_report) {
  67. config
  68. .plugin("webpack-bundle-analyzer")
  69. .use(require("webpack-bundle-analyzer").BundleAnalyzerPlugin)
  70. .end();
  71. }
  72. },
  73. configureWebpack: {
  74. resolve: {
  75. extensions: [".js", ".vue", ".json", ".ts", ".tsx"], // 加入ts 和 tsx
  76. },
  77. },
  78. };