open-index/open-npm huggingface dataset:
npm package: @plaidev/rollup-plugin-http-resolve
Description: ## 💿 Installation
Author: Plaid Inc.
Latest version: 0.2.1

# @plaidev/rollup-plugin-http-resolve

## 💿 Installation

```sh
npm install rollup-plugin-http-resolve --save
```

## 🛠️ Configuration

```ts
// rollup.config.js

import { httpResolve } from "@plaidev/rollup-plugin-http-resolve";
import alias from "@rollup/plugin-alias";
import { resolve } from "node:path";
import { fileURLToPath } from "node:url";

const __dirname = fileURLToPath(new URL(".", import.meta.url));

export default {
  input: "index.js",
  plugins: [
    alias({
      entries: [
        /**
         * NOTE:
         *  You have to resolve 'path' like 'path-browserify'
         */
        {
          find: 'path'
          replacement: resolve(__dirname, "./node_modules/path-browserify/index.js"),
        },
        // something alias ...
      ],
    }),
    /**
     * Setup '@plaidev/rollup-plugin-http-resolve' plugin
     */
    httpResolve({
      // something options ...
    }),
  ],
};
```

## 🍭 Examples

### CDN Resolve

```ts
const vol = Volume.fromJSON({
  '/index.js': `
    import {h} from "preact";
    console.log(h);
    `,
});

const memfs = createFs(vol) as IPromisesAPI;
const rolled = await rollup({
  input: '/index.js',
  plugins: [
    httpResolve({
      fallback(id) {
        // Avoid local relative path
        if (!id.startsWith('.')) {
          return `https://esm.sh/${id}`;
        }
      },
    }),
    memfsPlugin(memfs),
  ],
});
const out = await rolled.generate({ format: 'es' });
const code = out.output[0].code;
```

### With transform import

Rewrite `https://` code by your self.

```js
import ts from "typescript";

export default {
  plugins: [
    httpResolve(),
    {
      name: "transform-cdn",
      transform(code, id) {
        if (id?.startsWith("https://")) {
          const out = ts.transpileModule(code, {
            compilerOptions: {
              module: ts.ModuleKind.ESNext,
              target: ts.ScriptTarget.ES5,
            },
          });
          return {
            code: out.outputText,
            map: out.sourceMapText,
          };
        }
      },
    },
  ],
});
```

## ✨ Credits

- [mizchi](https://github.com/mizchi) for his work on [uniroll](https://github.com/mizchi/uniroll), this rollup plugin is fokred from the project.

## ©️ LICENSE

[Apache License 2.0](./LICENSE)