nuxt.config.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import * as path from "path";
  2. const devPort = 3000;
  3. const serverPort = 3000;
  4. const env = {
  5. dev: {
  6. MODE: 'development',
  7. ENV_API: `http://127.0.0.1:${devPort}` //测试服务器地址
  8. },
  9. pro: {
  10. MODE: 'production',
  11. ENV_API: `http://127.0.0.1:${serverPort}` // 正式服务器地址
  12. }
  13. }
  14. function loadSvgConfig(config, ctx) {
  15. // 排除 nuxt 原配置的影响,Nuxt 默认有vue-loader,会处理svg,img等
  16. // 找到匹配.svg的规则,然后将存放svg文件的目录排除
  17. const svgRule = config.module.rules.find(rule => rule.test.test(".svg"));
  18. svgRule.exclude = [path.resolve(__dirname, "assets/icons/svg")];
  19. //添加loader规则
  20. config.module.rules.push({
  21. test: /\.svg$/, // 匹配.svg
  22. include: [path.resolve(__dirname, "assets/icons/svg")], // 将存放svg的目录加入到loader处理目录
  23. use: [
  24. { loader: "svg-sprite-loader", options: { symbolId: "icon-[name]" } }
  25. ]
  26. });
  27. }
  28. export default {
  29. // Global page headers (https://go.nuxtjs.dev/config-head)
  30. head: {
  31. title: '合方圆-合天地方圆',
  32. meta: [
  33. { charset: 'utf-8' },
  34. { name: 'viewport', content: 'width=device-width, initial-scale=1' },
  35. { hid: 'description', name: 'description', content: '' }
  36. ],
  37. link: [
  38. { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
  39. ]
  40. },
  41. css: [
  42. '@/assets/public.css'
  43. ],
  44. // Auto import components (https://go.nuxtjs.dev/config-components)
  45. components: true,
  46. // Modules for dev and build (recommended) (https://go.nuxtjs.dev/config-modules)
  47. buildModules: [
  48. '@nuxtjs/tailwindcss'
  49. ],
  50. // Modules (https://go.nuxtjs.dev/config-modules)
  51. modules: [
  52. // https://go.nuxtjs.dev/axios
  53. '@nuxtjs/axios',
  54. // '@nuxtjs/style-resources',
  55. ],
  56. plugins: [
  57. "@plugins/svg-icon.js",
  58. // {src: '~/plugins/vue-pdf.js', ssr: false}
  59. ],
  60. // api中间件
  61. serverMiddleware: [
  62. '~/server/index.js'
  63. ],
  64. // styleResources: {
  65. // scss: [
  66. // '~/assets/_var.scss'
  67. // ]
  68. // },
  69. // Axios module configuration (https://go.nuxtjs.dev/config-axios)
  70. axios: {
  71. proxy: true
  72. },
  73. proxy: {
  74. },
  75. // Build Configuration (https://go.nuxtjs.dev/config-build)
  76. build: {
  77. extractCSS: true,
  78. extend(config, ctx) {
  79. loadSvgConfig(config,ctx);
  80. // 合并js文件
  81. // config.optimization.splitChunks = {
  82. // chunks: 'all',
  83. // minChunks: 1,
  84. // cacheGroups: {
  85. // vendor: {
  86. // test: /[\\/]node_modules[\\/]/,
  87. // name(module) {
  88. // // get the name. E.g. node_modules/packageName/not/this/part.js
  89. // // or node_modules/packageName
  90. // const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
  91. // // npm package names are URL-safe, but some servers don't like @ symbols
  92. // return `npm.${packageName.replace('@', '')}`;
  93. // }
  94. // }
  95. // }
  96. // }
  97. },
  98. },
  99. server: {
  100. port: devPort, // default: 3000
  101. host: '0.0.0.0', // default: localhost
  102. },
  103. generate: {
  104. routes:
  105. [
  106. '/product/m2m',
  107. '/product/aiCam',
  108. '/product/sm',
  109. '/product/low',
  110. '/product/cam',
  111. '/product/item/m2m',
  112. '/product/item/aiCam',
  113. '/product/item/sm',
  114. '/product/item/low',
  115. '/product/item/cam',
  116. '/solution/sol',
  117. '/solution/acs',
  118. '/solution/epower',
  119. '/solution/item/sol',
  120. '/solution/item/acs',
  121. '/solution/item/epower',
  122. '/news/com',
  123. '/news/pa',
  124. '/news/in',
  125. '/news/item/com',
  126. '/news/item/pa',
  127. '/news/item/in',
  128. ]
  129. }
  130. }