- 
 
- 
  Notifications
 You must be signed in to change notification settings 
- Fork 56
#118 Switch to Vite #121
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
#118 Switch to Vite #121
Conversation
Thanks @thinkverse! Bit short on time now but will give this a go soon.
I can't get the CSS to render. I keep on running into this with every project I migrate to Vite. Do you know what I need to do here?
I can't get the CSS to render
I've never had issues running npm run dev or npm run build and loading Vite assets with Valet or artisan serve. Are you using Sail or Docker? Could be that the port for Vite's dev server isn't open if it runs dev? 🤔
Just artisan serve.
I just run the npm scripts in another terminal, I never had issues with that before. Is it a CORS issue, or does the browser block assets from different origins?
How I run Paste with artisan serve 1 .
Footnotes
@driesvints Looking at it again though, it seems the @vite directive isn't being interpreted by the Blade compiler since it prints out @vite([...]). Did you run composer install to install the updated dependencies?
I'm sure I updated both Composer files to require a version of Laravel where the Vite directive exists.
Yeah, I updated composer.json to use "laravel/framework": "^9.19", which is where the Vite directive was added1 . And composer.lock was updated using composer update --lock and that locked Laravel to the compatible version v9.27.0. 🤔
Footnotes
It suddenly works for me 🤷♂️
Anyway, very much appreciated @thinkverse, thank you!
I now have issues deploying this... can't figure out what's wrong...
> @ build /home/forge/paste.laravel.io/releases/20220908071709
> vite build
sh: 1: vite: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! @ build: `vite build`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the @ build 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! /home/forge/.npm/_logs/2022-09-08T07_17_32_919Z-debug.log
Seems like vite itself was missing as a dependency. No idea how I ever got it to build locally 😅
How the heck did I miss that? 🤦♂️ I don't have Vite installed globally so I wonder how I also got it to build locally. That's a new one. 😂 Good catch. 👍
You know what. I've cracked it, laravel-vite-plugin has Vite as a development dependency so it'll be installed locally, but if you install for production those won't be installed, and since I forgot to add Vite as a dependency it was missing on the server and not locally. 🙂
Thanks for checking that 👍
This PR switches over from Laravel Mix to Vite. This PR also removes unused dependencies like
lodashandaxiosto keep the bundle size down, due to loading all ofhighlight.jsthe bundle size is ~1000 KB, with gzip compression it's ~290 KB. Similar to the size Webpack produces, but slightly larger initial size. With the unused dependencies bundled I saw a build size of ~1025 KB and ~310 KB with gzip.Solved the issue I mentioned about line numbers in #118 by moving the
hljsimport to thebootstrap.jsfile and then importing that intoapp.js, which fixes the issue of the line numbers plugin not findinghljson the window object.Looking forward to the review. 👍
Closes #118