nuxt.config.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. import unpluginVueComponents from 'unplugin-vue-components/webpack';
  2. // import colors from 'vuetify/es5/util/colors'
  3. import zhHans from 'vuetify/lib/locale/zh-Hans';
  4. import dotenv from 'dotenv';
  5. // dotenv.config({
  6. // path: `.env`,
  7. // });
  8. let mode = 'development';
  9. const modeIndex = process.argv.indexOf('--mode');
  10. if (modeIndex !== -1) {
  11. mode = process.argv[modeIndex + 1];
  12. }
  13. dotenv.config({
  14. path: `.env.${mode}`,
  15. });
  16. export default {
  17. // Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode
  18. ssr: false,
  19. // Global page headers: https://go.nuxtjs.dev/config-head
  20. head: {
  21. titleTemplate: '%s',
  22. title: 'android-cloud-H5-nuxt',
  23. htmlAttrs: {
  24. lang: 'zh-CN',
  25. },
  26. meta: [
  27. { charset: 'utf-8' },
  28. {
  29. hid: 'author',
  30. name: 'author',
  31. content: process.env.npm_package_author_name,
  32. },
  33. {
  34. hid: 'version',
  35. name: 'version',
  36. content: process.env.npm_package_version,
  37. },
  38. {
  39. name: 'viewport',
  40. content:
  41. 'width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,shrink-to-fit=no,viewport-fit=cover',
  42. },
  43. {
  44. hid: 'description',
  45. name: 'description',
  46. content: process.env.npm_package_description || '',
  47. },
  48. { name: 'format-detection', content: 'telephone=no' },
  49. {
  50. hid: 'keywords',
  51. name: 'keywords',
  52. content: '双子星云手机',
  53. },
  54. ],
  55. link: [{ rel: 'icon', type: 'image/x-icon', href: '/h5/favicon.ico' }],
  56. },
  57. // Global CSS: https://go.nuxtjs.dev/config-css
  58. css: [
  59. // 'normalize.css',
  60. '@mdi/font/css/materialdesignicons.css',
  61. '~/assets/style/main.scss',
  62. // 'vant/lib/index.css'
  63. ],
  64. // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  65. plugins: [
  66. '~/plugins/axios',
  67. // '~/plugins/api',
  68. '~/plugins/file-upload',
  69. // '~/plugins/message',
  70. '~/plugins/toast',
  71. '~/plugins/error-captured',
  72. '~/plugins/user-agent',
  73. '~/plugins/native',
  74. '~/plugins/filters',
  75. '~/plugins/vue-data-dict',
  76. // '~/plugins/jweixin',
  77. // '~/plugins/umeng-datasources',
  78. // '@/plugins/vant',
  79. ],
  80. // Auto import components: https://go.nuxtjs.dev/config-components
  81. components: [
  82. '~/components',
  83. // {
  84. // path: 'vant/es',
  85. // level: 1,
  86. // pattern: '*/index.js',
  87. // ignore: ['utils/index.js'],
  88. // prefix: 'van',
  89. // },
  90. ],
  91. // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  92. buildModules: [
  93. ['@nuxtjs/dotenv', { filename: `.env.${mode}` }],
  94. '@nuxtjs/style-resources',
  95. // https://go.nuxtjs.dev/eslint
  96. '@nuxtjs/eslint-module',
  97. // https://go.nuxtjs.dev/stylelint
  98. '@nuxtjs/stylelint-module',
  99. // '~/modules/unplugin-vue-components'
  100. // '@aceforth/nuxt-optimized-images',
  101. '~/modules/postcss-px-to-viewport',
  102. // '~/modules/vant',
  103. // https://go.nuxtjs.dev/vuetify
  104. '@nuxtjs/vuetify',
  105. '@unocss/nuxt',
  106. '~/modules/vee-validate',
  107. // '@nuxtjs/composition-api/module',
  108. ],
  109. // Modules: https://go.nuxtjs.dev/config-modules
  110. modules: [
  111. // https://go.nuxtjs.dev/axios
  112. '@nuxtjs/axios',
  113. '@nuxtjs/auth-next',
  114. ],
  115. unocss: {
  116. uno: true,
  117. },
  118. optimizedImages: {
  119. // optimizeImagesInDev: true,
  120. },
  121. // Axios module configuration: https://go.nuxtjs.dev/config-axios
  122. axios: {
  123. proxy: process.env.NODE_ENV === 'development',
  124. // https: process.env.API_HTTPS === 'true',
  125. // // Workaround to avoid enforcing hard-coded localhost:3000: https://github.com/nuxt-community/axios-module/issues/308
  126. // baseURL: '/',
  127. },
  128. proxy: {
  129. '/api': {
  130. // target: 'http://gntest.phone.androidscloud.com:1280',
  131. target: `http${process.env.API_PORT === '443' ? 's' : ''}://${
  132. process.env.API_HOST
  133. }:${process.env.API_PORT}`,
  134. pathRewrite: {
  135. // '^/api': ''
  136. },
  137. },
  138. '/file': {
  139. target: `http${process.env.FILE_PORT === '443' ? 's' : ''}://${
  140. process.env.FILE_HOST
  141. }:${process.env.FILE_PORT}`,
  142. pathRewrite: {
  143. '^/file': '',
  144. },
  145. },
  146. },
  147. auth: {
  148. plugins: ['~/plugins/auth', '~/plugins/baidu-tongji'],
  149. strategies: {
  150. password: {
  151. scheme: '~/schemes/password',
  152. token: {
  153. property: 'data.token',
  154. name: 'Authorization',
  155. type: '',
  156. },
  157. user: {
  158. property: 'data',
  159. },
  160. endpoints: {
  161. login: { url: '/user/v1/client/login', method: 'post' },
  162. user: { url: '/user/v1/client/personalInfo', method: 'get' },
  163. logout: {
  164. url: '/user/v5/visitDetailed/operationVisitDetailed',
  165. method: 'post',
  166. },
  167. },
  168. },
  169. // user: {
  170. // property: 'user',
  171. // // autoFetch: true
  172. // },
  173. },
  174. cookie: false,
  175. },
  176. // Vuetify module configuration: https://go.nuxtjs.dev/config-vuetify
  177. vuetify: {
  178. defaultAssets: false,
  179. customVariables: ['~/assets/style/variables.scss'],
  180. lang: {
  181. locales: { zhHans },
  182. current: 'zhHans',
  183. },
  184. theme: {
  185. dark: false,
  186. // themes: {
  187. // dark: {
  188. // primary: colors.blue.darken2,
  189. // accent: colors.grey.darken3,
  190. // secondary: colors.amber.darken3,
  191. // info: colors.teal.lighten1,
  192. // warning: colors.amber.base,
  193. // error: colors.deepOrange.accent4,
  194. // success: colors.green.accent3,
  195. // },
  196. // },
  197. },
  198. },
  199. // Build Configuration: https://go.nuxtjs.dev/config-build
  200. build: {
  201. // extend(config, { isClient, loaders: { less } }) {
  202. // // console.log('🚀 ~ file: nuxt.config.js ~ line 197 ~ extend ~ less', less);
  203. // less.lessOptions = {
  204. // modifyVars: {
  205. // // 直接覆盖变量
  206. // 'text-color': '#111',
  207. // 'border-color': '#eee',
  208. // },
  209. // };
  210. // },
  211. plugins: [
  212. // unpluginVueComponents({
  213. // resolvers: [
  214. // {
  215. // type: 'component',
  216. // resolve(componentName) {
  217. // if (componentName.startsWith('Validation')) {
  218. // console.log(
  219. // '🚀 ~ file: nuxt.config.js ~ line 230 ~ resolve ~ componentName',
  220. // componentName,
  221. // );
  222. // return {
  223. // name: componentName,
  224. // from: 'vee-validate',
  225. // // sideEffects: getSideEffects(importName, options),
  226. // };
  227. // }
  228. // },
  229. // },
  230. // ],
  231. // }),
  232. ],
  233. babel: {
  234. plugins: [],
  235. },
  236. postcss: {
  237. plugins: {},
  238. },
  239. loaders: {
  240. vue: {
  241. transformAssetUrls: {
  242. 'v-img': 'src',
  243. },
  244. },
  245. },
  246. },
  247. router: {
  248. base: '/h5/',
  249. middleware: ['auth'],
  250. },
  251. styleResources: {
  252. scss: ['~/assets/style/variables.scss'],
  253. less: ['~/assets/style/variables.less'],
  254. // hoistUseStatements: true,
  255. },
  256. server: {
  257. port: 3000, // default: 3000
  258. host: '0.0.0.0', // default: localhost,
  259. timing: false,
  260. },
  261. };