nuxt.config.js 7.5 KB

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