nuxt.config.js 5.7 KB

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