nuxt.config.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import * as path from "path";
  2. function loadSvgConfig(config, ctx) {
  3. // 排除 nuxt 原配置的影响,Nuxt 默认有vue-loader,会处理svg,img等
  4. // 找到匹配.svg的规则,然后将存放svg文件的目录排除
  5. const svgRule = config.module.rules.find(rule => rule.test.test(".svg"));
  6. svgRule.exclude = [path.resolve(__dirname, "assets/icons/svg")];
  7. //添加loader规则
  8. config.module.rules.push({
  9. test: /\.svg$/, // 匹配.svg
  10. include: [path.resolve(__dirname, "assets/icons/svg")], // 将存放svg的目录加入到loader处理目录
  11. use: [
  12. { loader: "svg-sprite-loader", options: { symbolId: "icon-[name]" } }
  13. ]
  14. });
  15. }
  16. export default {
  17. // Global page headers (https://go.nuxtjs.dev/config-head)
  18. head: {
  19. title: '合方圆-合天地方圆',
  20. meta: [
  21. { charset: 'utf-8' },
  22. { name: 'viewport', content: 'width=device-width, initial-scale=1' },
  23. { hid: 'description', name: 'description', content: '' }
  24. ],
  25. link: [
  26. { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
  27. ]
  28. },
  29. css: [
  30. '@/assets/public.css'
  31. ],
  32. // Auto import components (https://go.nuxtjs.dev/config-components)
  33. components: true,
  34. // Modules for dev and build (recommended) (https://go.nuxtjs.dev/config-modules)
  35. buildModules: [
  36. '@nuxtjs/tailwindcss'
  37. ],
  38. // Modules (https://go.nuxtjs.dev/config-modules)
  39. modules: [
  40. // https://go.nuxtjs.dev/axios
  41. '@nuxtjs/axios',
  42. ],
  43. plugins: ["@plugins/svg-icon.js"],
  44. // api中间件
  45. serverMiddleware: [
  46. '~/server/index.js'
  47. ],
  48. // Axios module configuration (https://go.nuxtjs.dev/config-axios)
  49. axios: {
  50. proxy: true
  51. },
  52. proxy: {
  53. '/api': {
  54. target: 'http://szhfy.com.cn/', // 目标接口域名
  55. pathRewrite: {
  56. '^/api': '/api', // 把 /api 替换成 /
  57. changeOrigin: true // 表示是否跨域
  58. }
  59. },
  60. '/public': {
  61. target: 'http://szhfy.com.cn/', // 目标接口域名
  62. pathRewrite: {
  63. changeOrigin: true // 表示是否跨域
  64. }
  65. }
  66. },
  67. // Build Configuration (https://go.nuxtjs.dev/config-build)
  68. build: {
  69. extend(config, ctx) {
  70. loadSvgConfig(config,ctx)
  71. }
  72. },
  73. server: {
  74. port: 8000, // default: 3000
  75. host: '0.0.0.0', // default: localhost
  76. }
  77. }