Vite way to explore https:https://cdn.v2ex.com/navatar/20d1/35f0/1112_normal.png?m=1636147498 https:https://cdn.v2ex.com/navatar/20d1/35f0/1112_large.png?m=1636147498 2025-01-02T08:20:10Z Copyright © 2010-2018, V2EX vite 通过局域网或者端口转发进行访问时特别慢。 tag:www.v2ex.com,2025-01-02:/t/1102050 2025-01-02T08:20:10Z 2025-01-02T08:20:10Z Danswerme member/Danswerme 有时想把本地开发中的链接发给同事,同事通过局域网访问时打开特别慢,DevTools 中可以看到主要是卡在入口文件,搜了一下也有人提到了类似的问题:
https://www.xqy404.com/blog/2024/migrate-vite-to-rspack/ ,但是没有解决方案。

大家有遇到这个问题的吗?

]]> vite+vue3 有什么插件可以让编译后的 js 被加密保护吗。类似 jsjiami.com 那样 tag:www.v2ex.com,2023-08-31:/t/969726 2023-08-31T04:29:55Z 2023-09-13T05:37:10Z dzdh member/dzdh vite 有什么插件会把 unicode 转成中文吗 tag:www.v2ex.com,2023-08-22:/t/967335 2023-08-22T04:04:26Z 2023-08-22T09:56:14Z chenliangngng member/chenliangngng
但是 build 之后 unicode 变成了中文(直接看 dist 里面的 css),导致生产环境偶发中文乱码。

项目是 vue3+vite+antdv


其他插件
```
"@vitejs/plugin-vue":"^2.3.1",
"@vitejs/plugin-vue-jsx":."^1.3.10",
"vite":"^2.9.7",
"vite-babel-plugin":"0.0.2",
"vite-plugin-cesium":"1.2.10",
"vite-plugin-commonjs-externals":"00.1.1",
``` ]]>
请教: vite + electron.js + vue.js 3 开发桌面软件,无法在 renderer 中加载 C++ node module tag:www.v2ex.com,2023-08-16:/t/965905 2023-08-16T13:40:48Z 2023-08-16T14:17:48Z feelapi member/feelapi 首先这个场景特殊,不应该在 renderer 中使用 C++ node module ,这个 node 是用来做几何计算的。技术栈基于 electron-vite, 尝试了 vite-plugin-native ,未遂。增加 assetesInclude 可以过滤 node 打包,但是不能加载 node 。

]]>
请教一个 vite 代理的问题 tag:www.v2ex.com,2023-04-12:/t/931821 2023-04-12T02:06:53Z 2023-04-12T05:57:14Z qq309187341 member/qq309187341 我通过 configure 方法拦截了对应的接口,但是因为这个接口是 post 请求,我要如何才能拿到其中的 body 内容,req.body 返回的是 undefined 。是不是需要使用 body-parser 插件解析一下?能不能写下如何操作?

server: {
port: 9900,
proxy: {
'/root': {
target: 'http://192.168.3.216',
changeOrigin: true,
configure: (proxy, options) => {
proxy.on('proxyReq', (proxyReq, req, res) => {
console.log(req.body)
})
}
},
},
}, ]]>
请问各位大佬一个 vite 插件的问题 tag:www.v2ex.com,2023-03-29:/t/928106 2023-03-29T03:37:43Z 2023-03-29T03:36:43Z qq309187341 member/qq309187341 vite 设置生产环境 baseURL 为 /api/,真实请求会自动添加本机 ip 地址吗 tag:www.v2ex.com,2023-03-28:/t/927751 2023-03-28T02:16:41Z 2023-04-05T09:01:06Z jiechen257 member/jiechen257 # .env.production 文件 # 线上环境 NODE_ENV = "production" # 线上环境接口地址(easymock) VITE_API_URL = "/api/" # VITE_API_URL = "http://192.168.3.220:80/api/"
// 用于 axios 配置 const cOnfig= { // 默认地址请求地址,可在 .env.*** 文件中修改 baseURL: import.meta.env.VITE_API_URL as string, // 设置超时时间( 10s ) timeout: ResultEnum.TIMEOUT as number, // 跨域时候允许携带凭证 withCredentials: true }; 

