nuxt.config.js 4.2 KB

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