nuxt.config.js 5.2 KB

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