nuxt.config.js 5.3 KB

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