# vite-plugin-cache-resource

> vite plugin for caching request contents to local files

Latest version **0.0.1** (published 2022-02-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install vite-plugin-cache-resource
pnpm add vite-plugin-cache-resource
yarn add vite-plugin-cache-resource
bun add vite-plugin-cache-resource
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2022-02-23 |
| First published | 2022-02-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 10.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | yue |
| Maintainers | __yue__ |

## Links

- npm: https://www.npmjs.com/package/vite-plugin-cache-resource
- Repository: https://github.com/rainy-me/vite-plugin-cache-resource
- Homepage: https://github.com/rainy-me/vite-plugin-cache-resource#readme
- Issues: https://github.com/rainy-me/vite-plugin-cache-resource/issues
- npm.io page: https://npm.io/package/vite-plugin-cache-resource

## Dependencies (3)

- [fs-extra](https://npm.io/package/fs-extra.md) ^10.0.1
- [node-fetch](https://npm.io/package/node-fetch.md) 2
- [sanitize-filename](https://npm.io/package/sanitize-filename.md) ^1.6.3

## Recent versions

- 0.0.1 (latest) — 2022-02-23

## README

# 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

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

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

```

### options

- `cacheDir`: where the files are saved to
  -  default: `${process.cwd()}/tmp`

```ts
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

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

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


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

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

---
_Source: https://npm.io/package/vite-plugin-cache-resource · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
