feat: 新增路径别名、多环境配置、生产环境打包配置
This commit is contained in:
5
.env.development
Normal file
5
.env.development
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# 开发环境变量
|
||||||
|
ENV = 'development'
|
||||||
|
|
||||||
|
# base api
|
||||||
|
VUE_APP_BASE_API = '/dev-api'
|
||||||
6
.env.production
Normal file
6
.env.production
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# 生产环境变量
|
||||||
|
ENV = 'production'
|
||||||
|
|
||||||
|
# base api
|
||||||
|
VUE_APP_BASE_API = '/prod-api'
|
||||||
|
|
||||||
6
.env.staging
Normal file
6
.env.staging
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# 模拟环境变量
|
||||||
|
ENV = 'staging'
|
||||||
|
|
||||||
|
# base api
|
||||||
|
VUE_APP_BASE_API = '/stage-api'
|
||||||
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
"name": "vue3-element-admin",
|
"name": "vue3-element-admin",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite serve --mode development",
|
||||||
"build": "vue-tsc --noEmit && vite build",
|
"build:prod": "vue-tsc --noEmit && vite build --mode production",
|
||||||
"serve": "vite preview"
|
"serve": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
"vuex": "^4.0.2"
|
"vuex": "^4.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/node": "^16.11.7",
|
||||||
"@vitejs/plugin-vue": "^1.9.3",
|
"@vitejs/plugin-vue": "^1.9.3",
|
||||||
"typescript": "^4.4.3",
|
"typescript": "^4.4.3",
|
||||||
"vite": "^2.6.4",
|
"vite": "^2.6.4",
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
// This starter template is using Vue 3 <script setup> SFCs
|
|
||||||
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
|
|
||||||
import HelloWorld from './components/HelloWorld.vue'
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<img alt="Vue logo" src="./assets/logo.png" />
|
<img alt="Vue logo" src="./assets/logo.png" />
|
||||||
|
|||||||
@@ -1,42 +1,27 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-input v-model="input" placeholder="Please input" />
|
<el-input v-model="num"/>
|
||||||
<el-input-number v-model="num" :min="1" :max="10" @change="handleChange"/>
|
<el-button @click="handleClick">点击+1</el-button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {defineComponent, ref} from 'vue'
|
import {defineComponent, computed} from 'vue'
|
||||||
|
import {userStore} from '@/store';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
setup() {
|
setup() {
|
||||||
const num = ref(1)
|
const store = userStore()
|
||||||
const handleChange = (value: string) => {
|
const num = computed(()=>{
|
||||||
console.log(value)
|
return store.state.count
|
||||||
|
})
|
||||||
|
const handleClick = () => {
|
||||||
|
store.commit('increment')
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
input:ref(''),
|
|
||||||
num,
|
num,
|
||||||
handleChange,
|
handleClick
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
a {
|
|
||||||
color: #42b983;
|
|
||||||
}
|
|
||||||
|
|
||||||
label {
|
|
||||||
margin: 0 0.5em;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
code {
|
|
||||||
background-color: #eee;
|
|
||||||
padding: 2px 4px;
|
|
||||||
border-radius: 4px;
|
|
||||||
color: #304455;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {InjectionKey} from 'vue'
|
import {InjectionKey} from 'vue'
|
||||||
import {createStore, Store} from 'vuex'
|
import {createStore,useStore as baseUseStore ,Store} from 'vuex'
|
||||||
|
|
||||||
export interface State {
|
export interface State {
|
||||||
count: number
|
count: number
|
||||||
@@ -20,6 +20,7 @@ export const store = createStore<State>({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export function userStore(){
|
||||||
|
return baseUseStore(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,16 @@
|
|||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"lib": ["esnext", "dom"]
|
"lib": ["esnext", "dom"],
|
||||||
},
|
|
||||||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
|
|
||||||
|
|
||||||
|
/* Vite 路径别名报错 */
|
||||||
|
"baseUrl": "./",
|
||||||
|
"paths": {
|
||||||
|
"@": ["src"],
|
||||||
|
"@/*": ["src/*"]
|
||||||
|
},
|
||||||
|
|
||||||
|
"skipLibCheck": true // element-plus 生产打包报错,通过此配置修改 TS 不对第三方依赖类型检查
|
||||||
|
},
|
||||||
|
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,43 @@
|
|||||||
import { defineConfig } from 'vite'
|
import {defineConfig} from 'vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
|
|
||||||
|
// 在 ts 模块中加载 node 核心模块需要安装 node 的类型补充模块: npm i -D @types/node
|
||||||
|
import path from 'path'
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [vue()]
|
plugins: [vue()],
|
||||||
|
resolve: {
|
||||||
|
// Vite2设置别名路径方式一
|
||||||
|
/**
|
||||||
|
alias:{
|
||||||
|
|
||||||
|
"/@":path.resolve("./src"),
|
||||||
|
},
|
||||||
|
**/
|
||||||
|
|
||||||
|
// Vite2设置别名路径方式二
|
||||||
|
alias: [
|
||||||
|
{
|
||||||
|
find: "@",
|
||||||
|
replacement: path.resolve("./src")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
find: "@image",
|
||||||
|
replacement: path.resolve("./src/assets/images")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
find: "@router",
|
||||||
|
replacement: path.resolve("./src/router")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
find: "@store",
|
||||||
|
replacement: path.resolve("./src/store")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
find: "@api",
|
||||||
|
replacement: path.resolve("./src/api")
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user