universal-vue / uvue

Vue CLI plugin to create universal Vue applications with ease
https://universal-vue.github.io/docs/
MIT License
127 stars 13 forks source link

Now V2 / Lambda deployment #6

Closed dohomi closed 5 years ago

dohomi commented 5 years ago

Hi @chymz I'm currently playing around with the new version of now which basically wraps application code through builder to run serverless functions. Is it possible to run a server of the pre-builded sources similar like the functional approach starting NuxtJS programatically? I found this very basic example: https://github.com/zeit/now-examples/tree/master/vue-ssr It would be great to add an example of using uvue on the now infrastructure Cheers

yabab-dev commented 5 years ago

It's on my roadmap, I need to dig a bit more on Now v2 ;)

dohomi commented 5 years ago

That would be great! Now v2 is giving be big headaches at the moment. None of my Nuxt projects were able to convert from v1 => v2 yet

yabab-dev commented 5 years ago

I've tested a bit, it will be hard :smile:

First attempt was to use @now/node builder: the tool ncc used to package source code and make it ready to lambda function seems not working with esm package used in UVue.

Second attempt with @now/node-server: it seems better but lambda size limit is 50mb and my package have 52mb of files...

yabab-dev commented 5 years ago

Finally got it working!

What I've done:

  1. Switched from yarn to npm (yarn seems buggy with now)
  2. Moved 2 cypress devDependencies to peerDependencies to have a faster build
  3. Created Now needed files
  4. Made a shell script to build app and remove devDependencies from node_modules

Now my package is 22mb of files, and :tada:

https://uvue-examples-1o0lbwihq.now.sh/

Full commit here: https://github.com/universal-vue/examples/commit/f8deae00767ac77b7b703f078d2ab377a0f2fcef

dohomi commented 5 years ago

cool beans @chymz 👍
the ncc project of zeit seems really cool for creating lambda bundles, haven't checked it yet.

yabab-dev commented 5 years ago

Added in docs: https://universal-vue.github.io/docs/guide/deploy.html#now-v2

dohomi commented 5 years ago

@chymz cool thanks for doing that. I haven't got much time to try this package yet, but what I am doing with NuxtJS is following:

  1. deploy the /.nuxt/dist/clientstatically under a different subdomain as static files (as CDN)
  2. update build.publicPath inside nuxt.config.js to point to public files CDN domain of 1.)
  3. deploy the server as npm project into now

That gave me very nice results for Pagespeed and Lighthouse Not sure if thats possible with this package but I'm sure you can archive the same with the different bundler section for the public client side files after building the project. Cheers and keep up the great work