nuxt.config.js 5.2 KB

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