Can you share your actual webpack.mix.js and resources/js/app.js files?
Installing Vue through Laravel Mix is hard
Well it's not as how it is written in the documentation or perhaps im not fully understanding it. Created a fresh project and did everything that said and I get errors. This is what the documentation says:
- Ensure NodeJs and NPM are both installed on your machine. While being at the user root level on my machine, (not in the projects folder) I ran
npm -vandnode -vand both of them were installed. Good. - Then on the project folder level, run
npm installthis installs all npm dependencies, since I want Vue, and it is a Javascript front-end framework, it needs to have these, it's like what it runs on, like Laravel needs Composer.
Besides installing Vue I also want TailwindCSS, that gave me no problem, at the end the Laravel Mix app built the application.
For installing Tailwind, as per the documentation: https://laravel.com/docs/8.x/mix#tailwindcss
After that was done, and given the information on the documentation I continued reading down and https://laravel.com/docs/8.x/mix#working-with-scripts now we get to the part for Vue and other frameworks.
- You need to add
.vue()inside a file namedwebpack.mix.jsbelow this line: mix.js('resources/js/app.js', 'public/js'), done! - Apparently that's all one needs regarding the documentation, again I wanted to base my installation solely on what it's written in there, I believe it's the best approach.
-
npm run devthrew a bunch of errors, one line in particular stood out:We couldn't find a supported version of Vue in your project. Please ensure that it's installed (npm install vue).
Ok, so I need to install vue through npm. Ran it, but again I encounter some other issues. Conclusion; not only am I not getting Vue but also there seemed to be a problem with Valet. Perhaps my knowledge of how my dev environment needs to be set is wrong, I mean should my dev environment be in a certain way? It was clear enough that I only needed Node and NPM before actually trying to do anything with Mix. Sometimes I don't get these CLI procedures, could somebody please tell me what's wrong here?
Nevertheless there is yet another method which im familiar with for getting Vue, and that is through composer require laravel/ui and php artisan ui vue but I don't want any extra files, I wish to make my UI layouts and components using TailwindCSS or CSS. Thanks! I need to know how to get Vue so I can be familiar with a process that actually works it is why im making this loong post, but I never expected I would be mislead. Again, thank you for your patience! :-)
A couple of things to consider then, and it's still a mystery as to why it wouldn't be in the docs but like I said it could be just me that im not aware of other things, it also may be that previous work with Vue is required, who knows.
Where I felt like I was misleaded, regarding the documentation instructions was that after doing everything up to this point: https://laravel.com/docs/8.x/mix#vue, you still need to install Vue through NPM: (https://vuejs.org/v2/guide/installation.html#NPM) and after that, you can certainly start using Vue.
app.js
import Vue from 'vue';
window.Vue = require('vue');
new Vue({
el: '#app',
});
Please or to participate in this conversation.