build: docker文件优化

This commit is contained in:
louis 2024-03-04 13:17:32 +08:00
parent c7c774f801
commit 7d34d4ac83
7 changed files with 25 additions and 18 deletions

View File

@ -14,21 +14,24 @@ RUN npm install -g pnpm
# 构建项目
# 安装生成依赖
FROM base AS prod-deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
# 基于prod-deps生成的依赖执行构建
FROM base AS builder
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN pnpm run build
## 不适用rimraf,因为rimraf是开发环境依赖
# 将prod-deps生成的依赖拷贝到base/$PROJECT_DIR中,开始在builder构建阶段build,最后拷贝build生成的dist到base/$PROJECT_DIR中
FROM base AS result
COPY --from=prod-deps $PROJECT_DIR/node_modules $PROJECT_DIR/node_modules
COPY --from=builder $PROJECT_DIR/dist $PROJECT_DIR/dist
# 构建项目 VITE_BASE_URL=/ 为了静态资源assets中文件的路径正确 去掉/api
ENV VITE_BASE_URL=/
RUN pnpm run build
# # 将prod-deps生成的依赖拷贝到base/$PROJECT_DIR中,开始在builder构建阶段build,最后拷贝build生成的dist到base/$PROJECT_DIR中
# FROM base AS result
# 构建nginx,并且在result之后拷贝dist到nginx中其中包含了自定义nginx.conf,
FROM nginx:alpine as production
ENV PROJECT_DIR=/huaxin-front
COPY --from=result $PROJECT_DIR/dist/ /usr/share/nginx/html
COPY --from=result $PROJECT_DIR/nginx.conf /etc/nginx/nginx.conf
COPY --from=builder $PROJECT_DIR/dist/ /usr/share/nginx/html
COPY --from=builder $PROJECT_DIR/nginx.conf /etc/nginx/nginx.conf
EXPOSE 80

View File

@ -6,7 +6,7 @@ services:
build:
context: .
dockerfile: Dockerfile
target: result
target: production
container_name: huaxin-base-frontend
ports:
- '80:80'

View File

@ -91,9 +91,10 @@ export async function dictTypeDelete(
}
/** 一次性获取所有的字典类型(不分页) GET /api/system/dict-type/all*/
export async function dictTypeGetAll(options?: RequestOptions) {
export async function dictTypeGetAll(params: API.DictTypeListParams, options?: RequestOptions) {
return request<API.DictTypeEntity[]>('/api/system/dict-type/all', {
method: 'GET',
params,
...(options || {}),
});
}

View File

@ -264,10 +264,12 @@ declare namespace API {
field?: string;
order?: 'ASC' | 'DESC';
/** 字典类型名称 */
name: string;
name?: string;
/** 字典类型code */
code: string;
code?: string;
_t?: number;
withItems?: boolean;
storeCodes?: string[];
};
type DictTypeUpdateParams = {

View File

@ -43,7 +43,7 @@
const collapsed = ref<boolean>(false);
//
const asiderWidth = computed(() => (collapsed.value ? 80 : 220));
const getTheme = computed(() => (layoutSetting.value.navTheme === 'light' ? 'light' : 'dark'));
const getTheme = computed(() => (layoutSetting.value.navTheme === 'dark' ? 'dark' : 'light'));
</script>
<style lang="less" scoped>

View File

@ -9,9 +9,12 @@ const needCachedKey = [
export const useDictStore = defineStore('dict', () => {
const dictTypes = ref<API.DictTypeDto[]>([]);
const getDictTypes = async () => {
dictTypes.value = await Api.systemDictType.dictTypeGetAll();
dictTypes.value = await Api.systemDictType.dictTypeGetAll({
storeCodes: needCachedKey,
withItems: true,
});
};
getDictTypes();
const getDictItemsByCode = async (code: string): Promise<API.DictItemEntity[]> => {
try {
const dictType = dictTypes.value.find((item) => item.code === code);

View File

@ -110,9 +110,7 @@ export const useUserStore = defineStore('user', () => {
const afterLogin = async () => {
try {
const { accountProfile } = Api.account;
const dictStore = useDictStore();
// 获取所有字典类型
await dictStore.getDictTypes();
useDictStore();
// const wsStore = useWsStore();
const userInfoData = await accountProfile();