如代码所示,我改为 /api/ 后,生产环境还是能正常访问后端,我查了下 axios 的 baseURL 字段解释,是明确说了不会自己添加 ip 的,所以想请教下是什么情况

]]>
Vite 执行 build 时如何能够自动添加其他文件到 dist 文件夹? tag:www.v2ex.com,2022-12-13:/t/902145 2022-12-13T03:33:48Z 2022-12-13T05:58:42Z dominickkorey member/dominickkorey 搜索了半天好像也没有找到相关的需求,大家如果有知道的话可以告诉我

]]>
element plus 按钮的问题,求帮助 tag:www.v2ex.com,2022-11-11:/t/894497 2022-11-11T07:27:37Z 2022-11-11T07:31:21Z qq309187341 member/qq309187341
1:无法显示
<el-button text size="large" :icon="props.collapsed ? IExpand : IFold" class="collapsed">
</el-button>

2.可以显示
<el-button text size="large" class="collapsed">
<IExpand />
</el-button>

请问是写法不对,还是哪些需要配置。倾向第一种方式。如果是因为使用了插件导致组件库无法识别的话,目前无法解决的话,我只能使用第二种方式了。 ]]>
问下前端大佬,VITE+ESLINT+VSCODE 在 编译阶段 不报错怎么解决? tag:www.v2ex.com,2022-08-19:/t/873979 2022-08-19T06:12:58Z 2022-08-11T06:12:58Z colatea member/colatea
VUE-CLI+VSCODE 就报错

VITE 不知道是什么鬼,非要在浏览器里操作到位置的时候才会在 console 里报,弄了一堆暗病

请问大佬,这是 VITE 的特性还是我配置有问题?? ]]>
Vite + React + Ant Design + Tailwind CSS + ESLint + Prettier + TypeScript 最佳实践 tag:www.v2ex.com,2022-08-10:/t/872054 2022-08-10T17:58:46Z 2022-12-06T11:41:45Z nanxiaobei member/nanxiaobei 很难过 Create React App 被时代淘汰,现在我们用 Vite 开发 React + Ant Design 吧。

很难过 CSS 被时代淘汰(明明没有好不好!),现在我们用 Tailwind CSS 吧。

很难过 yarn 被时代淘汰,现在我们用 pnpm 吧。

1. 用 Vite 生成一个 React + TypeScript 项目

pnpm create vite my-react-app --template react-ts 

https://vitejs.dev/guide/#scaffolding-your-first-vite-project

2. 按照提示进入项目,安装依赖:

cd my-react-app pnpm install 

3. 安装 Ant Design 相关依赖

pnpm add antd @ant-design/icons pnpm add -D less vite-plugin-imp # 用于按需引入组件 

https://ant.design/docs/react/introduce#Using-npm-or-yarn

4. 修改 vite.config.ts 为如下内容:

import { defineConfig } from 'vite'; import vitePluginImp from 'vite-plugin-imp'; import react from '@vitejs/plugin-react'; // https://vitejs.dev/config/ export default defineConfig({ plugins: [ react(), vitePluginImp({ optimize: true, libList: [ { libName: 'antd', style: (name) => `antd/es/${name}/style`, }, ], }), ], css: { preprocessorOptions: { less: { JavascriptEnabled: true, // 如需定制 antd 主题,请取消以下内容注释 https://ant.design/docs/react/customize-theme // modifyVars: { // hack: `true; @import "./src/theme.less";`, // }, }, }, }, }); 

https://vitejs.dev/config/

5. 安装 Tailwind CSS 相关依赖

pnpm add -D tailwindcss postcss autoprefixer npx tailwindcss init 

Tailwind CSS ,用过都说好!几乎不用再添加 less/scss 文件,不用切换文件改完 CSS 再切回来,直接修改组件的 className 即可,"最短修改路径",便捷简洁现代化!(当然如果不想用可以不安装)

6. 按照 Tailwind CSS 官方指南配置

https://tailwindcss.com/docs/installation/using-postcss

注意:生成的 TypeScript 项目中,不支持 .js 配置文件,需使用 .cjs 文件。

touch postcss.config.cjs 

postcss.config.cjs 内容:

module.exports = { plugins: { tailwindcss: {}, autoprefixer: {}, }, }; 

