nuxt.config.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. const seoRouter = require("./plugins/seoRouter");
  2. const pkg = require("./package");
  3. if (process.env.NODE_ENV) {
  4. require("events").EventEmitter.defaultMaxListeners = 50;
  5. }
  6. const modifyHtml = html => {
  7. let htmlRegx = new RegExp("<style(([\\s\\S])*?)<\\/style>", "igm");
  8. let match = html.match(htmlRegx);
  9. if (match) {
  10. html = html.replace(htmlRegx, "");
  11. match.forEach((item, index) => {
  12. html = html.replace(/<\/body>/, item + "</body>");
  13. });
  14. }
  15. return html;
  16. };
  17. module.exports = {
  18. mode: "universal",
  19. watchers: {
  20. ignored: [".nuxt/**", "node_modules/**"],
  21. webpack: {
  22. watchOptions: {
  23. ignored: [".nuxt/**", "node_modules/**"]
  24. }
  25. }
  26. },
  27. vue: {
  28. config: {
  29. productionTip: process.env.NODE_ENV !== "development",
  30. devtools: process.env.NODE_ENV === "development"
  31. }
  32. },
  33. env: {
  34. baseUrl:
  35. process.env.NODE_ENV == "development"
  36. ? "https://dev.test.proginn.com"
  37. : "https://www.proginn.com",
  38. jishuBaseUrl:
  39. process.env.NODE_ENV == "development"
  40. ? "https://dev.test-jishuin.proginn.com"
  41. : "https://jishuin.proginn.com"
  42. },
  43. /**
  44. * 打包文件
  45. */
  46. build: {
  47. extractCSS: true,
  48. resourceHints: true,
  49. transpile: ['proginn-lib']
  50. },
  51. hooks: {
  52. // This hook is called before rendering the html to the browser
  53. "render:route": (url, page, { req, res }) => {
  54. // console.log(page.html.substring(page.html.indexOf("</body>") - 100));
  55. page.html = modifyHtml(page.html);
  56. // console.log(page.html.substring(page.html.indexOf("</body>") - 100));
  57. }
  58. },
  59. server: {
  60. host: `0.0.0.0`,
  61. port: 3000
  62. },
  63. /*
  64. ** Headers of the page
  65. */
  66. head: {
  67. title: "程序员客栈",
  68. meta: [
  69. {
  70. charset: "utf-8"
  71. },
  72. {
  73. name: "viewport",
  74. content: "width=device-width, initial-scale=1"
  75. },
  76. {
  77. name: "applicable-device",
  78. content: "pc, mobile "
  79. },
  80. {
  81. name: "baidu-site-verification",
  82. content: "7IbkIN9Kwp"
  83. },
  84. {
  85. "http-equiv": "X-UA-Compatible",
  86. content: "IE=edge,chrome=1"
  87. },
  88. // hid: 'x', 可在页面内覆盖这里
  89. {
  90. name: "robots",
  91. content: "noindex,follow"
  92. },
  93. {
  94. name: "description",
  95. content: pkg.description
  96. },
  97. {
  98. "http-equiv": "Cache-Control",
  99. content: "no-transform"
  100. },
  101. {
  102. "http-equiv": "Cache-Control",
  103. content: "no-siteapp"
  104. }
  105. ],
  106. link: [
  107. {
  108. rel: "icon",
  109. type: "image/x-icon",
  110. href: "/favicon.ico"
  111. }
  112. ]
  113. },
  114. /*
  115. ** Customize the progress-bar color
  116. */
  117. loading: {
  118. continuous: true
  119. },
  120. /*
  121. ** Global CSS
  122. */
  123. css: [
  124. "@/assets/css/common.css",
  125. "@/assets/css/special.css",
  126. "swiper/dist/css/swiper.css"
  127. ],
  128. /*
  129. ** Plugins to load before mounting the App
  130. */
  131. plugins: [
  132. "plugins/common",
  133. "plugins/element",
  134. "plugins/nuxtAxios",
  135. "plugins/deviceType",
  136. "plugins/vant",
  137. "plugins/router",
  138. {
  139. src: "plugins/vant.js",
  140. ssr: false
  141. },
  142. {
  143. src: "plugins/rem",
  144. ssr: false
  145. },
  146. {
  147. src: "plugins/vconsole",
  148. ssr: false
  149. },
  150. {
  151. src: "plugins/vue-swiper.js",
  152. ssr: false
  153. },
  154. {
  155. src: "plugins/g2.js",
  156. ssr: false
  157. }
  158. ],
  159. /*
  160. ** Axios module configuration
  161. */
  162. axios: {
  163. // See http://github.com/nuxt-community/axios-module#options
  164. proxy: process.env.NODE_ENV === "development",
  165. // http: true,
  166. progress: true,
  167. // baseURL: process.env.BASE_URL || '',
  168. // browserBaseURL: '',
  169. timeout: 15000,
  170. credentials: true,
  171. proxyHeaders: true
  172. // debug: true
  173. },
  174. /**
  175. * Proxy
  176. */
  177. proxy: [
  178. // ["/api", { target: "https://web.test.proginn.com", changeOrigin: true }],
  179. [
  180. "/api",
  181. {
  182. target: "https:/dev.test.proginn.com",
  183. changeOrigin: true
  184. }
  185. ],
  186. [
  187. "/list",
  188. {
  189. target: "https://dev.test-jishuin.proginn.com",
  190. changeOrigin: true
  191. }
  192. ],
  193. [
  194. "/file/proxyUpload",
  195. {
  196. target: "https://dev.test.proginn.com",
  197. changeOrigin: true
  198. }
  199. ],
  200. [
  201. "/file/prepareUpload",
  202. {
  203. target: "https://dev.test.proginn.com",
  204. changeOrigin: true
  205. }
  206. ],
  207. [
  208. "/file/uploadCallback",
  209. {
  210. target: "https://dev.test.proginn.com",
  211. changeOrigin: true
  212. }
  213. ],
  214. // [ '/programmerinnfile', { target: 'https://v0.api.upyun.com', changeOrigin: true } ],
  215. [
  216. "/upload_image",
  217. {
  218. target: "http://dev.test.proginn.com",
  219. changeOrigin: true
  220. }
  221. ],
  222. [
  223. "/image",
  224. {
  225. target: "https://stacdn.proginn.com",
  226. changeOrigin: true
  227. }
  228. ]
  229. ],
  230. buildModules: [
  231. '@nuxt/typescript-build',
  232. ['@nuxtjs/router', {
  233. path: 'router',
  234. fileName: 'index.js',
  235. keepDefaultRouter: true,
  236. }]
  237. ],
  238. /*
  239. ** Nuxt.js modules
  240. */
  241. modules: [
  242. "@nuxtjs/axios",
  243. "@nuxtjs/proxy",
  244. ["nuxt-buefy", {
  245. css: false,
  246. materialDesignIcons: false
  247. }]
  248. ],
  249. router: {
  250. middleware: ["initialize"],
  251. ...seoRouter
  252. }
  253. };