For more than a year I am working with nuxt.js on daily basis. In this review I would try to summarize all ups and downs while working with a framework. Hopefully this article may persuade you to try nuxt on your new project and you will also be aware of some caveats along the way, which I faced.
TL;TR
- Have a year working with nuxt on daily basis.
- Nuxt is a very convenient and amazing for production.
- Nuxt is extendable and have lots of features and driven by vast and talented community
- Nuxt have caveats, which have some workaround but nothing is ideal :)
Benefits
- performant
- structure
- community
- documentation (guides for testing, guides for deploying)
- modules (i18n, sitemap, svg, apollo, axios, pwa, sentry, GA, GTM)
Caveats
- shared state problem (node problem)
- is-https and heroku (i18n multi domains, sitemap)
-
this
everywhere - weak
rx.js
support
One remark before I start, I don't know if it was an idea, but I just love how nuxt logo is mountain, like you are behind a reliable wall.
Project
First of all I want to give a small introfuction to the project. A year ago, in Oktober 2018 my friend rami alsalman (Ph.D. in machine learning!) approached me and shared the pain of using job websites nowadays, f.e. you are trying to find Software Backend Engineer php
and you get a list of offers, with python
, C#
, ASP.net
and so on.
All in all relevancy is poor sometimes because the recognition of offer description - like recognition of required programming skills, soft skills is the problem on it's own.
The idea was to build a search system only around machine learning algorythms that will recognise any job offer description text, any search text and applicant CV, so we could directly show most matching jobs based on CV.
That is how we came up with idea of clusterjobs.de. I was responsible for web application and became CTO of a startup and my friend became a CEO and machine learning search engine engineer.
Why nuxt?
First of all I wanted to start a project with a long-term framework that will help us start fast and extend it in future. Other main point was to have SSR, cause we wanted to have sustainable SEO as a main traffic channel. Having php on a backend for SSR would lead to duplicating all the templates and double work, which we couldn't afford, cause the dev team is just me :).
I started to investigate javascript SSR solutions and nuxt seemed clearly a winner. There was 2.0.0 major release and good documentation, and decided to take a risk with a new technology on a new project and take nuxt as a framework for clusterjobs.
Deployment and CD with nuxt
To save some time on manual deployments I invested couple of days to set up proper Gitlab pipeline to deploy app to heroku.
Here is a great article on nuxt docs about deploying to heroku.
Here is a great article on how to deploy vue on heroku in gitlab Pipeline.
Combine them together and BOOM! That is what I have at the moment:
A year of development
After all environment was done it took roughly 2–3 months to prepare MVP and go live. Numerous iterations and improvements afterwards and till now I did not regret at any point of time that I chose nuxt.
So why is it good? I thought of really best moments that I experienced and here they are:
Performance
It is performant, even though it is full js framework that need to deliver all library files to the client it still tries it's best to do it in less harmful way.
With last 2.10 update I found out guys have updated webpack config so during development only updated chunks are rebuild, which really speed up development. Also webpack for production is extendable and you could play around with it on your own, or use default config which is pretty performant on it's own.
My webpack build config. Here are the docs for this.
Structuring
The good advantage is that I as a developer didn't need to think where to put this or that. Nuxt comes with a skeleton of app, with everything you need to build complex web app. Pages, components, assets, static, middlewares, plugins and so on.
The only thing that pissed me off is that nuxt encourages you to use ~/component/blah-blah
kind of stuff to import all over the application.
So and JetBrains IDE, that I love with a bottom of my heart, couldn't recognise those pathes.
Workaround for that is pretty simple:
Name this file
phpstorm.webpack.config.js
(Cause it is PHPStorm and not WEBStorm in my case 😛) and put it in the root folder of your nuxt app to make ~
in you import pathes work!
Community
Community is living, huge thanks to
who created nuxt itself and driving it till current moment, huge thanks to the Core Team and all contributors for such an amazing product. Probably if you tried nuxt you know these resources, but I just put them here:- Brand new updated nuxt website with guides, docs and everything you might be interested
- Amazing platform for open source communities. All Issues, questions and so on regarding nuxt and nuxt-community modules
Modules
That is the thing that makes you love nuxt, really.
Coming from such a great community nuxt has readjusted vue modules, new modules, modules for everything. Found som not covered use-case in nuxt? Write a module, make it nuxt-community open source!
Here is a list of modules I use in production:
i18n
Internationalisation, with multi-domains for each language, working out of the box. Like isn't it awesome? Languages and separate domains is crucial for SEO and could improve your presence in Google results list heavily. And here you just need to add module, integrate it with your UI and that's it.sitemap
Also super important thing that is needed for every prod website. This module will generate sitemap based on your routes. You could also use axios th request your API and get all dynamic routes or whatever you want.svg
Use svg all over the app, but load them from auto-generated spriteapollo
GraphQL is awesome!pwa
PWA is our future, try to investigate this topic, if you still haven't done it yet! Upd. Samsung started to show PWA apps in Galaxy store!sentry
get to know your user's pain with awesome service that will log all production errors for you.
Caveats
There was some problems of course during the year of working with nuxt.
Now I ll try to give context for each of them and help you avoid them in future:
Shared state on multiple requests in nuxt
This is related to how node.js works. If you have a global variable, it will be overwritten in simultaneous request.
Some insights are given in this Stack Overflow question.
The problem that I experienced was related to fetch function on my offer-list page (search results).
I was making action call like
Making search on server sideThat was done to populate store on server side and use the same offers on client side.
But when it is done inside action, like action -> commit -> store
then for some reason that data is mixed.
I confess, I did not investigate the true reason of that, maybe some global object of Vuex store or something like that, but the problem was that
while I had my application running for first request, every next request got it's state. So you might end up landing here https://en.clusterjobs.de/search/fullstack developer and having machine learning engineer results.
Fix for that was:
Committing directly from fetch function.
So action -> back to fetch -> commit -> state
. Action should return a Promise wich is resolved with proper data, which you could use back in fetch
function.
Probably after that point commit calls where close to the end of fetch and page had correct data, but general problem might be still here.
Heroku and is-https
I am hosting app using cloudflare
for DNS and heroku
as a server. Pointing domain to heroku is done through CNAME
. Which is giving me some problems.
Several modules of nuxt (sitemap, i18n) are using is-https library to identify on server side the type of request.
The request which is done to cloudlfare is https, but probably that proxying is not.
I got some advices in CMTY on that.
Enabling x-forwarded-proto should help, but I didn't try it so far
this
everywhere
Personally I like to write functional code in js. It is possible with nuxt but all the modules makes you use this.
Want to get current locale in vuex store or in component? this.app.i18n.locale
THe same for switching locale and getting all locales list.
Wnat to change page in Vuex?
this.router.push
I can live with that, but having those objects as an arguments inside functions also could benefit for better code separation.
Rx.js
I love RX and love to apply it to especially state managing use cases.
RX could be integrated to vue js and to nuxt as well, if we are talking about DOM events. There is this package:
https://github.com/vuejs/vue-rx
To integrate it to nuxt, just create a plugin like this:
Put this file into plugins folder and add the plugin in nuxt.config.js
. There were also couple of trials to integrate it into vuex, but so far repo is deprecated, and I haven't seen any articles regarding this in the late time.
Summarize
All in all I love nuxt, I even prepared a workshop for my fellow colleagues and did it couple of times to spread the knowledge and encourage them to try it.
I think it is a very mature and developed tool for any need. You could use it for everything starting from simple static landing, personal website, up to complex web application and ecommerce platform.
I faced some caveats, which are feasible to fix, but also I had a lot of great moments, when everything so simple and works so awesome.
I truly believe in that framework and deeply grateful to people that created it and are maintainig it till this very moment.
Thank you, nuxt, nuxt :P
Top comments (9)
I was not able to ge sourcemapping working. All dources inder webpack in devtools are precompiled. I am not seeing there original vue files with vue templates like I see on app that I have builtbby vite+vue.
Does nuxt allow that at all?
Undoubtedly a great tool for those of us who are entrepreneurs and do not have a great team.
I love nuxt.
Thank you for this article Mikhail :)
Really happy that you enjoyed using Nuxt!
Was a pleasure investigating and working with Nuxt, thanks for a great tool and great community :)
Hi, Mikhail, would like to check with you, in your project, what frontend design framework you were using in Nuxt.js? Is it BootstrapVue or Vuetify or other? Which one would you recommend and why?
Actually design was done by friend of mine, styles were written by me :)
Possible to help forward my question to your friend? I appreciate your kindness and prompt response.
Initially, it was based on material design by google, something like this material.io/
Do you have any advice on using node as http server in production?
I confuse if I should use Nuxt as SPA then serve it with Nginx or should use Nuxt as SSR then serve it with Node.