nuxt.config.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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: '云手机',
  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/api',
  67. // '~/plugins/file-upload',
  68. // '~/plugins/message',
  69. '~/plugins/toast',
  70. '~/plugins/error-captured',
  71. '~/plugins/user-agent',
  72. '~/plugins/native',
  73. '~/plugins/filters',
  74. '~/plugins/vue-data-dict',
  75. { src: '~/plugins/v-mask', mode: 'client' },
  76. { src: '~/plugins/vconsole', mode: 'client' },
  77. { src: '~/plugins/callapp', mode: 'client' },
  78. '~/plugins/jweixin',
  79. // '~/plugins/umeng-datasources',
  80. '@/plugins/vant',
  81. '@/plugins/vue-clipboard2',
  82. '~/plugins/common',
  83. ],
  84. // Auto import components: https://go.nuxtjs.dev/config-components
  85. components: [
  86. '~/components',
  87. // {
  88. // path: 'vant/es',
  89. // level: 1,
  90. // pattern: '*/index.js',
  91. // ignore: ['utils/index.js'],
  92. // prefix: 'van',
  93. // },
  94. ],
  95. // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  96. buildModules: [
  97. ['@nuxtjs/dotenv', { filename: `.env.${mode}` }],
  98. '@nuxtjs/style-resources',
  99. // https://go.nuxtjs.dev/eslint
  100. // https://go.nuxtjs.dev/stylelint
  101. // '~/modules/unplugin-vue-components'
  102. // '@aceforth/nuxt-optimized-images',
  103. '~/modules/postcss-px-to-viewport',
  104. // '~/modules/vant',
  105. // https://go.nuxtjs.dev/vuetify
  106. '@nuxtjs/vuetify',
  107. '@unocss/nuxt',
  108. '~/modules/vee-validate',
  109. // '@nuxtjs/composition-api/module',
  110. ],
  111. // Modules: https://go.nuxtjs.dev/config-modules
  112. modules: [
  113. // https://go.nuxtjs.dev/axios
  114. '@nuxtjs/axios',
  115. '@nuxtjs/auth-next',
  116. ],
  117. unocss: {
  118. uno: true,
  119. rules: [
  120. [/^w-(\d+)rpx$/, ([, d]) => ({ width: `${d * (100 / 375)}vw` })],
  121. [/^h-(\d+)rpx$/, ([, d]) => ({ height: `${d * (100 / 375)}vw` })],
  122. ],
  123. },
  124. optimizedImages: {
  125. // optimizeImagesInDev: true,
  126. },
  127. // Axios module configuration: https://go.nuxtjs.dev/config-axios
  128. axios: {
  129. proxy: process.env.NODE_ENV === 'development',
  130. https: process.env.API_HTTPS === 'true',
  131. // // Workaround to avoid enforcing hard-coded localhost:3000: https://github.com/nuxt-community/axios-module/issues/308
  132. // baseURL: '/',
  133. },
  134. proxy: {
  135. [process.env.API_PREFIX]: {
  136. // target: 'http://gntest.phone.androidscloud.com:1280',
  137. target: `http${process.env.API_HTTPS === 'true' ? 's' : ''}://${process.env.API_HOST
  138. }:${process.env.API_PORT}`,
  139. pathRewrite: {
  140. // '^/api': ''
  141. },
  142. ws: false
  143. },
  144. '/file': {
  145. target: `http${process.env.FILE_HTTPS === 'true' ? 's' : ''}://${process.env.FILE_HOST
  146. }:${process.env.FILE_PORT}`,
  147. pathRewrite: {
  148. '^/file': '',
  149. },
  150. },
  151. },
  152. auth: {
  153. plugins: ['~/plugins/axios', '~/plugins/auth', '~/plugins/baidu-tongji'],
  154. redirect: {
  155. login: '/login',
  156. logout: '/login',
  157. callback: '/login',
  158. home: '/login',
  159. },
  160. strategies: {
  161. password: {
  162. scheme: '~/schemes/password',
  163. token: {
  164. property: 'data.token',
  165. name: 'Authorization',
  166. type: '',
  167. },
  168. user: {
  169. property: 'data',
  170. },
  171. endpoints: {
  172. login: { url: '/user/v1/client/login', method: 'post' },
  173. user: { url: '/user/v1/client/personalInfo', method: 'get' },
  174. logout: {
  175. url: '/user/v5/visitDetailed/operationVisitDetailed',
  176. method: 'post',
  177. },
  178. },
  179. },
  180. // user: {
  181. // property: 'user',
  182. // // autoFetch: true
  183. // },
  184. },
  185. cookie: false,
  186. },
  187. // Vuetify module configuration: https://go.nuxtjs.dev/config-vuetify
  188. vuetify: {
  189. defaultAssets: false,
  190. customVariables: ['~/assets/style/variables.scss'],
  191. lang: {
  192. locales: { zhHans },
  193. current: 'zhHans',
  194. },
  195. theme: {
  196. dark: false,
  197. // themes: {
  198. // dark: {
  199. // primary: colors.blue.darken2,
  200. // accent: colors.grey.darken3,
  201. // secondary: colors.amber.darken3,
  202. // info: colors.teal.lighten1,
  203. // warning: colors.amber.base,
  204. // error: colors.deepOrange.accent4,
  205. // success: colors.green.accent3,
  206. // },
  207. // },
  208. },
  209. },
  210. // Build Configuration: https://go.nuxtjs.dev/config-build
  211. build: {
  212. transpile: ['vee-validate/dist/rules'],
  213. // extend(config, { isClient, loaders: { less } }) {
  214. // // console.log('🚀 ~ file: nuxt.config.js ~ line 197 ~ extend ~ less', less);
  215. // less.lessOptions = {
  216. // modifyVars: {
  217. // // 直接覆盖变量
  218. // 'text-color': '#111',
  219. // 'border-color': '#eee',
  220. // },
  221. // };
  222. // },
  223. plugins: [
  224. // unpluginVueComponents({
  225. // resolvers: [
  226. // {
  227. // type: 'component',
  228. // resolve(componentName) {
  229. // if (componentName.startsWith('Validation')) {
  230. // console.log(
  231. // '🚀 ~ file: nuxt.config.js ~ line 230 ~ resolve ~ componentName',
  232. // componentName,
  233. // );
  234. // return {
  235. // name: componentName,
  236. // from: 'vee-validate',
  237. // // sideEffects: getSideEffects(importName, options),
  238. // };
  239. // }
  240. // },
  241. // },
  242. // ],
  243. // }),
  244. ],
  245. babel: {
  246. babelrc: false,
  247. },
  248. postcss: {
  249. plugins: {},
  250. },
  251. loaders: {
  252. vue: {
  253. transformAssetUrls: {
  254. 'v-img': 'src',
  255. },
  256. },
  257. },
  258. },
  259. router: {
  260. base: '/h5/',
  261. middleware: ['auth'],
  262. },
  263. styleResources: {
  264. scss: ['~/assets/style/variables.scss'],
  265. less: ['~/assets/style/variables.less'],
  266. // hoistUseStatements: true,
  267. },
  268. server: {
  269. port: 3000, // default: 3000
  270. host: '0.0.0.0', // default: localhost,
  271. timing: false,
  272. },
  273. };