nuxt.config.js 5.5 KB

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