Complete base template files

main
PeterAlbus 2 years ago
parent a1e75f1555
commit eaadbafd8c

@ -0,0 +1 @@
VITE_APP_ENV = 'dev'

@ -0,0 +1 @@
VITE_APP_ENV = 'prod'

@ -0,0 +1 @@
VITE_APP_ENV = 'test'

@ -0,0 +1,15 @@
/* eslint-env node */
require("@rushstack/eslint-patch/modern-module-resolution");
module.exports = {
root: true,
extends: [
"plugin:vue/vue3-essential",
"eslint:recommended",
"@vue/eslint-config-typescript/recommended",
"@vue/eslint-config-prettier",
],
parserOptions: {
ecmaVersion: "latest",
},
};

33
.gitignore vendored

@ -1,11 +1,28 @@
# ---> Vue # Logs
# gitignore template for Vue.js projects logs
# *.log
# Recommended template: Node.gitignore npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
# TODO: where does this rule come from? node_modules
docs/_book .DS_Store
dist
dist-ssr
coverage
*.local
# TODO: where does this rule come from? /cypress/videos/
test/ /cypress/screenshots/
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

@ -0,0 +1,3 @@
{
"recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
}

@ -1,3 +1,72 @@
# vite-vue3-templete # Vite + Vue3 + TypeScript
# 前端项目模板
This template should help get you started developing with Vue 3 in Vite.
该模板可以帮助快速构建一个基于Vite的Vue3项目。
## Dependencies / 包含库
+ Vue3 + TypeScript + Less + Vue-Router + ESlint + Axios + Pinia
+ Element-Plus 2.2.15 + ElementPlus-Icons
+ OpenLayers 7 + ECharts 5.3.3 + turf
+ moment / nprogress / qs
## Development Standard / 开发规范
+ 页面SFC存放于views文件夹内组件存放于components。
+ 接口url及请求相关方法放置于services文件夹内。不同环境通过VITE_APP_ENV识别。
## Recommended IDE Setup / 推荐IDE及插件
[IntelliJ IDEA](https://www.jetbrains.com/idea/) / [WebSorm](https://www.jetbrains.com.cn/webstorm/)
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).
## Type Support for `.vue` Imports in TS
TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin) to make the TypeScript language service aware of `.vue` types.
If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471#discussioncomment-1361669) that is more performant. You can enable it by the following steps:
1. Disable the built-in TypeScript Extension
1) Run `Extensions: Show Built-in Extensions` from VSCode's command palette
2) Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
2. Reload the VSCode window by running `Developer: Reload Window` from the command palette.
## Customize configuration / 自定义配置
See [Vite Configuration Reference](https://vitejs.dev/config/).
## Project Setup
```sh
npm install
```
### Compile and Hot-Reload for Development
```sh
npm run dev
```
### Type-Check, Compile and Minify for Production
```sh
npm run build
```
### Run Unit Tests with [Vitest](https://vitest.dev/)
```sh
npm run test:unit
```
### Lint with [ESLint](https://eslint.org/)
```sh
npm run lint
```
基于Vite+Vue3的项目模板包含常用库

5
auto-imports.d.ts vendored

@ -0,0 +1,5 @@
// Generated by 'unplugin-auto-import'
export {}
declare global {
}

@ -0,0 +1,31 @@
/**
* Used to package and output gzip. Note that this does not work properly in Vite, the specific reason is still being investigated
* https://github.com/anncwb/vite-plugin-compression
*/
import type { Plugin } from 'vite';
import compressPlugin from 'vite-plugin-compression';
export function configCompressPlugin(compress: 'gzip' | 'brotli' | 'none'): Plugin | Plugin[] {
const compressList = compress.split(',');
const plugins: Plugin[] = [];
if (compressList.includes('gzip')) {
plugins.push(
compressPlugin({
ext: '.gz',
})
);
}
if (compressList.includes('brotli')) {
plugins.push(
compressPlugin({
ext: '.br',
algorithm: 'brotliCompress',
})
);
}
return plugins;
}

14
components.d.ts vendored

@ -0,0 +1,14 @@
// generated by unplugin-vue-components
// We suggest you to commit this file into source control
// Read more: https://github.com/vuejs/core/pull/3399
import '@vue/runtime-core'
export {}
declare module '@vue/runtime-core' {
export interface GlobalComponents {
HtmlView: typeof import('./src/components/HtmlView.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
}
}

6
env.d.ts vendored

@ -0,0 +1,6 @@
/// <reference types="vite/client" />
declare module "*.vue" {
import { defineComponent } from "vue";
const Component: ReturnType<typeof defineComponent>;
export default Component;
}

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>air</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>

11778
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -0,0 +1,53 @@
{
"name": "dt-web-stage",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "run-p type-check build-only",
"preview": "vite preview --port 4173",
"test:unit": "vitest --environment jsdom",
"build-only": "vite build",
"type-check": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
},
"dependencies": {
"@element-plus/icons-vue": "^2.0.9",
"@turf/turf": "^6.5.0",
"axios": "^0.27.2",
"echarts": "^5.3.3",
"element-plus": "^2.2.15",
"less": "^4.1.3",
"lodash": "^4.17.21",
"moment": "^2.29.4",
"nprogress": "^0.2.0",
"ol": "^7.1.0",
"pinia": "^2.0.17",
"qs": "^6.11.0",
"vue": "^3.2.37",
"vue-router": "^4.1.3"
},
"devDependencies": {
"@rushstack/eslint-patch": "^1.1.4",
"@types/jsdom": "^20.0.0",
"@types/node": "^16.11.47",
"@types/nprogress": "^0.2.0",
"@types/qs": "^6.9.7",
"@vitejs/plugin-vue": "^3.0.1",
"@vue/eslint-config-prettier": "^7.0.0",
"@vue/eslint-config-typescript": "^11.0.0",
"@vue/test-utils": "^2.0.2",
"@vue/tsconfig": "^0.1.3",
"eslint": "^8.21.0",
"eslint-plugin-vue": "^9.3.0",
"jsdom": "^20.0.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.7.1",
"typescript": "~4.7.4",
"unplugin-auto-import": "^0.11.2",
"unplugin-vue-components": "^0.22.4",
"vite": "^3.0.4",
"vite-plugin-compression": "^0.5.1",
"vitest": "^0.21.0",
"vue-tsc": "^0.39.5"
}
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

@ -0,0 +1,10 @@
<script setup lang="ts">
import { RouterLink, RouterView } from "vue-router";
</script>
<template>
<RouterView />
</template>
<style scoped>
</style>

@ -0,0 +1,74 @@
/* color palette from <https://github.com/vuejs/theme> */
:root {
--vt-c-white : #ffffff;
--vt-c-white-soft: #f8f8f8;
--vt-c-white-mute: #f2f2f2;
--vt-c-black : #181818;
--vt-c-black-soft: #222222;
--vt-c-black-mute: #282828;
--vt-c-indigo: #2c3e50;
--vt-c-divider-light-1: rgba(60, 60, 60, 0.29);
--vt-c-divider-light-2: rgba(60, 60, 60, 0.12);
--vt-c-divider-dark-1 : rgba(84, 84, 84, 0.65);
--vt-c-divider-dark-2 : rgba(84, 84, 84, 0.48);
--vt-c-text-light-1: var(--vt-c-indigo);
--vt-c-text-light-2: rgba(60, 60, 60, 0.66);
--vt-c-text-dark-1 : var(--vt-c-white);
--vt-c-text-dark-2 : rgba(235, 235, 235, 0.64);
}
/* semantic color variables for this project */
:root {
--color-background : var(--vt-c-white);
--color-background-soft: var(--vt-c-white-soft);
--color-background-mute: var(--vt-c-white-mute);
--color-border : var(--vt-c-divider-light-2);
--color-border-hover: var(--vt-c-divider-light-1);
--color-heading: var(--vt-c-text-light-1);
--color-text : var(--vt-c-text-light-1);
--section-gap: 160px;
}
@media (prefers-color-scheme: dark) {
:root {
--color-background : var(--vt-c-black);
--color-background-soft: var(--vt-c-black-soft);
--color-background-mute: var(--vt-c-black-mute);
--color-border : var(--vt-c-divider-dark-2);
--color-border-hover: var(--vt-c-divider-dark-1);
--color-heading: var(--vt-c-text-dark-1);
--color-text : var(--vt-c-text-dark-2);
}
}
*,
*::before,
*::after {
box-sizing : border-box;
margin : 0;
position : relative;
font-weight: normal;
}
body {
min-height : 100vh;
color : var(--color-text);
background : var(--color-background);
transition : color 0.5s, background-color 0.5s;
line-height: 1.6;
font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu,
Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
font-size : 15px;
text-rendering : optimizeLegibility;
-webkit-font-smoothing : antialiased;
-moz-osx-font-smoothing: grayscale;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 261.76 226.69" xmlns:v="https://vecta.io/nano"><path d="M161.096.001l-30.225 52.351L100.647.001H-.005l130.877 226.688L261.749.001z" fill="#41b883"/><path d="M161.096.001l-30.225 52.351L100.647.001H52.346l78.526 136.01L209.398.001z" fill="#34495e"/></svg>

After

Width:  |  Height:  |  Size: 308 B

@ -0,0 +1,8 @@
@import "./base.css";
body,
html,
#app {
width : 100%;
height : 100%;
}

@ -0,0 +1,42 @@
<template>
<div class="html-container">
<iframe id="html-view" :src="viewUrl" v-if="!showImg"></iframe>
<img src="../assets/error.jpg" v-if="showImg" />
</div>
</template>
<script setup lang="ts">
import { onMounted, computed, ref } from "vue";
import axios from "axios";
// ts
interface Props {
url: string;
}
const props = defineProps<Props>();
const viewUrl: any = computed(() => props.url);
let showImg = ref(false);
function error() {}
onMounted(() => {
});
</script>
<style lang="less" scoped>
.html-container {
width: 100%;
height: 100%;
#html-view {
width: 100%;
height: 100%;
border: 0px;
overflow: hidden;
}
img {
position: absolute;
width: 100%;
max-height: 100%;
top: 0;
bottom: 0;
margin: auto;
}
}
</style>

@ -0,0 +1,102 @@
/**
*@name dragMove.js
*@time 2022/09/01
*@description
*@author bobo
* example <div class="dialog"
v-dialogDrag="{
dragEle: '.header',//点击拖动的那个dom的选择器
drag: true, //是否开启拖动
}"
>
<div class="header"></div>
<div class="dialog-content"></div>
</div>
*/
// 拖拽的指令
const drag = {
beforeMount(el: any, binding: any) {
// 自定义属性,判断是否可拖拽
if (!binding.value.drag) return
const dialogHeaderEl = el.querySelector(binding.value.dragEle)
const dragDom = el
dialogHeaderEl.style.cssText += ';cursor:move;'
// dragDom.style.cssText += ';bottom:0px;'
// 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);
const sty = (function () {
if ((document.body as any).currentStyle) {
// 在ie下兼容写法
return (dom: any, attr: any) => dom.currentStyle[attr]
}
return (dom: any, attr: any) => getComputedStyle(dom, null)[attr]
})()
dialogHeaderEl.onmousedown = (e: any) => {
// 鼠标按下,计算当前元素距离可视区的距离
const disX = e.clientX - dialogHeaderEl.offsetLeft
const disY = e.clientY - dialogHeaderEl.offsetTop
const screenWidth = document.body.clientWidth // body当前宽度
const screenHeight = document.documentElement.clientHeight // 可见区域高度(应为body高度可某些环境下无法获取)
const dragDomWidth = dragDom.offsetWidth // 对话框宽度
const dragDomheight = dragDom.offsetHeight // 对话框高度
const minDragDomLeft = dragDom.offsetLeft
const maxDragDomLeft = screenWidth - dragDom.offsetLeft - dragDomWidth
const minDragDomTop = dragDom.offsetTop
const maxDragDomTop = screenHeight - dragDom.offsetTop - dragDomheight
// 获取到的值带px 正则匹配替换
let styL = sty(dragDom, 'left')
// 为兼容ie
if (styL === 'auto') styL = '0px'
let styT = sty(dragDom, 'top')
// console.log(styL)
// 注意在ie中 第一次获取到的值为组件自带50% 移动之后赋值为px
if (styL.includes('%')) {
styL = +document.body.clientWidth * (+styL.replace(/%/g, '') / 100)
styT = +document.body.clientHeight * (+styT.replace(/%/g, '') / 100)
} else {
styL = +styL.replace(/px/g, '')
styT = +styT.replace(/px/g, '')
}
document.onmousemove = function (e) {
// 通过事件委托,计算移动的距离
let left = e.clientX - disX
let top = e.clientY - disY
// 边界处理
if (-(left) > minDragDomLeft) {
left = -(minDragDomLeft)
} else if (left > maxDragDomLeft) {
left = maxDragDomLeft
}
if (-(top) > minDragDomTop) {
top = -(minDragDomTop)
} else if (top > maxDragDomTop) {
top = maxDragDomTop
}
// 移动当前元素
dragDom.style.cssText += `;left:${left + styL}px;top:${top + styT}px;`
}
document.onmouseup = function (e: any) {
document.onmousemove = null
document.onmouseup = null
}
return false
}
}
}
// 挂载,注册
const directives = {
install: function (app: any) {
app.directive('dialogDrag', drag)
}
};
export default directives;

@ -0,0 +1,32 @@
import { createApp } from "vue";
import { createPinia } from "pinia";
import App from "./App.vue";
import router from "./router";
import 'nprogress/nprogress.css';
import "./assets/main.css";
import 'element-plus/dist/index.css';// element plus样式
import * as ElIcons from '@element-plus/icons-vue' //element plus图标
//全局移动指令
import dragMove from "./directives/dragMove";
const app = createApp(App);
//全局引用element-plus
// import ElementPlus from 'element-plus';
// app.use(ElementPlus);
// 全局注册element-plus图标
for (const name in ElIcons) {
app.component(name, (ElIcons as any)[name]);
}
app.use(createPinia());
app.use(router);
//注册全局移动指令
app.use(dragMove)
app.mount("#app");

@ -0,0 +1,26 @@
import { createRouter, createWebHistory, createWebHashHistory } from "vue-router";
import Nprogress from 'nprogress';
import HomeView from "../views/HomeView.vue";
const router = createRouter({
history: createWebHashHistory(),
//使用history打包后会变空白
// history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: "/",
name: "home",
component: HomeView //() => import("../views/HomeView.vue"),
},
],
});
router.beforeEach((to, from, next) => {
Nprogress.start();
next();
});
router.afterEach(to => {
Nprogress.done();
});
export default router;

