Nuxt.js: perf/size: smaller nuxt-start size

Created on 21 Nov 2018  Â·  11Comments  Â·  Source: nuxt/nuxt.js

What problem does this feature solve?

Cold starts on serverless platforms like Now 2.0 would be more efficient.

What does the proposed changes look like?

When I have a package.json file that looks like this (working example)

dependencies: {
  "nuxt": "^2.3.2"
}

Run with nuxt-start

npm ci —production

nu -sch ./node_modules: > 100mb

When I have a package.json file that looks like this (working example)

"dependencies": {
  "@nuxt/core": "^2.3.2",
  "core-js": "^2.5.7"
},
devDependencies: {
  "nuxt": "^2.3.2"
}

and programatically run with nuxt.render

npm ci
npm run build
npm ci —production
nu -sch ./node_modules is 26mb

Which is still pretty big.

(this installation pattern was taken from @now/next)

I noticed the nuxt-start package, but it doesn’t work unless nuxt is installed as well, which brings us back to where we started at > 100mb.

In comparison react, react-dom, next-server@canary has a 2.8mb 12mb node_modules footprint

next-server is used in the @next/builder.

Conclusion

There should be an npm module similar to next-server, but for nuxt. This would make it easier to make a nuxt-builder for Now 2.0

This feature request is available on Nuxt community (#c8183)
feature-request

Most helpful comment

@rlindskog core-js shouldnt be needed. its a bug in babel that should be fixed in next release of preset-env https://github.com/babel/babel/pull/9048 and it should appear only in node 10+. You use node 10 or 11 right?
As for size. Its 16mb with core js. Less than 11mb without core-js. And yes, its logical filesize. Here my node modules archive so you can compare ( with core-js). https://www.dropbox.com/s/4t09a5u0pz2rbn8/node_modules_nuxt-start.zip?dl=0
here gist https://gist.github.com/pi0/dcf528794d29fa455c9ca745fb85fe04

All 11 comments

I noticed the nuxt-start package, but it doesn’t work unless nuxt is installed as well, which brings us back to where we started at > 100mb.

That shouldnt happen. It work without nuxt and im using it for aws lambda serverless.
Maybe u just encountered a this bug in it https://github.com/nuxt/nuxt.js/pull/4384

@aldarund I was able to get nuxt-start working with the recent updates, but also had to run npm install --production core-js (+7mb) to get it to work. Even with nuxt-start, the node_modules output is still 26mb (it's basically the same as the @nuxt/core implementation), which seems relatively large compared to what it could be.

@rlindskog its not 26mb even with core-js. Its 15,7 MB (16 561 152 bytes) Other is your deps.

If you calculate it with du -sh ./node_modules (finds the logical filesize), it will be 26mb with _just_ nuxt-start and core-js as dependencies.

Anyway, I found that next-server should've been installed as next-server@canary, which brings up the NextJS production node_modules up to 12mb (just react, react-dom, next-server@canary dependencies).

That's 26mb for Nuxt (19mb without core-js) and 12mb for Next.

@rlindskog core-js shouldnt be needed. its a bug in babel that should be fixed in next release of preset-env https://github.com/babel/babel/pull/9048 and it should appear only in node 10+. You use node 10 or 11 right?
As for size. Its 16mb with core js. Less than 11mb without core-js. And yes, its logical filesize. Here my node modules archive so you can compare ( with core-js). https://www.dropbox.com/s/4t09a5u0pz2rbn8/node_modules_nuxt-start.zip?dl=0
here gist https://gist.github.com/pi0/dcf528794d29fa455c9ca745fb85fe04

@aldarund Good work! I think lodash is still being installed in @nuxtjs/core because of [email protected] @nuxtjs/opencollective

After npm install in nuxt/packages/core

nuxt.js/packages/core$ npm ls lodash
@nuxt.js/packages/core
└─┬ @nuxtjs/[email protected]
  └─┬ [email protected]
    └── [email protected]

It looks like consola, has been already updated in @nuxtjs/opencollective to 2.0.7, which doesn't contain lodash. Maybe @nuxtjs/opencollective just needs a release?

@rlindskog Good catch!

Current nuxt-start-edge size: current nuxt-start-edge size

It is now install size after #4439. More optimizations on the way.

Closing as most "issues" and questions are solved.

Current size: install size

Thanks for the heads up! 👍

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

uptownhr picture uptownhr  Â·  3Comments

msudgh picture msudgh  Â·  3Comments

maicong picture maicong  Â·  3Comments

vadimsg picture vadimsg  Â·  3Comments

shyamchandranmec picture shyamchandranmec  Â·  3Comments