tailwind.config.cjs 内容:

/** @type {import('tailwindcss').Config} */ module.exports = { content: ['./src/**/*.{html,tsx}'], theme: { extend: {}, }, plugins: [], }; 

重命名 index.cssmain.css,修改其内容为:

@tailwind base; @tailwind components; @tailwind utilities; 

6. 安装 ESLint 相关依赖

pnpm add -D eslint eslint-config-react-app 

https://github.com/facebook/create-react-app/tree/main/packages/eslint-config-react-app

虽然 create-react-app 被淘汰了,但它的 ESLint 规则还是最权威的,开发 React 项目的最佳规范!

7. 安装 Prettier 相关依赖

pnpm add -D prettier eslint-config-prettier @trivago/prettier-plugin-sort-imports 

https://github.com/prettier/eslint-config-prettier
https://github.com/trivago/prettier-plugin-sort-imports

@trivago/prettier-plugin-sort-imports,一个非常好用的对 import 进行自动排序的 Prettier 插件,用了就回不去了!(当然如果不想用可以不安装)

8. 添加 .eslintrc.cjs

touch .eslintrc.cjs 
module.exports = { extends: ['react-app', 'prettier'], }; 

9. 添加 .prettierrc.cjs

touch .prettierrc.cjs 
module.exports = { singleQuote: true, // 以下为 @trivago/prettier-plugin-sort-imports 配置,若未使用可删去 // importOrder 中的文件顺序规范,可依据项目实际情况自行更改 plugins: [require.resolve('@trivago/prettier-plugin-sort-imports')], importOrder: [ '^vite', '^react', '^antd', '<THIRD_PARTY_MODULES>', 'components/', 'pages/', 'hooks/', 'utils/', '^[./]', ], importOrderSortSpecifiers: true, importOrderGroupNamespaceSpecifiers: true, importOrderCaseInsensitive: true, }; 

10. 大功告成,试试吧!

删除 App.css,修改 App.tsx 文件为:

import { useState } from 'react'; import { Button } from 'antd'; import { AlertOutlined } from '@ant-design/icons'; import reactLogo from './assets/react.svg'; function App() { const [count, setCount] = useState(0); return ( <div className="grid place-content-center h-screen text-center text-lg"> <div className="flex mx-auto items-center gap-8"> <a href="https://vitejs.dev" target="_blank" rel="noreferrer"> <img src="http://www.v2ex.com/vite.svg" className="w-28" alt="Vite logo" /> </a> <a href="https://reactjs.org" target="_blank" rel="noreferrer"> <img src={reactLogo} className="w-32 animate-spin [animation-duration:10s]" alt="React logo" /> </a> </div> <h1 className="my-20 font-semibold text-6xl">Vite + React</h1> <div> <Button className="inline-flex items-center rounded-md" size="large" icon={<AlertOutlined />} OnClick={() => setCount((count) => count + 1)} > count is {count} </Button> <p className="mt-4 mb-12"> Edit <code>src/App.tsx</code> and save to test HMR </p> </div> <p className="opacity-40"> Click on the Vite and React logos to learn more </p> </div> ); } export default App; 

启动项目:

pnpm run dev 

耶寺!点开本地开发链接看看效果吧!

附赠

以上 shell 命令的合订版:

pnpm create vite my-react-app --template react-ts cd my-react-app pnpm install pnpm add antd @ant-design/icons pnpm add -D less vite-plugin-imp tailwindcss postcss autoprefixer eslint eslint-config-react-app prettier eslint-config-prettier @trivago/prettier-plugin-sort-imports npx tailwindcss init touch postcss.config.cjs touch .eslintrc.cjs touch .prettierrc.cjs 
]]>
vite+vue3+ts 自己搭建时候一些步骤及踩坑分享 tag:www.v2ex.com,2022-07-01:/t/863345 2022-07-01T00:25:00Z 2022-07-01T01:31:48Z missilexuan member/missilexuan vite 官网

初始构建运行

跟着官网构建完成后
yarn 拉取包后直接 yarn dev 无法运行起来
命令行显示

> Local: http://localhost:3000/ > Network: use `--host` to expose 

页面显示 Cannot GET /

原因:没有局域网中暴露服务
需要再 vite.config.ts 中添加配置