@ -0,0 +1,147 @@
import axios, { AxiosRequestConfig as _AxiosRequestConfig, AxiosResponse as _AxiosResponse } from 'axios';
import { ElMessage } from 'element-plus';
import { BASE_URL } from "@/services/urlConfig";
import * as qs from 'qs';
// 可能需要自定义添加些配置
interface AxiosRequestConfig extends _AxiosRequestConfig { }
interface AxiosResponse extends _AxiosResponse { }
// 约束封装axios四个方法的对象
interface Http {
get(data: any, url: string, header?: any, baseUrl?: string): Promise<any>;
post(data: any, url: string, header?: any, baseUrl?: string): Promise<any>;
put(data: any, url: string, header?: any, baseUrl?: string): Promise<any>;
delete(data: any, url: string, header?: any, baseUrl?: string): Promise<any>;
}
// 约束方法名称数组
type HttpName = keyof Http;
// 方法名称数组用于循环封装axios方法
const funArr: HttpName[] = ['get', 'post', 'put', 'delete'];
// axios 全局配置
const DEFAULT_CONFIG: AxiosRequestConfig = {
timeout: 30 * 1000 // 超时
};
const http = {};
funArr.map((key: HttpName) => {
// 断言当前http类型
(<Http>http)[key] = (data, url, header = null, baseURL = BASE_URL) => {
// 根据全局配置创建 axios 实例
const instance = axios.create(DEFAULT_CONFIG);
// 请求拦截器
instance.interceptors.request.use(
(config: AxiosRequestConfig) => {
return config;
},
err => Promise.reject(err)
);
// 响应拦截器
instance.interceptors.response.use(
(response: AxiosResponse) => {
if (response.status && response.status === 200) {
if (response.data.code === 0) {
ElMessage.error(response.data.msg);
return Promise.reject(response.data.msg);
}
if (response.data.code === 500) {
ElMessage.error(response.data.msg);
return Promise.reject(response.data.msg);
}
return response.data;
// if (response.data.status) {
// return response.data.msg;
// } else {
// ElMessage.error(response.data.error);
// return Promise.reject(response.data.error);
// }
}
},
error => {
if (error && error.response) {
let msg = '';
switch (error.response.status) {
case 400:
msg = '错误请求';
break;
case 401:
msg = '未授权,请重新登录';
break;
case 403:
msg = '拒绝访问';
break;
case 404:
msg = '请求错误,未找到该资源';
break;
case 405:
msg = '请求方法未允许';
break;
case 408:
msg = '请求超时';
break;
case 500:
if (error.response.data.message !== null) {
msg = error.response.data.message;
} else msg = '服务器出错!';
break;
case 501:
msg = '服务器无法识别请求方法';
break;
case 502:
msg = '网络错误';
break;
case 503:
msg = '服务不可用';
break;
case 504:
msg = '网络超时';
break;
case 505:
msg = 'http版本不支持该请求';
break;
default:
msg = '未知的错误,请联系管理员!';
}
ElMessage.error({ message: msg });
} else {
// 超时处理
if (error.message.includes('timeout')) {
ElMessage.error({ message: '服务器响应超时,请刷新当前页' });
} else {
ElMessage.error({ message: '未知的错误,请联系管理员!' });
}
}
return Promise.reject(error);
}
);
// 组织请求数据
const requestData: AxiosRequestConfig = {
method: key,
headers: header || { "Content-Type": "application/json" },
url,
baseURL
};
// 对请求中的 data 进行处理
if (key === 'get') {
requestData.params = data;
} else if (data instanceof FormData) {
// 一般post采用FormData的形式发送数据
requestData.data = data;
} else {
// 将对象转为url参数形式 { a: 1, b: 2 } => ?a=1&b=2
requestData.data = data;
}
return instance
.request(requestData)
.then(response => Promise.resolve(response))
.catch(error => Promise.reject(error));
};
});
export default <Http>http;

