# rollup-plugin-url-resolve

> Use URLs in your Rollup imports

Latest version **0.2.0** (published 2021-06-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install rollup-plugin-url-resolve
pnpm add rollup-plugin-url-resolve
yarn add rollup-plugin-url-resolve
bun add rollup-plugin-url-resolve
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2021-06-03 |
| First published | 2019-06-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 13.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 137 |
| Author | Michael Jackson |
| Maintainers | mreinstein, mjackson |

## Links

- npm: https://www.npmjs.com/package/rollup-plugin-url-resolve
- Repository: https://github.com/mjackson/rollup-plugin-url-resolve
- Homepage: https://github.com/mjackson/rollup-plugin-url-resolve#readme
- Issues: https://github.com/mjackson/rollup-plugin-url-resolve/issues
- npm.io page: https://npm.io/package/rollup-plugin-url-resolve

## Dependencies (4)

- [mime-types](https://npm.io/package/mime-types.md) ^2.1.24
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.4.5
- [make-fetch-happen](https://npm.io/package/make-fetch-happen.md) ^9.0.2
- [data-uri-to-buffer](https://npm.io/package/data-uri-to-buffer.md) ^3.0.1

## Recent versions

- 0.2.0 (latest) — 2021-06-03
- 0.1.2 — 2021-06-03
- 0.1.1 — 2019-08-05
- 0.1.0 — 2019-06-11

## README

## rollup-plugin-url-resolve

The goal of this plugin is to avoid the need to use `npm` or `yarn` clients to explicitly install your dependencies from the registry before you bundle. Instead of specifying your dependencies in `package.json`, you specify them in your source code as [URLs](https://url.spec.whatwg.org/#absolute-url-with-fragment-string) in `import` statements. Then Rollup dynamically fetches and includes those dependencies when you bundle.

For example, you could put the following in your `rollup.config.js`:

```js
import urlResolve from 'rollup-plugin-url-resolve';

export default {
  // ...
  plugins: [urlResolve()]
};
```

Then, in your source files, you can do stuff like this:

```js
import * as d3 from 'https://unpkg.com/d3?module';
```

Run `rollup`, and you're done. No more `npm install`! :) Well, at least not for your app's dependencies.

Currently, the following URL protocols are supported:

- `https:` and `http:`
- `file:`
- `data:`

It might help to think about this plugin as an alternative to [`rollup-plugin-node-resolve`](https://www.npmjs.com/package/rollup-plugin-node-resolve), but for any URL, not just stuff you've already installed in `node_modules`.

### Options

The `urlResolve` function accepts all the same options as [`make-fetch-happen`](https://www.npmjs.com/package/make-fetch-happen). They are used when we need to `fetch` a module from a remote URL. One option that is particularly useful is `cacheManager`, which can be used to cache the results of `fetch` operations on disk. This can make your builds a lot faster if many of your URLs point to remote servers.

```js
import urlResolve from 'rollup-plugin-url-resolve';

export default {
  // ...
  plugins: [
    urlResolve({
      // Caches the results of all fetch operations
      // in a local directory named ".cache"
      cacheManager: '.cache'
    })
  ]
};
```

There are various other options as well, including support for retrying failed requests and proxy servers. Please see [the list of options](https://www.npmjs.com/package/make-fetch-happen#extra-options) for more information.

### Using CommonJS

You could also try using a URL that returns CommonJS, though you won't get the benefit of tree-shaking that using JavaScript modules provides. Still, it can be a useful stopgap until a package you need starts publishing JavaScript modules.

If you do this, you'll probably want to use [`rollup-plugin-commonjs`](https://www.npmjs.com/package/rollup-plugin-commonjs) on those URLs in your Rollup config, just like you would normally do for stuff in `node_modules`:

```js
import commonjs from 'rollup-plugin-commonjs';
import urlResolve from 'rollup-plugin-url-resolve';

export default {
  // ...
  plugins: [
    urlResolve(),
    commonjs({
      // Treat unpkg URLs as CommonJS
      include: /^https:\/\/unpkg\.com/,
      // ...except for unpkg ?module URLs
      exclude: /^https:\/\/unpkg\.com.*?\?.*?\bmodule\b/
    })
  ]
};
```

### License

[MIT](./LICENSE)

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