server: { host: '0.0.0.0' } 

添加后命令行显示

 > Network: http://192.168.52.1:3000/ > Network: http://192.168.142.1:3000/ > Local: http://localhost:3000/ > Network: http://172.17.12.99:3000/ 

可正常访问

配置 Eslint standard 规则

由于 vite 中没有帮我们引入 eslint 代码校验,所以我们需要自己手动配置 eslint
注意不要照抄 vue-cli 里的 .edlintrc.js 配置 其中一些引入的内容是针对 vue-cli 来的

需要安装的包

yarn add eslint eslint-plugin-vue eslint-config-standard eslint-plugin-import eslint-plugin-n eslint-plugin-promise @typescript-eslint/parser @typescript-eslint/eslint-plugin vite-plugin-eslint -D 

各包说明

//基础的 eslit eslint //Vue 的官方 ESLint 插件 针对 vue 语法进行校验 eslint-plugin-vue // standard 规则校验 eslint-config-standard eslint-plugin-import //eslint-plugin-n 用 n 不要用 node node 停止维护了 standard 依赖会报错 eslint-plugin-n eslint-plugin-promise // 一个 ESLint 解析器,它利用 TypeScript ESTree 允许 ESLint lint TypeScript 源代码 @typescript-eslint/parser // 一个 ESLint 插件,为 TypeScript 代码库提供 lint 规则 @typescript-eslint/eslint-plugin vite-plugin-eslint // vite ESLint 插件。 

添加.eslintrc.js 文件

module.exports = { root: true, parser: 'vue-eslint-parser', extends: [ 'standard', 'plugin:@typescript-eslint/recommended', 'plugin:vue/vue3-recommended' ], plugins: ['@typescript-eslint', 'vue'], env: { node: true }, parserOptions: { ecmaVersion: 2020, parser: '@typescript-eslint/parser' } } 

如果不生效检查下 vsconde eslint 插件有没有安装启用,如果安装了 看下 eslint 插件有没有报错

vue3 <script setup lang="ts"> 写法中不需要引入 defineProps 即可使用
但是 eslint 会报错 需要在配置文件中添加配置

env: { node: true, 'vue/setup-compiler-macros': true ++ }, 

之后发现新问题
发现 standard 语法规则 vscode 会报红 但是运行不会报错
发现是 vite.config.ts 中 eslintPlugin({ include: []}) 只写了 js 将 ts 补上就好了

@ 指向 src

在 vite.config.ts 中配置

 resolve: { alias: { // 当使用文件系统路径的别名时,请始终使用绝对路径。相对路径的别名值会原封不动地被使用,因此无法被正常解析。 '@': path.resolve(__dirname, './src') } } 

没有 path 需要引入 import path from 'path'
如果 path 报引入错误 需要在 tsconfig.node.json 中 添加

"compilerOptions": { "allowSyntheticDefaultImports": true } 

如果是 ts 项目 还需要 yarn add @types/node -D
同时在 config.json 中添加

"compilerOptions": { "baseUrl": ".", "paths": { "@/*": ["src/*"] } } 

环境变量

vue-router

yarn add vue-router@4

css 预处理器

npm add -D stylus 官网说明
Vite 也同时提供了对 .scss, .sass, .less, .styl 和 .stylus 文件的内置支持。
没有必要为它们安装特定的 Vite 插件,但必须安装相应的预处理器依赖
引入全局则需要 yarn add stylus-loader -D

引入全局样式在 vite.config.ts 中添加

css: { preprocessorOptions: { stylus: { imports: [ path.resolve(__dirname, './src/assets/stylus/reset.styl') ] } } } 

打包 GZIP 压缩

yarn add vite-plugin-compression -D 在 vite.config.ts 中引入 配置说明

import viteCompression from 'vite-plugin-compression' export default defineConfig({ plugins: [ viteCompression({ threshold: 100 * 1000 }) ] }) 

路由+transition

transition 内必须只有一个根元素

自动引入文件夹内文件

在之前 package 打包模式下
提供了 require.context 来进行文件夹遍历导入功能
我们在自动导入 store 中用到了

在 vite 中 没有 require.context ,vite 提供了 import.meta.glob 进行导入

]]>
How to use Vite to build all kinds of TypeScript projects, including CSR/SSR/CDN/MonoRepository tag:www.v2ex.com,2022-05-05:/t/850995 2022-05-05T09:55:31Z 2022-05-09T09:05:24Z taowen member/taowen https://github.com/taowen/vite-howto

