nuxt.config.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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' : ''}://${
  138. process.env.API_HOST
  139. }:${process.env.API_PORT}`,
  140. pathRewrite: {
  141. // '^/api': ''
  142. },
  143. },
  144. '/file': {
  145. target: `http${process.env.FILE_HTTPS === 'true' ? 's' : ''}://${
  146. process.env.FILE_HOST
  147. }:${process.env.FILE_PORT}`,
  148. pathRewrite: {
  149. '^/file': '',
  150. },
  151. },
  152. },
  153. auth: {
  154. plugins: ['~/plugins/axios', '~/plugins/auth', '~/plugins/baidu-tongji'],
  155. redirect: {
  156. login: '/login',
  157. logout: '/login',
  158. callback: '/login',
  159. home: '/login',
  160. },
  161. strategies: {
  162. password: {
  163. scheme: '~/schemes/password',
  164. token: {
  165. property: 'data.token',
  166. name: 'Authorization',
  167. type: '',
  168. },
  169. user: {
  170. property: 'data',
  171. },
  172. endpoints: {
  173. login: { url: '/user/v1/client/login', method: 'post' },
  174. user: { url: '/user/v1/client/personalInfo', method: 'get' },
  175. logout: {
  176. url: '/user/v5/visitDetailed/operationVisitDetailed',
  177. method: 'post',
  178. },
  179. },
  180. },
  181. // user: {
  182. // property: 'user',
  183. // // autoFetch: true
  184. // },
  185. },
  186. cookie: false,
  187. },
  188. // Vuetify module configuration: https://go.nuxtjs.dev/config-vuetify
  189. vuetify: {
  190. defaultAssets: false,
  191. customVariables: ['~/assets/style/variables.scss'],
  192. lang: {
  193. locales: { zhHans },
  194. current: 'zhHans',
  195. },
  196. theme: {
  197. dark: false,
  198. // themes: {
  199. // dark: {
  200. // primary: colors.blue.darken2,
  201. // accent: colors.grey.darken3,
  202. // secondary: colors.amber.darken3,
  203. // info: colors.teal.lighten1,
  204. // warning: colors.amber.base,
  205. // error: colors.deepOrange.accent4,
  206. // success: colors.green.accent3,
  207. // },
  208. // },
  209. },
  210. },
  211. // Build Configuration: https://go.nuxtjs.dev/config-build
  212. build: {
  213. transpile: ['vee-validate/dist/rules'],
  214. // extend(config, { isClient, loaders: { less } }) {
  215. // // console.log('🚀 ~ file: nuxt.config.js ~ line 197 ~ extend ~ less', less);
  216. // less.lessOptions = {
  217. // modifyVars: {
  218. // // 直接覆盖变量
  219. // 'text-color': '#111',
  220. // 'border-color': '#eee',
  221. // },
  222. // };
  223. // },
  224. plugins: [
  225. // unpluginVueComponents({
  226. // resolvers: [
  227. // {
  228. // type: 'component',
  229. // resolve(componentName) {
  230. // if (componentName.startsWith('Validation')) {
  231. // console.log(
  232. // '🚀 ~ file: nuxt.config.js ~ line 230 ~ resolve ~ componentName',
  233. // componentName,
  234. // );
  235. // return {
  236. // name: componentName,
  237. // from: 'vee-validate',
  238. // // sideEffects: getSideEffects(importName, options),
  239. // };
  240. // }
  241. // },
  242. // },
  243. // ],
  244. // }),
  245. ],
  246. babel: {
  247. babelrc: false,
  248. },
  249. postcss: {
  250. plugins: {},
  251. },
  252. loaders: {
  253. vue: {
  254. transformAssetUrls: {
  255. 'v-img': 'src',
  256. },
  257. },
  258. },
  259. },
  260. router: {
  261. base: '/h5/',
  262. middleware: ['auth'],
  263. },
  264. styleResources: {
  265. scss: ['~/assets/style/variables.scss'],
  266. less: ['~/assets/style/variables.less'],
  267. // hoistUseStatements: true,
  268. },
  269. server: {
  270. port: 3000, // default: 3000
  271. host: '0.0.0.0', // default: localhost,
  272. timing: false,
  273. },
  274. };