@ -0,0 +1,14 @@
/**
* @description xxxx-
* @author xxxx
* @time yyyy-MM-dd
*/
import http from './httpConfig';
/**
* xx-
* @param data
* @returns
*/
export const login = (data: object) => http.post(data, '/user/login');

@ -0,0 +1,13 @@
const env:string=import.meta.env.VITE_APP_ENV
export const BASE_URL:string|undefined = {
dev: "https://api.devserver.com/base/url",
prod: "https://api.prodserver.com/base/url",
test: "https://api.testserver.com/base/url",
}[env]
const FILE_BASE_URL:string|undefined = {
dev: "https://file.devserver.com/templete/",
prod: "https://file.prodserver.com/templete/",
test: "https://file.testserver.com/templete/",
}[env];

@ -0,0 +1,16 @@
import { defineStore } from "pinia";
export const useCounterStore = defineStore({
id: "counter",
state: () => ({
counter: 0,
}),
getters: {
doubleCount: (state) => state.counter * 2,
},
actions: {
increment() {
this.counter++;
},
},
});

@ -0,0 +1,37 @@
<script setup lang="ts">
import { ref, reactive, onMounted } from "vue";
import HtmlView from "../components/HtmlView.vue";
onMounted(async () => {});
</script>
<template>
<main>
<div class="container">Hello Vite</div>
</main>
</template>
<style lang="less" scoped>
main {
width: 100%;
height: 100%;
display: flex;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
.container {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
font-size: 3rem;
font-family: "Comic Sans MS", cursive, sans-serif;
font-weight: bold;
overflow: hidden;
}
}
</style>