蹩脚英文,见谅

]]>
请问能否通过 vite 插件功能去修改项目中某一个文件的内容或者获取文件内容? tag:www.v2ex.com,2022-05-02:/t/850538 2022-05-02T11:17:56Z 2022-05-02T12:42:11Z qq309187341 member/qq309187341 vite 应该怎么学? tag:www.v2ex.com,2022-01-09:/t/827185 2022-01-09T14:59:15Z 2022-01-08T22:59:15Z Leviathann member/Leviathann 有的配置还和 rollup 有重叠

比如我想把打包的东西都输出到一个文件夹(而不是默认的 dist + dist/asset )并且自定义一个打包目标文件名,在官网搜了半天没搜到怎么配,尝试配 buildRollupOptions ,改了 file 又报错,又根据报错改了几个配置项才发现原来需要把 dir 和 manualChunks 设为 undefined 来把 vite 默认的配置覆盖掉才行

怎么才能知道 vite 默认的 rollup 配置是啥?必须看源码吗?

而且感觉前端的工具链有很多重叠的功能,esbuild 可以设置编译目标,tsc 也可以,rollup 也可以用 babel 插件做

tsc 直接指定版本就行( es5 )而 esbuild 和 babel 要用个奇怪的 query 字符串,指定浏览器版本或者占有率啥的?

另外如果想指定输入和输出的 html 文件名又该怎么做?

官网没提,翻 rollup 的文档发现官方的实例的 entry 都是 js 文件,试了一下手动在 rollupOptions 指定 input ,但是又和 output 的 file 冲突? ]]>
vite 打包后,好好的功能报错了?有没有懂 vite 打包原理的大佬,求解一下 tag:www.v2ex.com,2021-11-17:/t/816007 2021-11-17T04:59:31Z 2021-11-17T08:36:25Z devilte member/devilte 前端项目,技术栈是 Vue3.x + Vite + TypeScript

本地运行起来的一切正常,打包上线后,控制台报了错误:

TypeError: Right-hand side of 'instanceof' is not an object 

调试之后发现,打包后的源码里,一个 instanceof 方法的左边是一个 div 元素对象,这个 div 对象是用来绑定画布用的容器,代码中如下:

 template: <div class="graph" ref="graphRef" id="graphRef"></div> script: const graphRef = ref<HTMLElement | null>(null); 

报错位置代码如下,图上的这些代码并不是写在项目里的,应该是打包后注入进去的: I4YiC9.png

现在问题就是不知道 打包后的这些方法使用逻辑是什么?怎么解决这个报错呢?求解

]]>
Vite+React+TS+Eslint+Prettier starter kit tag:www.v2ex.com,2021-11-13:/t/815145 2021-11-13T07:47:39Z 2021-11-13T07:45:39Z XTTX member/XTTX
Vite + React + Typescript + Eslint + Airbnb eslint rules + Airbnb Typescript rules + Prettier + env variable import + Absolute Import Path


https://github.com/jt6677/vite_ts_eslint_prettier_aribnbts

==============================================
!yes, tons of setup and config files.

==============================================
env variable import:

You need to add type in env.d.ts like "readonly VITE_ANYTHING: string"
variables MUST start with VITE_
usage of env variable in your app, no need to import, just use it as a global variable: console.log(import.meta.env.VITE_API_URL)

==============================================
Absolute Import Path

import App from "~/components". ~/ is the absoulte path, equal to ./src

==============================================
reverse Proxy in vite.config.ts ]]>
VitePress 如何创建自定义的 UI 主题 tag:www.v2ex.com,2021-05-12:/t/776391 2021-05-12T02:07:27Z 2021-05-12T02:04:27Z oligi member/oligi
  • 尤大新出的 vitepress 据说比 vuepress 更好,所以想试试
  • 搭建好项目后发现自带的 UI 很不喜欢,所以打算换个类似 elementUI 或者 Vuetify,请问有大佬知道吗?
  • ]]>
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86