0.0.1 • Published 2 years ago

vite-plugin-cache-resource v0.0.1

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

vite-plugin-cache-resource

cache request contents to local files

usage

install

pnpm add vite-plugin-cache-resource -D

config

add cacheResource to vite config

import { cacheResource } from "vite-plugin-cache-resource";

export default defineConfig({
  plugins: [
    cacheResource(),
  ],
});

options

  • cacheDir: where the files are saved to
    • default: ${process.cwd()}/tmp
import path from "path/posix";
import { defineConfig } from "vite";
import { cacheResource } from "vite-plugin-cache-resource";

export default defineConfig({
  plugins: [
    cacheResource({
      cacheDir: path.join(__dirname, ".cache"),
    }),
  ],
});

text content

import example from "cache:https://example.com";

expect(
  parse(example).querySelector("title").textContent
).toMatchInlineSnapshot('"Example Domain"');

json

import todo from "cache+json:https://jsonplaceholder.typicode.com/todos/1";

expect(todo["title"]).toMatchInlineSnapshot('"delectus aut autem"');