@ -0,0 +1,21 @@
{
"extends": "@vue/tsconfig/tsconfig.web.json",
"include": [
"env.d.ts",
"src/**/*",
"src/**/*.vue"
],
"exclude": [
"src/**/__tests__/*"
],
"compilerOptions": {
"composite": true,
"baseUrl": ".",
"paths": {
"@/*": [
"./src/*"
]
},
"preserveValueImports": false
}
}

@ -0,0 +1,18 @@
{
"extends": "@vue/tsconfig/tsconfig.node.json",
"include": [
"vite.config.*",
"vitest.config.*",
"cypress.config.*",
"src/**/*",
"build/**/*",
"src/**/*.vue"
],
"compilerOptions": {
"composite": true,
"types": [
"node"
],
"preserveValueImports": false
}
}

@ -0,0 +1,14 @@
{
"files": [],
"references": [
{
"path": "./tsconfig.config.json"
},
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.vitest.json"
}
]
}

@ -0,0 +1,13 @@
{
"extends": "./tsconfig.app.json",
"exclude": [],
"compilerOptions": {
"composite": true,
"lib": [],
"types": [
"node",
"jsdom"
],
"preserveValueImports": false
}
}

@ -0,0 +1,110 @@
import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
// element plus按需导入
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import { configCompressPlugin } from './build/vite/plugins/compress';
const path = require("path");
const resolve = function (dir: any) {
return path.join(__dirname, dir);
};
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
// element plus按需导入
AutoImport({
resolvers: [
//自动导入element plus相关函数
ElementPlusResolver()
]
}),
Components({
resolvers: [
//自动导入element plus组件
ElementPlusResolver()
]
}),
configCompressPlugin('gzip')
],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url))
},
},
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
},
},
},
build: {
// 规定触发警告的 chunk 大小。(以 kbs 为单位)
chunkSizeWarningLimit: 500,
// 指定生成静态资源的存放路径(相对于 build.outDir
assetsDir: "./assets",
// 小于此阈值的导入或引用资源将内联为 base64 编码,以避免额外的 http 请求.单位 KB
assetsInlineLimit: 4096,
// 启用/禁用 CSS 代码拆分。当启用时,在异步 chunk 中导入的 CSS 将内联到异步 chunk 本身,并在其被加载时插入。
// 如果禁用,整个项目中的所有 CSS 将被提取到一个 CSS 文件中。
cssCodeSplit: true
// 分解块,将大块分解成更小的块
// rollupOptions: {
// output: {
// manualChunks(id) {
// if (id.includes('node_modules')) {
// return id.toString().split('node_modules/')[1].split('/')[0].toString();
// }
// }
// }
// }
},
// lintOnSave: true, // 是否开启eslint保存检测
// productionSourceMap: false, // 是否在构建生产包时生成sourcdeMap
// chainWebpack: config => {
// config.resolve.alias
// .set("@", resolve("src"))
// .set("@v", resolve("src/views"))
// .set("@c", resolve("src/components"))
// .set("@u", resolve("src/utils"))
// .set("@s", resolve("src/service")); /* 别名配置 */
// config.optimization.runtimeChunk("single");
// },
server: {
// host: "localhost",
/* 本地ip地址 */
//host: "192.168.1.107",
host: "0.0.0.0", //局域网和本地访问
port: 8080,
/* 自动打开浏览器 */
open: false,
/* 跨域代理 */
// proxy: {
// "/api": {
// /* 目标代理服务器地址 */
// target: "", //
// // target: "", //
// /* 允许跨域 */
// changeOrigin: true,
// ws: true,
// pathRewrite: {
// "^/api": ""
// }
// }
// }
},
// 开发或生产环境服务的公共基础路径。合法的值包括以下几种:
// 绝对 URL 路径名,例如 /foo/
// 完整的 URL例如 https://foo.com/
// 空字符串或 ./(用于嵌入形式的开发)
base: './'
});
Loading…
Cancel
Save