-
-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Vite work with Vue 2 #305
Comments
It doesn't work with Vue 2 and |
Unfortunately Vite doesn't work with Vue 2 (at least for now). We should make it work though. |
vue
is detected but no matching @vue/compiler-sfc
is found. Make sure to install both and use the same version.
I appreciate the response. Thanks for the hard work Evan, Marvin and company. |
I didn't do anything, Evan is here the brain. 😄 |
Could you point us to any Update 1: $ npm init vite-app --help
No results for "init" "vite-app" $ npx vitejs/vite --help
Cannot find module '../dist/cli'
Require stack:
- ~/.npm/_npx/59851/lib/node_modules/vite/bin/vite.js Update 2:
So nothing has to be done? |
@jfoliveira Normally you have |
@MarvinRudolph Yeah, but I couldn't find Anyway, tried your suggestion and here is what I did, achieving partial success: // created a new app:
npm init vite-app my-vue3-vite-ts // app created <script lang="ts" type="module" src="/src/main.ts"></script> In the ...
</template>
<script lang="ts">
export interface SomeType {
someProp: string
}
function tsLogValue(param1: SomeType): void {
console.log('Param value strongly typed with TS: ', param1.someProp);
}
tsLogValue(123); // vite/tsc should fail to compile this?!?
tsLogValue({ someProp: 'prop value'}); // this should compile fine
...
export default { Questions:
That would be helpful! |
@jfoliveira vite doesn’t do type-checking like in the readme explained. You need to use |
Oohh, I missed that part, sorry. Now I followed the steps in the README. Created a {
"compilerOptions": {
"isolatedModules": true
}
} Changed my "scripts": {
"dev": "tsc --noEmit && vite",
"build": "tsc --noEmit && vite build"
}, So I should no longer run
Hmmmm, now I think I got it. Vite uses esbuild which supports some TypeScript, but not full TypeScript. If one wants to go full TypeScript then TypeScript needs to be added to the vite created project. Right? Let's try:
Attempted to serve the app in dev mode with vite again, but didn't work. Notice the errors come mainly from $ npm run dev
> my-vue3-vite-ts@0.0.0 dev ~/my-vue3-vite-ts
> tsc --noEmit && vite
node_modules/@vue/reactivity/dist/reactivity.d.ts:166:13 - error TS2339: Property 'matchAll' does not exist on type 'SymbolConstructor'.
166 [Symbol.matchAll]: infer V;
~~~~~~~~
node_modules/@vue/reactivity/dist/reactivity.d.ts:168:13 - error TS2339: Property 'matchAll' does not exist on type 'SymbolConstructor'.
168 [Symbol.matchAll]: V;
~~~~~~~~
node_modules/@vue/runtime-core/dist/runtime-core.d.ts:437:20 - error TS2344: Type 'Function & T[key]["get"]' does not satisfy the constraint '(...args: any) => any'.
Type 'Function' provides no match for the signature '(...args: any): any'.
437 } ? ReturnType<T[key]['get']> : ReturnType<T[key]>;
~~~~~~~~~~~~~
node_modules/@vue/runtime-core/dist/runtime-core.d.ts:437:48 - error TS2344: Type 'T[key]' does not satisfy the constraint '(...args: any) => any'.
Type 'T[keyof T]' is not assignable to type '(...args: any) => any'.
Type 'T[string] | T[number] | T[symbol]' is not assignable to type '(...args: any) => any'.
Type 'T[string]' is not assignable to type '(...args: any) => any'.
437 } ? ReturnType<T[key]['get']> : ReturnType<T[key]>;
~~~~~~
node_modules/@vue/runtime-core/dist/runtime-core.d.ts:950:10 - error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.
950 export { TrackOpTypes }
~~~~~~~~~~~~
node_modules/@vue/runtime-core/dist/runtime-core.d.ts:976:10 - error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.
976 export { TriggerOpTypes }
~~~~~~~~~~~~~~
src/main.ts:2:17 - error TS2307: Cannot find module './App.vue' or its corresponding type declarations.
2 import App from './App.vue'
~~~~~~~~~~~
Found 7 errors.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-vue3-vite-ts@0.0.0 dev: `tsc --noEmit && vite`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-vue3-vite-ts@0.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! ~/.npm/_logs/2020-05-31T15_05_17_994Z-debug.log |
bring support to vue 2 is a totally waste of time, better wait for vue 3 stable version dude |
@mdbetancourt Not every Vue project started recently. You have enterprise applications as well countless others who can't upgrade right now. Get some perspective :\ |
@naknode exactly and this is an experimental project... and afaik they are doing everything they can to make vue 3 backward compatible with vue 2 so before try using an experimental lib and migrate to it you should first try migrate to vue 3, so instead of spending time doing this compatible with vue 2 that time could be used to develop more features. |
i 've ever imagined that might |
Hey guys, I write a plugin to suppot vue2.It can worked fine in dev.See https://github.com/underfin/vite-plugin-vue2 |
Hey I am new to Vue/Vite, so the best way for me learning vue is through vue 2 and the new composition api (cause there are much more rescources). I first tried Vue 3, where I loved Vite. Could you explain me how to integrate Vue 2 with Vite (the fast build is incredible), I couldn't really figure out how to use it in my Vue 2 project.I don't need Typescript support. Kind regards |
@yyx990803 ,I think you should not spend a lot of time to make vite compatible with vue2, vue3 is great and for future.and users of vue2 will switch to vue3. |
can you update it for vite 2, please? |
Yeah. I will work for it. |
@Djaler The major feature is already works.I thinkt it shoule be closed. |
@underfin how about adding a |
I don't seem to be able to run it on my macbook pro. First I get a warning from yarn/npm about @vue/compiler-sfc depending on Vue3:
If I run the app everything seems to be fine. It prints vite's message on the console:
But then any request to the app just returns a 404:
What am I doing wrong? Here is my vite config:
And my main.js:
|
I also created a vite vue2 composition-api example project very recently without any vue cli dependencies: here. |
Thanks, both! I'll check it out. |
With those examples I was able to port my vuetify app to vite. But doesn't seem to be anything like vuetify-loader for vite. I have to manually load all the vuetify components, making all the views look like this: import { mapGetters } from "vuex";
import {
VApp, VAppBar, VMain, VAppBarNavIcon, VToolbarTitle, VRow, VCol, VTextField, VIcon, VBtn, VNavigationDrawer, VList,
VDivider, VListItem, VListItemAction, VListItemContent, VListItemTitle,
} from 'vuetify/lib'
export default {
components: {
VApp, VAppBar, VMain, VAppBarNavIcon, VToolbarTitle, VRow, VCol, VTextField, VIcon, VBtn, VNavigationDrawer, VList,
VDivider, VListItem, VListItemAction, VListItemContent, VListItemTitle,
},
... Is there any other solution that I might not have seen? Thanks |
Thank you @Djaler! |
No, I just used it one time with rollup |
I am using vite-plugin-components with a custom resolver for Vuetify as described in the section Importing from UI Libraries. I have a simple conditional check (in my case no other components would meet the condition except for Vuetify components) like this: ViteComponents({
customComponentResolvers: [
(name) => {
// where `name` is always CapitalCase
if (name.startsWith("V"))
return { importName: name, path: "vuetify/lib" };
},
],
}) With the above, I neither have to import Vuetify Components in my .vue files nor add them to components property. |
Hi I'm new to vite. |
I hope we are not getting off-topic here :-). My setup is similar to @lstoeferle's here, minus the TS, WindiCSS, etc. In src/main.js import Vue from 'vue'
import App from '@/App.vue'
import { createApp, h } from 'vue-demi'
import vuetify from './plugins/vuetify'
// ....
Vue.config.productionTip = false
Vue.config.devtools = true
const app = createApp({
vuetify,
render: () => h(App),
})
app.mount('#app') In src/plugins/vuetify.js import Vue from 'vue'
import Vuetify from 'vuetify/lib/framework'
Vue.use(Vuetify)
export default new Vuetify({...vuetify options if you wish}}) In a component (.vue) <v-btn depressed color="primary" @click="handleButtonClick()">
My Primary Button
</v-btn> This works. Vuetify colors and classes work. The only thing that currently doesn't work is v-icon but I suspect I am missing some configuration. However, I think I will be changing my setup to use rollup-plugin-vuetify instead since it supports both auto-importing of Vuetify components and Vuetify tree-shaking. Hope this helps. |
Thank you so much, everything works fine. 😎 |
The vite-plugin-component support Vuetify out of the box as well now.
|
Describe the bug
Trying Vite on a fresh vue 2.5 / typescript app.
Reproduction
Create a new app:
npm init vite-app vue25 --template vue
Replace
package.json
with this:System Info
vite
version: 0.18.0vue
version (fromyarn.lock
orpackage-lock.json
)@vue/compiler-sfc
versionI thought this worked with Vue 2.5 as @vue/compiler-sfc is vue 3... only.
The text was updated successfully, but these errors were encountered: