nuxt.config.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import * as path from "path";
  2. const devPort = 3000;
  3. const serverPort = 4201;
  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. '@/assets/tailwindCom.css',
  44. ],
  45. // Auto import components (https://go.nuxtjs.dev/config-components)
  46. components: true,
  47. // Modules for dev and build (recommended) (https://go.nuxtjs.dev/config-modules)
  48. buildModules: [
  49. '@nuxtjs/tailwindcss'
  50. ],
  51. // Modules (https://go.nuxtjs.dev/config-modules)
  52. modules: [
  53. // https://go.nuxtjs.dev/axios
  54. '@nuxtjs/axios',
  55. // '@nuxtjs/style-resources',
  56. ],
  57. plugins: [
  58. "@plugins/svg-icon.js",
  59. // {src: '~/plugins/vue-pdf.js', ssr: false}
  60. ],
  61. // api中间件
  62. serverMiddleware: [
  63. '~/server/index.js'
  64. ],
  65. // styleResources: {
  66. // scss: [
  67. // '~/assets/_var.scss'
  68. // ]
  69. // },
  70. // Axios module configuration (https://go.nuxtjs.dev/config-axios)
  71. axios: {
  72. proxy: true
  73. },
  74. proxy: {
  75. },
  76. // Build Configuration (https://go.nuxtjs.dev/config-build)
  77. build: {
  78. extractCSS: true,
  79. extend(config, ctx) {
  80. loadSvgConfig(config,ctx);
  81. // 合并js文件
  82. // config.optimization.splitChunks = {
  83. // chunks: 'all',
  84. // minChunks: 1,
  85. // cacheGroups: {
  86. // vendor: {
  87. // test: /[\\/]node_modules[\\/]/,
  88. // name(module) {
  89. // // get the name. E.g. node_modules/packageName/not/this/part.js
  90. // // or node_modules/packageName
  91. // const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
  92. // // npm package names are URL-safe, but some servers don't like @ symbols
  93. // return `npm.${packageName.replace('@', '')}`;
  94. // }
  95. // }
  96. // }
  97. // }
  98. },
  99. },
  100. env : process.env.NODE_ENV === 'production' ? env.pro : env.dev,
  101. server: {
  102. // 根据环境变量判断当前运行环境 nuxt start 使用production环境
  103. port: process.env.NODE_ENV === 'production' ? serverPort : devPort, // default: 3000
  104. host: '0.0.0.0', // default: localhost
  105. },
  106. generate: {
  107. routes:
  108. [
  109. '/product/m2m',
  110. '/product/aiCam',
  111. '/product/sm',
  112. '/product/low',
  113. '/product/cam',
  114. '/product/item/m2m',
  115. '/product/item/aiCam',
  116. '/product/item/sm',
  117. '/product/item/low',
  118. '/product/item/cam',
  119. '/solution/sol',
  120. '/solution/acs',
  121. '/solution/epower',
  122. '/solution/item/sol',
  123. '/solution/item/acs',
  124. '/solution/item/epower',
  125. '/news/com',
  126. '/news/pa',
  127. '/news/in',
  128. '/news/item/com',
  129. '/news/item/pa',
  130. '/news/item/in',
  131. ]
  132. }
  133. }