https://github.com/dalcib/esbuild-plugin-cache
https://github.com/dalcib/esbuild-plugin-cache
Last synced: 15 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/dalcib/esbuild-plugin-cache
- Owner: dalcib
- License: mit
- Created: 2020-12-06T10:28:18.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-11-23T20:50:16.000Z (over 2 years ago)
- Last Synced: 2025-04-23T09:02:56.187Z (15 days ago)
- Language: JavaScript
- Homepage:
- Size: 107 KB
- Stars: 45
- Watchers: 1
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-esbuild - esbuild-plugin-cache
README
# esbuild-plugin-cache
### Esbuid plugin to cache http/https imports.
The plugin allows to use http/https imports without installing npm packages on node_modules.
It also allows to use [import-maps](https://github.com/WICG/import-maps) .
It can provide a feature similar to Snowpack 3.0, the new [Streaming NPM Imports](https://www.snowpack.dev/posts/2020-12-03-snowpack-3-release-candidate), which allows to skip the NPM install and node_modules.
```javascript
//index.js
import React from 'https://cdn.skypack.dev/[email protected]'
console.log(React.version)
```#### Build script:
```javascript
//build.js
import esbuild from 'esbuild'
import { cache } from 'esbuild-plugin-cache'esbuild
.build({
entryPoints: ['index.js'],
bundle: true,
outfile: 'bundle.js',
plugins: [cache()],
})
.catch(() => process.exit(1))
```#### Config:
`config: {importmap: {imports:{[key: string]: string}}, directory: string}`
- `importmap`: Import-map object. Default: `{}`
- `directory`: Path or name for the directory of the cache. Default to Deno cache directory. Optionally the cache directory can be defined with DENO_DIR env variable: `process.env.DENO_DIR = 'cache'`.
#### Using with `importmap`
```javascript
//index.js
import React from 'react'
console.log(React.version)
``````javascript
//build.js
import esbuild from 'esbuild'
import { cache } from 'esbuild-plugin-cache'const importmap = {
imports: {
react: 'https://cdn.skypack.dev/[email protected]',
},
}esbuild
.build({
entryPoints: ['index.js'],
bundle: true,
outfile: 'bundle.js',
plugins: [cache({ importmap, directory: './cache' })],
})
.catch(() => process.exit(1))
```