Merge pull request #100 from vintonHuang/vue-h5-template

fix: 🐛 1.优化多语言初始化的时候,拿不到语言值的问题。2. 增加生产环境删除console和debugger配置
This commit is contained in:
fonghehe 2022-08-26 10:36:34 +08:00 committed by GitHub
commit ed76982537
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 78 additions and 13 deletions

View File

@ -61,6 +61,7 @@
"stylelint-config-recommended-vue": "^1.4.0",
"stylelint-config-standard": "^28.0.0",
"stylelint-order": "^5.0.0",
"terser": "^5.15.0",
"typescript": "^4.6.3",
"unplugin-auto-import": "^0.11.2",
"unplugin-vue-components": "^0.22.4",

View File

@ -13,7 +13,7 @@ export function loadLang() {
export const i18n = createI18n({
// globalInjection: true,
// legacy: false,
legacy: false,
locale: 'zh-cn',
fallbackLocale: 'zh-cn',
messages: loadLang(),
@ -23,7 +23,7 @@ export function setLang(locale?: string) {
if (locale) {
localStorage.setItem('lang', locale);
}
i18n.global.locale = locale || localStorage.getItem('lang') || '';
i18n.global.locale.value = locale || localStorage.getItem('lang') || '';
}
setLang();

View File

@ -6,7 +6,7 @@ import router from '/@/router';
import store from '/@/store';
import './assets/font/iconfont.css';
import './assets/app.css';
import 'amfe-flexible';
// import 'amfe-flexible';
const app = createApp(App);

View File

@ -41,3 +41,30 @@ export const useUserStore = defineStore({
paths: ['token'],
},
});
// export const useUserStore = defineStore('app-user', () => {
// const Token = ref(token);
// const info = ref<Record<any, any>>({});
// const setInfo = (info: any) => {
// info.value = info ? info : '';
// };
// const getUserInfo = () => {
// return info || {};
// };
// const login = () => {
// return new Promise((resolve) => {
// const { data } = loginPassword();
// watch(data, () => {
// setInfo(data.value);
// // useCookies().set(VITE_TOKEN_KEY as string, data.value.token);
// resolve(data.value);
// });
// });
// };
// return {
// Token,
// info,
// setInfo,
// login,
// getUserInfo,
// };
// });

View File

@ -14,3 +14,10 @@
}
}
}
@mixin center {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}

View File

@ -13,7 +13,7 @@
</nut-cell-group>
<nut-cell-group :title="$t('home.cssMultiLanguage')" class="supportList">
<nut-cell>
<div :class="['btn-confirm', i18n.global.locale]"></div>
<div :class="['btn-confirm', locale]"></div>
</nut-cell>
</nut-cell-group>
<div class="btn-wrap">
@ -30,14 +30,16 @@
<script lang="ts" setup name="HomePage">
import { computed } from 'vue';
import { useUserStore } from '/@/store/modules/user';
import { setLang, i18n } from '/@/i18n';
import { setLang } from '/@/i18n';
import { useI18n } from 'vue-i18n';
const { locale } = useI18n();
let cellList = ['vue3', 'vite', 'vue-router', 'axios', 'Pinia', 'vue-i18n', 'vue-jsx', 'vatlet/vant/nutUI'];
const userStore = useUserStore();
const getUserInfo = computed(() => {
const { name = '' } = userStore.getUserInfo || {};
return name;
});
console.log('生产环境需移除', locale.value);
const changeLang = (type) => {
setLang(type);
};

View File

@ -35,6 +35,16 @@ export default function ({ command }: ConfigEnv): UserConfigExport {
hmr: true,
},
plugins: createVitePlugins(isProduction),
build: {
minify: 'terser',
terserOptions: {
compress: {
//生产环境时移除console
drop_console: true,
drop_debugger: true,
},
},
},
css: {
preprocessorOptions: {
scss: {

View File

@ -503,6 +503,14 @@
resolved "https://registry.yarnpkg.com/@jridgewell/set-array/-/set-array-1.1.2.tgz#7c6cf998d6d20b914c0a55a91ae928ff25965e72"
integrity sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==
"@jridgewell/source-map@^0.3.2":
version "0.3.2"
resolved "https://registry.npmmirror.com/@jridgewell/source-map/-/source-map-0.3.2.tgz#f45351aaed4527a298512ec72f81040c998580fb"
integrity sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw==
dependencies:
"@jridgewell/gen-mapping" "^0.3.0"
"@jridgewell/trace-mapping" "^0.3.9"
"@jridgewell/sourcemap-codec@^1.4.10":
version "1.4.13"
resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.13.tgz#b6461fb0c2964356c469e115f504c95ad97ab88c"
@ -1103,16 +1111,16 @@ acorn-jsx@^5.3.2:
resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.2.tgz#7ed5bb55908b3b2f1bc55c6af1653bada7f07937"
integrity sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==
acorn@^8.5.0, acorn@^8.8.0:
version "8.8.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.0.tgz#88c0187620435c7f6015803f5539dae05a9dbea8"
integrity sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w==
acorn@^8.7.1:
version "8.7.1"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.1.tgz#0197122c843d1bf6d0a5e83220a788f278f63c30"
integrity sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A==
acorn@^8.8.0:
version "8.8.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.0.tgz#88c0187620435c7f6015803f5539dae05a9dbea8"
integrity sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w==
agent-base@4, agent-base@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.3.0.tgz#8165f01c436009bccad0b1d122f05ed770efc6ee"
@ -1899,7 +1907,7 @@ commander@2.15.1:
resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f"
integrity sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==
commander@^2.8.1:
commander@^2.20.0, commander@^2.8.1:
version "2.20.3"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==
@ -6739,7 +6747,7 @@ source-map-resolve@^0.5.0:
source-map-url "^0.4.0"
urix "^0.1.0"
source-map-support@^0.5.0:
source-map-support@^0.5.0, source-map-support@~0.5.20:
version "0.5.21"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f"
integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==
@ -7266,6 +7274,16 @@ tempfile@^2.0.0:
temp-dir "^1.0.0"
uuid "^3.0.1"
terser@^5.15.0:
version "5.15.0"
resolved "https://registry.npmmirror.com/terser/-/terser-5.15.0.tgz#e16967894eeba6e1091509ec83f0c60e179f2425"
integrity sha512-L1BJiXVmheAQQy+as0oF3Pwtlo4s3Wi1X2zNZ2NxOB4wx9bdS9Vk67XQENLFdLYGCK/Z2di53mTj/hBafR+dTA==
dependencies:
"@jridgewell/source-map" "^0.3.2"
acorn "^8.5.0"
commander "^2.20.0"
source-map-support "~0.5.20"
text-table@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"