将 Vuetify 2 添加到 vite 项目
我的团队使用基于类的组件和打字稿在 Vue 2 中开发应用程序。
现在,我们想迁移到 Vite - 因为它具有所有优势。
我已遵循本指南(我只能推荐) https://vueschool.io/ articles/vuejs-tutorials/how-to-migrate-from-vue-cli-to-vite/
简而言之 - 它不起作用。浏览器甚至无法从index.html获取“/src/main.js” 但是如果我输入“/src/main.ts”,它会获取它,但会显示错误,表明 Vuetify 甚至没有安装。 我知道.ts文件是浏览器无法读取的,我只是在调试了2个小时后尝试了一下
此外,我在Vuetify文档中看到“第一方Vite支持”仍有待发布。 https://vuetifyjs.com/en/introduction/roadmap/#in-development
我的问题是 - 是否可以在 Vite 中添加 Vuetify 应用程序?
package.json(仅依赖项)
"dependencies": {
"vue": "^2.6.12",
"vue-class-component": "^7.2.6",
"vue-property-decorator": "^9.1.2",
"vuetify": "^2.4.0",
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"@vitejs/plugin-vue": "^1.6.1",
"@vue/cli-plugin-typescript": "^4.5.15",
"@vue/eslint-config-typescript": "^7.0.0",
"eslint": "^8.9.0",
"eslint-plugin-vue": "^8.5.0",
"sass": "~1.32.0",
"typescript": "~4.1.5",
"vite": "^2.6.13",
"vite-plugin-vue2": "^1.9.2",
"vue-cli-plugin-vuetify": "^2.4.5",
"vue-template-compiler": "^2.6.14",
"vuetify-loader": "^1.7.0"
},
tsconfig.json
{
"compilerOptions": {
// ...
"target": "esnext",
"module": "esnext",
"isolatedModules": true,
"useDefineForClassFields": true,
"types": [
"webpack-env",
"vite/client"
],
vite.config.js
import { defineConfig } from "vite";
import { createVuePlugin as vue } from "vite-plugin-vue2";
const path = require("path");
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
});
顶部呈现的空 html,以及“no vuetify”错误指示器 当我将 .ts 导入 index.html
<script type="module" src="/src/main.ts"></script>
My team developed application in Vue 2 with class based components and typescript.
Now, we want to migrate to Vite - because of all the advantages it carries.
I have followed this guide (which I can only recommend)
https://vueschool.io/articles/vuejs-tutorials/how-to-migrate-from-vue-cli-to-vite/
In short - it don't work. Browser can't even fetch "/src/main.js" from index.html
But if I put "/src/main.ts" it fetches it, but shows errors which indicates Vuetify is not even installed.
I know .ts files are not readable by browser, I just tried it after 2 hours of debugging
Also, I saw in Vuetify documentation that "First party Vite support" is still to be released.
https://vuetifyjs.com/en/introduction/roadmap/#in-development
My question is - is it even possible to add Vuetify in Vite application?
package.json (dependencies only)
"dependencies": {
"vue": "^2.6.12",
"vue-class-component": "^7.2.6",
"vue-property-decorator": "^9.1.2",
"vuetify": "^2.4.0",
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"@vitejs/plugin-vue": "^1.6.1",
"@vue/cli-plugin-typescript": "^4.5.15",
"@vue/eslint-config-typescript": "^7.0.0",
"eslint": "^8.9.0",
"eslint-plugin-vue": "^8.5.0",
"sass": "~1.32.0",
"typescript": "~4.1.5",
"vite": "^2.6.13",
"vite-plugin-vue2": "^1.9.2",
"vue-cli-plugin-vuetify": "^2.4.5",
"vue-template-compiler": "^2.6.14",
"vuetify-loader": "^1.7.0"
},
tsconfig.json
{
"compilerOptions": {
// ...
"target": "esnext",
"module": "esnext",
"isolatedModules": true,
"useDefineForClassFields": true,
"types": [
"webpack-env",
"vite/client"
],
vite.config.js
import { defineConfig } from "vite";
import { createVuePlugin as vue } from "vite-plugin-vue2";
const path = require("path");
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
});
empty html rendered in the top, and "no vuetify" error indicator
when I put .ts import in index.html
<script type="module" src="/src/main.ts"></script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
支持 Vuetify 2 链接
首先安装插件
然后在你的 vite.config.ts 文件中:
There is support for Vuetify 2 link
first install the plugin
Then in your vite.config.ts file:
安装 unplugin-vue-components。
然后在
vite.config.ts
中添加插件如果你也使用 vuetify 自定义 sass 变量
你可以参考我的 Vite 3 + Vuetify 2 + Vue 2.7 的入门模板
它还包括 Vuetify 2 组件中的 TypeScript 支持和 IntelliSense
https://github.com/kingyue737/vitify-admin
Install unplugin-vue-components.
then add the plugin in
vite.config.ts
If you also use vuetify custom sass variable
You can refer to my starter template with Vite 3 + Vuetify 2 + Vue 2.7
It also includes TypeScript support and IntelliSense in Vuetify 2 components
https://github.com/kingyue737/vitify-admin
我已经创建了 startar 模板。
https://github.com/logue/vite-vue2-vuetify-ts- starter
最初是为使用
vue-property-decorator
的项目制作的,它还支持组合 api。如果您想使用合成 API 访问 vuetify 函数,可以使用
useVuetify()
访问它。I've created startar template.
https://github.com/logue/vite-vue2-vuetify-ts-starter
Originally made for projects using
vue-property-decorator
, it also supports composition api.If you want to access the vuetify function with the composition api, you can access it with
useVuetify()
.我创建了存储库,将默认的
vue2
/vuetify2
官方模板从 vue-cli 迁移到 vite 5。它主要使用:
@vitejs/plugin-vue2
和vue:^2.7.0
(这是vue 2所需的最低版本)unplugin-vue-components
for vuetify 2请参阅:https://github.com/sbernard31/vuetify2-vite-template
I created repo where I migrate default
vue2
/vuetify2
official template from vue-cli to vite 5.It used mainly :
@vitejs/plugin-vue2
andvue:^2.7.0
(this is minimal version required) for vue 2unplugin-vue-components
for vuetify 2See : https://github.com/sbernard31/vuetify2-vite-template