vite.config.ts配置

配置路径处理模块

安装ts的类型声明文件

yarn add @types/node -D

通过配置alias来定义路径的别名

resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
'@coms': path.resolve(__dirname, 'src/components')
}
}

配置自动在浏览器打开

server: {
open: true
}

配置scss全局变量

安装依赖

npm install node-sass sass-loader sass -D
css: {
preprocessorOptions: {
scss: {
additionalData: `@import "@/assets/scss/_theme.scss";`
}
}
}

 vite.config.ts中虽然不对报错但是process.env参数中没有.env配置文件中的参数

配置按需加载

import styleImport from 'vite-plugin-style-import'
plugins: [
vue(),
styleImport({
libs: [{
libraryName: 'vant',
esModule: true,
resolveStyle: (name) => {
return `vant/es/${name}/style/css`;
},
}]
})
]

完整配置文件如下

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// import styleImport from 'vite-plugin-style-import'
import importToCDN, { autoComplete } from 'vite-plugin-cdn-import'
// 路径处理模块
import path from 'path' // https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
// styleImport({
// libs: [{
// libraryName: 'vant',
// esModule: true,
// resolveStyle: (name) => {
// return `vant/es/${name}/style/css`;
// },
// }]
// }),
importToCDN({
modules: [
autoComplete('vue'),
autoComplete('axios'),
autoComplete('lodash'),
{
name:'vue',
var:'Vue',
path:'https://cdn.jsdelivr.net/npm/vue@next'
},
{
name:'vuex',
var:'Vuex',
path:'https://cdn.jsdelivr.net/npm/vuex@4.0.2/dist/vuex.global.prod.js'
},
{
name:'vue-router',
var:'VueRouter',
path:'https://cdn.jsdelivr.net/npm/vue-router@4.0.10/dist/vue-router.global.prod.js'
},
{
name:'vant',
var:'vant',
css: 'https://cdn.jsdelivr.net/npm/vant@next/lib/index.css',
path:'https://cdn.jsdelivr.net/npm/vant@next/lib/vant.min.js'
}
]
})
],
resolve: {
// 定义别名
alias: {
'@': path.resolve(__dirname, 'src'),
'@components': path.resolve(__dirname, 'src/components')
}
},
css: {
preprocessorOptions: {
scss: {
charset: false,
additionalData: `@import "@/assets/scss/_theme.scss";`
},
less: {
javascriptEnabled: true
}
}
},
build: {
target: 'modules',
outDir: 'dist', // 指定输出路径
assetsDir: 'static', // 指定生成静态资源的存放路径
minify: 'terser', // 混淆器,terser构建后文件体积更小
sourcemap: false,
terserOptions: {
compress: {
drop_console: true, // 生产环境移除console
drop_debugger: true // 生产环境移除debugger
}
},
rollupOptions: {
treeshake: false,
output: {
manualChunks (id) {
if (id.includes('node_modules')) {
return id.toString().split('node_modules/')[1].split('/')[0].toString()
}
}
}
}
},
server: {
open: true, // 是否在浏览器打开
port: 8088, // 端口号
host: 'local.xxx.com'
},
// 引入第三方配置
optimizeDeps: {
include: []
}
})

最新文章

  1. C++ 11 多线程--线程管理
  2. iframe跨域+
  3. hibernate注解——@Temporal
  4. Linux实时流量监控工具 - iftop
  5. 【转】【MMX】 基于MMX指令集的程序设计简介
  6. PHP中使用数组指针函数操作数组示例
  7. 利用Shell命令获取IP地址
  8. Windows 进程通信 之 DDE技术
  9. ios Swift 资源池
  10. WinSock 异步I/O模型 转载
  11. 在单链表和双链表中删除倒数第k个结点
  12. Sybase identity 字段
  13. shell,python获取当前路径(脚本的当前路径) (aso项目记录)
  14. python学习第24天
  15. lemon special judge模板
  16. python爬虫——与不断变化的页面死磕和更新换代(3)
  17. Animate.css(一款有意思的CSS3动画库)
  18. IP地址、MAC地址及端口
  19. DRF框架固定配置
  20. Ajax在jQuery中的应用 (4)向jsp提交表单数据

热门文章

  1. 可扩展标记语言XML(淅淅沥沥的小雨)
  2. noVNC连接多台远程主机
  3. [BUUCTF]REVERSE——[GKCTF2020]BabyDriver
  4. CF950A Left-handers, Right-handers and Ambidexters 题解
  5. LuoguP7019 [NWRRC2017]Auxiliary Project 题解
  6. 网络路径排查工具使用/原理浅析(MTR、traceroute、tracepath、windows下besttrace)
  7. -bash: /etc/ld.so.preload: Operation not permitted处理
  8. c++设计模式概述之适配器
  9. 【九度OJ】题目1024:畅通工程 解题报告
  10. 【LeetCode】985. Sum of Even Numbers After Queries 解题报告(C++)