npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nuxt-payload-extractor

v1.1.1

Published

Nuxt.js module that makes `nuxt generate` command to store html and payload separately.

Downloads

97

Readme

Nuxt payload extractor

Nuxt.js module that makes nuxt generate command to store data payload in dist dir implementing full static generation. See it in action on my site: DreaMinder.pro

⚠️⚠️⚠️ This feature called "full static generated mode" has been released as a native Nuxt.js feature recently. You might want to try it out before using this module, it is much more powerful. ⚠️⚠️⚠️

Benefits

✓ If you use external API to fill your project with data, even after your site has been prerendered, you need to keep your API running to make client-side navigation possible. With this module your API data stores along with prerendered HTML, so the issue is solved

✓ Increases page download speed for crawlers

✓ Makes HTML source code look cleaner

✓ Decreases load on API server

✓ Makes prerendered and client rendered pages consistent in case API data changed after you deployed prerendered pages

✓ Decreases initial page download time x1.5-2 (which is actually doesn't affect perfomance)

Setup

  • Add nuxt-payload-extractor dependency
  • Define nuxt module:
{
  modules: [
   'nuxt-payload-extractor'
  ]
}
  • Add asyncData custom logic with $payloadURL helper
async asyncData({ $axios, $payloadURL, route }){
  //if generated and works as client navigation, fetch previously saved static JSON payload
  if(process.static && process.client && $payloadURL)
    return await $axios.$get($payloadURL(route))

  //your request logic
  let post = await $axios.$get(`/post.json`)
  return {
    post
  }
}
  • Run npm run generate

GraphQL usage

You'll need axios in your production bundle, your graphQL client is only invoked server-side, on 'generate' command.

async asyncData({ $axios, $payloadURL, route, app }) {
  if (process.static && process.client && $payloadURL) {
    return await $axios.$get($payloadURL(route))
  } else {
    let gqlData = await app.apolloProvider.defaultClient.query({
      query: gqlquery
    })
    return {
      gqlData
    }
  }
}

Options

You can blacklist specific paths using blacklist: [] options. They will be generated in native way. But you have to disable payload request inside of asyncData yourself. Check out example dir for details.

All payloads have timestamp applied to their names for better cache invalidation. You can turn them off by using versioning: false option. Keep in mind that timestamp changes on every generate run. Also, nuxt generate --no-build is not supported in this case.

Caveats

  • Are you using nested routes (with <nuxt-child />)? This case isn't compatible with nuxt-payload-extractor. It will only work if parent and child routes return different data-keys (ex. return { postsList } and return { singlePost }).
  • Are you filling your vuex store with page-specific data? It will break on client-side navigation. Use NuxtServerInit action for global vuex data or return your vuex data from asyncData to make it work.

How it works

  • Extracts <script>window.__NUXT__= ... </script> replacing it with <script src="payload.js">
  • Makes two files along with index.html of a prerendered page: payload.js for initial page load and payload.json for client-side navigation