fix: 报错和打包问题
This commit is contained in:
parent
2b11631b39
commit
b1e6814b31
12
build/css.ts
12
build/css.ts
|
@ -1,26 +1,26 @@
|
|||
import type { AcceptedPlugin } from 'postcss';
|
||||
import postCssPxToViewport8plugin from 'postcss-px-to-viewport-8-plugin';
|
||||
import type { CSSOptions, Plugin } from 'vite';
|
||||
import type { CSSOptions } from 'vite';
|
||||
|
||||
import { wrapperEnv } from './utils';
|
||||
|
||||
export const css = (mode): CSSOptions => {
|
||||
const plugins: Plugin[] = [usePostCssPxToViewport8plugin(mode)];
|
||||
export const css = (mode: string): CSSOptions => {
|
||||
const plugins: AcceptedPlugin[] = [usePostCssPxToViewport8plugin(mode)];
|
||||
|
||||
return {
|
||||
preprocessorOptions: {
|
||||
scss: {
|
||||
additionalData: `@use "@/assets/styles/minix/sidebar" as *;`,
|
||||
api: 'modern-compiler',
|
||||
},
|
||||
},
|
||||
postcss: {
|
||||
plugins: plugins.filter(Boolean),
|
||||
},
|
||||
} as CSSOptions;
|
||||
};
|
||||
};
|
||||
|
||||
/** 是否启用px转换vw插件 */
|
||||
const usePostCssPxToViewport8plugin = (mode): Plugin => {
|
||||
const usePostCssPxToViewport8plugin = (mode: string): AcceptedPlugin => {
|
||||
const { VITE_POST_CSS_PX_TO_VIEWPORT8_PLUGIN } = wrapperEnv(mode, 'VITE');
|
||||
|
||||
const cssPxToVw = postCssPxToViewport8plugin({
|
||||
|
|
|
@ -17,8 +17,7 @@ const boxenOptions: BoxenOptions = {
|
|||
/* 输出日志信息 */
|
||||
const printLogMessage = (VITE_PORT: number) => {
|
||||
return gradientString('cyan', 'magenta').multiline(
|
||||
`保存成功!服务器重新启动...
|
||||
项目访问地址如下:
|
||||
`欢迎使用此项目,项目访问地址如下:
|
||||
http://localhost:${VITE_PORT}`
|
||||
);
|
||||
};
|
||||
|
|
|
@ -9,6 +9,6 @@ const include = ['vue', 'vue-router', 'dayjs', 'axios', 'pinia', 'vue-types', 'j
|
|||
/**
|
||||
* 在预构建中强制排除的依赖项
|
||||
*/
|
||||
const exclude = [];
|
||||
const exclude: string[] = [];
|
||||
|
||||
export { include, exclude };
|
||||
|
|
|
@ -6,13 +6,14 @@ import UnoCSS from 'unocss/vite';
|
|||
import type { PluginOption } from 'vite';
|
||||
import { vitePluginFakeServer } from 'vite-plugin-fake-server';
|
||||
import removeConsole from 'vite-plugin-remove-console';
|
||||
import { createStyleImportPlugin } from 'vite-plugin-style-import';
|
||||
import Inspector from 'vite-plugin-vue-inspector';
|
||||
|
||||
import { useCDN } from './cdn';
|
||||
import { viteConsoleLog } from './info';
|
||||
import { compressPack, report, wrapperEnv } from './utils';
|
||||
|
||||
export const plugins = (mode): PluginOption[] => {
|
||||
export const plugins = (mode: string): PluginOption[] => {
|
||||
return [
|
||||
vue(),
|
||||
vueJsx(),
|
||||
|
@ -41,13 +42,21 @@ export const plugins = (mode): PluginOption[] => {
|
|||
}),
|
||||
],
|
||||
}),
|
||||
createStyleImportPlugin({
|
||||
libs: [
|
||||
{
|
||||
libraryName: 'vite-plugin-style-import',
|
||||
resolveStyle: (name) => `@/assets/${name}`,
|
||||
},
|
||||
],
|
||||
}),
|
||||
compressPack(mode),
|
||||
useMock(mode),
|
||||
];
|
||||
};
|
||||
|
||||
/** MOCK 服务 */
|
||||
const useMock = (mode) => {
|
||||
const useMock = (mode: string) => {
|
||||
const { VITE_MOCK_DEV_SERVER } = wrapperEnv(mode);
|
||||
|
||||
return VITE_MOCK_DEV_SERVER
|
||||
|
|
|
@ -4,7 +4,7 @@ export const resolve = () => {
|
|||
return {
|
||||
alias: {
|
||||
'@': pathResolve('../src'),
|
||||
'@build': pathResolve(),
|
||||
// '@build': pathResolve(),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@ import type { ServerOptions } from 'vite';
|
|||
import { wrapperEnv } from './utils';
|
||||
|
||||
/* 开发服务配置 */
|
||||
export const server = (mode) => {
|
||||
export const server = (mode: string) => {
|
||||
const { VITE_PORT, VITE_APP_URL, VITE_STRICT_PORT } = wrapperEnv(mode);
|
||||
|
||||
const options: ServerOptions = {
|
||||
|
|
|
@ -34,18 +34,20 @@ export const pathResolve = (dir = '.', metaUrl = import.meta.url) => {
|
|||
* @param prefix 需要过滤的前缀
|
||||
* @link 参考:https://cn.vite.dev/config/#using-environment-variables-in-config
|
||||
*/
|
||||
export const wrapperEnv = (mode, prefix: string = ''): ViteEnv => {
|
||||
const env = loadEnv(mode, root, prefix);
|
||||
// @ts-ignore
|
||||
export const wrapperEnv = (mode: string, prefix: string = ''): ViteEnv => {
|
||||
const env: any = loadEnv(mode, root, prefix);
|
||||
|
||||
// 将变量转换指定类型
|
||||
for (const envName of Object.keys(env)) {
|
||||
let realName = env[envName].replace(/\\n/g, '\n');
|
||||
let realName: string | boolean | number = env[envName].replace(/\\n/g, '\n');
|
||||
realName = realName === 'true' ? true : realName === 'false' ? false : realName;
|
||||
|
||||
if (envName === 'VITE_PORT') {
|
||||
realName = Number(realName);
|
||||
}
|
||||
env[envName] = realName;
|
||||
// @ts-ignore
|
||||
process.env[envName] = realName;
|
||||
}
|
||||
return env;
|
||||
|
@ -60,7 +62,7 @@ export const report = () => {
|
|||
};
|
||||
|
||||
/* 启用gzip压缩 */
|
||||
export const compressPack = (mode) => {
|
||||
export const compressPack = (mode: string) => {
|
||||
const { VITE_COMPRESSION } = wrapperEnv(mode);
|
||||
|
||||
return VITE_COMPRESSION == 'gzip' ? viteCompression({ threshold: 1024000 }) : null;
|
||||
|
|
|
@ -83,7 +83,7 @@ export default defineFlatConfig([
|
|||
rules: {
|
||||
...pluginTypeScript.configs.strict.rules,
|
||||
'@typescript-eslint/ban-types': 'off',
|
||||
'@typescript-eslint/no-redeclare': 'error',
|
||||
'@typescript-eslint/no-redeclare': 'off',
|
||||
'@typescript-eslint/ban-ts-comment': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/prefer-as-const': 'warn',
|
||||
|
|
|
@ -3,7 +3,7 @@ import { defineFakeRoute } from 'vite-plugin-fake-server/client';
|
|||
export default defineFakeRoute([
|
||||
{
|
||||
url: '/mock/users',
|
||||
methods: 'get',
|
||||
method: 'GET',
|
||||
response: () => ({
|
||||
code: 200,
|
||||
data: {
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@eslint/js": "^9.21.0",
|
||||
"@parcel/watcher": "^2.5.1",
|
||||
"@types/node": "^22.13.10",
|
||||
"@typescript-eslint/eslint-plugin": "^8.24.1",
|
||||
"@typescript-eslint/parser": "^8.24.1",
|
||||
"@unocss/preset-icons": "^66.0.0",
|
||||
|
@ -25,6 +27,7 @@
|
|||
"boxen": "^8.0.1",
|
||||
"dayjs": "^1.11.13",
|
||||
"echarts": "^5.6.0",
|
||||
"esbuild": "^0.25.1",
|
||||
"eslint": "^9.9.1",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-define-config": "^2.1.0",
|
||||
|
@ -36,6 +39,7 @@
|
|||
"nprogress": "^0.2.0",
|
||||
"pinia": "^2.3.1",
|
||||
"pinia-plugin-persistedstate": "^3.2.3",
|
||||
"postcss": "^8.5.3",
|
||||
"postcss-px-to-viewport-8-plugin": "^1.2.5",
|
||||
"prettier": "^3.3.3",
|
||||
"qs": "^6.14.0",
|
||||
|
@ -54,18 +58,22 @@
|
|||
"vite-plugin-remove-console": "^2.2.0",
|
||||
"vite-plugin-vue-inspector": "^5.3.1",
|
||||
"vue": "^3.5.13",
|
||||
"vue-demi": "^0.14.10",
|
||||
"vue-eslint-parser": "^9.4.3",
|
||||
"vue-router": "^4.4.3",
|
||||
"vue-types": "^6.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@iconify/json": "^2.2.310",
|
||||
"@types/nprogress": "^0.2.3",
|
||||
"@types/qs": "^6.9.18",
|
||||
"@vitejs/plugin-vue": "^5.2.1",
|
||||
"@vue/tsconfig": "^0.7.0",
|
||||
"eslint-plugin-simple-import-sort": "^12.1.1",
|
||||
"typescript": "~5.7.2",
|
||||
"vite": "^6.1.0",
|
||||
"vite-plugin-compression": "^0.5.1",
|
||||
"vite-plugin-style-import": "^2.0.0",
|
||||
"vue-tsc": "^2.2.0"
|
||||
},
|
||||
"engines": {
|
||||
|
|
540
pnpm-lock.yaml
540
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
@ -6,10 +6,10 @@
|
|||
</router-view>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
<style lang="scss">
|
||||
#app {
|
||||
width: 100%;
|
||||
//height: 100%;
|
||||
height: 1080px;
|
||||
//height: 100%;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -44,7 +44,7 @@ service.interceptors.response.use(
|
|||
}
|
||||
|
||||
// ElMessage.error(msg || '系统出错');
|
||||
return Promise.reject(msg || 'Error');
|
||||
return Promise.reject(response.data.message || 'Error');
|
||||
},
|
||||
(error: any) => {
|
||||
// 异常处理
|
||||
|
|
|
@ -44,7 +44,7 @@ service.interceptors.response.use(
|
|||
}
|
||||
|
||||
// ElMessage.error(msg || '系统出错');
|
||||
return Promise.reject(msg || 'Error');
|
||||
return Promise.reject(response.data.message || 'Error');
|
||||
},
|
||||
(error: any) => {
|
||||
// 异常处理
|
||||
|
|
|
@ -2,7 +2,7 @@ import 'animate.css';
|
|||
import '@unocss/reset/tailwind-compat.css';
|
||||
import 'uno.css';
|
||||
import 'virtual:unocss-devtools';
|
||||
import '@/assets/styles/global.scss';
|
||||
import './assets/styles/global.scss';
|
||||
|
||||
import { createApp } from 'vue';
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import error from '@/router/modules/error';
|
|||
import remaining from '@/router/modules/remaining';
|
||||
|
||||
// 静态路由
|
||||
const routes: RouteRecordRaw[] = [...remaining, ...error];
|
||||
const routes: RouteRecordRaw[] = [...remaining, ...error] as RouteRecordRaw[];
|
||||
const router = createRouter({
|
||||
history: createWebHashHistory(),
|
||||
routes,
|
||||
|
|
|
@ -2,8 +2,9 @@ import type { RouteRecordRaw } from 'vue-router';
|
|||
|
||||
import Layout from '@/layout/index.vue';
|
||||
import home from '@/router/modules/home';
|
||||
import type { RouteConfigsTable } from '@/types/router/Route';
|
||||
|
||||
const routes: RouteRecordRaw[] = [
|
||||
const routes: RouteRecordRaw[] | RouteConfigsTable[] = [
|
||||
{
|
||||
path: '/',
|
||||
name: 'layout',
|
||||
|
|
|
@ -10,7 +10,7 @@ const useAppStore = defineStore('appStore', {
|
|||
},
|
||||
getters: {},
|
||||
actions: {
|
||||
setBackground(background) {
|
||||
setBackground(background: string) {
|
||||
if (isCSSColor(background)) {
|
||||
this.background = background;
|
||||
} else if (isPath(background)) {
|
||||
|
|
|
@ -3,7 +3,7 @@ import { defineStore } from 'pinia';
|
|||
import { user } from '@/api/test';
|
||||
|
||||
/** 用户信息 */
|
||||
const useUserStore = defineStore('userStore', {
|
||||
export const useUserStore = defineStore('userStore', {
|
||||
state() {
|
||||
return {
|
||||
userinfo: {},
|
||||
|
@ -19,5 +19,3 @@ const useUserStore = defineStore('userStore', {
|
|||
},
|
||||
},
|
||||
});
|
||||
|
||||
export { useUserStore };
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
declare global {
|
||||
/* 环境便配置 */
|
||||
declare interface ViteEnv {
|
||||
export declare interface ViteEnv {
|
||||
VITE_APP_TITLE: string;
|
||||
VITE_PORT: number;
|
||||
VITE_PUBLIC_PATH: string;
|
||||
|
|
|
@ -4,15 +4,16 @@ import type { RouteComponent } from 'vue-router';
|
|||
* @description 完整子路由的`meta`配置表
|
||||
*/
|
||||
interface CustomizeRouteMeta {
|
||||
title: string;
|
||||
subtitle: string;
|
||||
transition: string;
|
||||
title?: string;
|
||||
subtitle?: string;
|
||||
transition?: string;
|
||||
hidden?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 整体路由配置表(包括完整子路由)
|
||||
*/
|
||||
interface RouteConfigsTable {
|
||||
export interface RouteConfigsTable {
|
||||
/** 路由地址 `必填` */
|
||||
path: string;
|
||||
/** 路由名字(保持唯一)`可选` */
|
||||
|
@ -25,5 +26,3 @@ interface RouteConfigsTable {
|
|||
/** 子路由配置项 */
|
||||
children?: Array<RouteConfigsTable>;
|
||||
}
|
||||
|
||||
export { RouteConfigsTable };
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
import { useEventListener } from '@vueuse/core';
|
||||
import { useDebounceFn, useEventListener } from '@vueuse/core';
|
||||
import type { EChartsType } from 'echarts';
|
||||
|
||||
/** 通用重置图表样式 */
|
||||
export const debounceChart = (myChart: EChartsType | undefined) => {
|
||||
useEventListener(window, 'resize', () => {
|
||||
const debounceFn = useDebounceFn(() => {
|
||||
myChart!.resize();
|
||||
});
|
||||
}, 500);
|
||||
|
||||
useEventListener(window, 'resize', debounceFn);
|
||||
};
|
||||
|
||||
/** 数字格式化 */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/** 判断是否是CSS颜色 */
|
||||
function isCSSColor(str) {
|
||||
function isCSSColor(str: string) {
|
||||
// 匹配十六进制颜色(如 #fff, #ffffff)
|
||||
const hexColor = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
|
||||
|
||||
|
@ -16,7 +16,7 @@ function isCSSColor(str) {
|
|||
}
|
||||
|
||||
/** 判断是否是相对路径或绝对路径 */
|
||||
function isPath(str) {
|
||||
function isPath(str: string) {
|
||||
// 匹配相对路径(如 ./path, ../path, path/to/file)
|
||||
const relativePath = /^\.{0,2}\/[^\/].*$/;
|
||||
|
||||
|
|
|
@ -98,10 +98,11 @@ export const ChartProgress = defineComponent({
|
|||
);
|
||||
});
|
||||
|
||||
return () => <div ref={chart} class="progress"></div>;
|
||||
return () => <div ref={chart} className="progress"></div>;
|
||||
},
|
||||
});
|
||||
|
||||
/** 更新图标数据 */
|
||||
const updateChart = (myChart: Ref<EChartsType | undefined>, props: any) => {
|
||||
myChart.value?.setOption({
|
||||
series: [
|
||||
|
|
|
@ -45,7 +45,7 @@ option.value = {
|
|||
};
|
||||
|
||||
export const renderEcharts = (element: Ref<HTMLDivElement>) => {
|
||||
const myChart = echarts.init(element.value, null, {
|
||||
const myChart: any = echarts.init(element.value, null, {
|
||||
renderer: 'svg',
|
||||
devicePixelRatio: window.devicePixelRatio,
|
||||
});
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
margin: 30px 0 0 0;
|
||||
width: 761px;
|
||||
height: 407px;
|
||||
background: url('@/assets/images/business-supervision/bg/content/bg-middle.png ') no-repeat center;
|
||||
background: url('@/assets/images/business-supervision/bg/content/bg-middle.png') no-repeat center;
|
||||
background-size: cover;
|
||||
|
||||
li {
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
import 'echarts/lib/component/dataZoom';
|
||||
|
||||
import type { EChartsOption } from 'echarts';
|
||||
import { type Ref, ref } from 'vue';
|
||||
|
||||
import echarts from '@/plugins/echarts';
|
||||
import { debounceChart } from '@/utils/chart';
|
||||
|
||||
const option = ref<EChartsOption>();
|
||||
const option = ref<any>();
|
||||
option.value = {
|
||||
backgroundColor: 'transparent',
|
||||
grid: { right: 10, left: 10, bottom: 20 },
|
||||
|
@ -97,7 +96,7 @@ option.value = {
|
|||
};
|
||||
|
||||
export const renderEcharts = (element: Ref<HTMLDivElement>) => {
|
||||
const myChart = echarts.init(element.value, null, {
|
||||
const myChart: any = echarts.init(element.value, null, {
|
||||
renderer: 'svg',
|
||||
devicePixelRatio: window.devicePixelRatio,
|
||||
});
|
||||
|
|
|
@ -1,50 +1,49 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"strict": true,
|
||||
"noLib": false,
|
||||
"sourceMap": true,
|
||||
"resolveJsonModule": true,
|
||||
"esModuleInterop": true,
|
||||
"lib": [
|
||||
"esnext",
|
||||
"dom"
|
||||
],
|
||||
"baseUrl": ".",
|
||||
"allowJs": true,
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"strict": false,
|
||||
"jsx": "preserve",
|
||||
"importHelpers": true,
|
||||
"experimentalDecorators": true,
|
||||
"strictFunctionTypes": false,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"isolatedModules": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"jsx": "preserve",
|
||||
"jsxFactory": "h",
|
||||
"jsxImportSource": "vue",
|
||||
"jsxFragmentFactory": "Fragment",
|
||||
"sourceMap": true,
|
||||
"baseUrl": ".",
|
||||
"allowJs": false,
|
||||
"resolveJsonModule": true,
|
||||
"lib": [
|
||||
"ESNext",
|
||||
"DOM"
|
||||
],
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"src/*"
|
||||
]
|
||||
// "@build/*": [
|
||||
// "build/*"
|
||||
// ]
|
||||
},
|
||||
"types": [
|
||||
"vite/client",
|
||||
"unplugin-icons/types/vue",
|
||||
"element-plus/global"
|
||||
"node",
|
||||
"vite/client"
|
||||
]
|
||||
},
|
||||
"files": [],
|
||||
"include": [
|
||||
"mock/*.ts",
|
||||
"src/**/*.ts",
|
||||
"src/**/*.tsx",
|
||||
"src/**/*.vue",
|
||||
"src/types/*.d.ts",
|
||||
"vite.config.ts"
|
||||
"vite.config.ts",
|
||||
"src/**/*.d.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"dist",
|
||||
"**/*.js",
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -10,7 +10,8 @@ import { server } from './build/server';
|
|||
import { root, wrapperEnv } from './build/utils';
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig(({ command, mode, isSsrBuild, isPreview }) => {
|
||||
// export default defineConfig(({ command, mode, isSsrBuild, isPreview }) => {
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = wrapperEnv(mode, 'VITE');
|
||||
|
||||
return {
|
||||
|
|
Loading…
Reference in New Issue