2.2.2 • Published 3 years ago

nuxt-remote-asset-cache v2.2.2

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

nuxt-remote-asset-cache

This stores remote assets, like images, that are referenced in the asyncData of a Nuxt page in some local directory that isn't destroyed between successive generate calls. This was written, in particular, for Netlify and it's NETLIFY_CACHE_DIR.

Example

nuxt.config.js

{
  modules: [
    	'nuxt-remote-asset-cache',
  ]
  
  /**
   * This would download anything in the data returned from asyncData with a
   * URL like http://cms.hostname.com/images/file.jpg to the directory path
   * from $NETLIFY_CACHE_DIR.  In addition, they will be published on every
   * generate into /dist/images/file.jpg (for example)
   */
  remoteAssetCache: {
    cacheDir: process.env.NETLIFY_CACHE_DIR,
    assetRegex: [
      {
        pattern: /https?:\/\/cms\.hostname\.com\/images\/([\w\d-.\/]+)/gi,
        replacement: {
          storagePath: "/images/$1",
          publicUrl: "#{process.env.URL}/images/$1",
          autoLowercase: true,
        }
      }
    ]
  }
}

pages/home.vue

<script>
export default {
  asyncData ({$cacheAssets}) {
    // Fetch some data from somewhere
    const data = { marquee: { 
      headline: 'Hi',
      background: 'http://cms.hostname.com/images/file.jpg'
    }}
    return $cacheAssets(data)
  }
}
</script>
2.2.1

3 years ago

2.2.2

3 years ago

2.2.0

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago