更新脚手架!
This commit is contained in:
101
vite.config.js
101
vite.config.js
@@ -1,7 +1,106 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import { resolve } from 'path'
|
||||
import AutoImport from 'unplugin-auto-import/vite'
|
||||
import Components from 'unplugin-vue-components/vite';
|
||||
import { VantResolver } from 'unplugin-vue-components/resolvers';
|
||||
import postcsspxtoviewport8plugin from 'postcss-px-to-viewport-8-plugin';
|
||||
import viteCompression from 'vite-plugin-compression';
|
||||
import { createHtmlPlugin } from 'vite-plugin-html'
|
||||
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [vue()]
|
||||
plugins: [
|
||||
vue(),
|
||||
// 多页面配置插件
|
||||
createHtmlPlugin({
|
||||
minify: true,
|
||||
pages: [
|
||||
{
|
||||
filename: 'index',
|
||||
entry: '/src/page/Home/main.js',
|
||||
template: 'index.html',
|
||||
injectOptions: {
|
||||
data: {
|
||||
title: '首页',
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
filename: 'share',
|
||||
entry: '/src/page/Share/main.js',
|
||||
template: 'share.html',
|
||||
injectOptions: {
|
||||
data: {
|
||||
title: '分享页',
|
||||
},
|
||||
}
|
||||
}
|
||||
]
|
||||
}),
|
||||
// 按需自动引入vant组件
|
||||
Components({
|
||||
resolvers: [VantResolver()],
|
||||
}),
|
||||
AutoImport({
|
||||
imports: ['vue', 'vue-router',]
|
||||
}),
|
||||
// 开启gzip压缩
|
||||
viteCompression({
|
||||
verbose: true, // 默认即可
|
||||
disable: false, //开启压缩(不禁用),默认即可
|
||||
deleteOriginFile: false, //删除源文件
|
||||
threshold: 10240, //压缩前最小文件大小
|
||||
algorithm: 'gzip', //压缩算法
|
||||
ext: '.gz', //文件类型
|
||||
})
|
||||
],
|
||||
server: { // ← ← ← ← ← ←
|
||||
host: '0.0.0.0' // ← 新增内容 ←
|
||||
},
|
||||
// 别名配置
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': resolve(__dirname, './src'),
|
||||
},
|
||||
extensions: ['.js', '.vue', '.json'] // 引入对应的文件时可以忽略其后缀
|
||||
},
|
||||
// css处理器配置
|
||||
css: {
|
||||
postcss: {
|
||||
plugins: [
|
||||
postcsspxtoviewport8plugin({
|
||||
unitToConvert: 'px',
|
||||
viewportWidth: file => {
|
||||
let num = 750;
|
||||
//van是375
|
||||
if (file.indexOf('van') > 0) {
|
||||
num = 375;
|
||||
}
|
||||
return num;
|
||||
},
|
||||
unitPrecision: 5, // 单位转换后保留的精度
|
||||
propList: ['*'], // 能转化为vw的属性列表
|
||||
viewportUnit: 'vw', // 希望使用的视口单位
|
||||
fontViewportUnit: 'vw', // 字体使用的视口单位
|
||||
selectorBlackList: ['ignore-'], // 需要忽略的CSS选择器,不会转为视口单位,使用原有的px等单位。
|
||||
minPixelValue: 1, // 设置最小的转换数值,如果为1的话,只有大于1的值会被转换
|
||||
mediaQuery: true, // 媒体查询里的单位是否需要转换单位
|
||||
replace: true, // 是否直接更换属性值,而不添加备用属性
|
||||
exclude: [], // 忽略某些文件夹下的文件或特定文件,例如 'node_modules' 下的文件
|
||||
include: [], // 如果设置了include,那将只有匹配到的文件才会被转换
|
||||
landscape: false, // 是否添加根据 landscapeWidth 生成的媒体查询条件 @media (orientation: landscape)
|
||||
landscapeUnit: 'vw', // 横屏时使用的单位
|
||||
landscapeWidth: 1628, // 横屏时使用的视口宽度
|
||||
}),
|
||||
],
|
||||
preprocessorOptions: {
|
||||
scss: {
|
||||
javascriptEnabled: true,
|
||||
additionalData: '@import "@/styles/global.scss";',
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user