Skip to content

Instantly share code, notes, and snippets.

@segphault
Created January 11, 2018 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save segphault/c084faf4b6dfbeb3ba7d4b7158d17213 to your computer and use it in GitHub Desktop.
Save segphault/c084faf4b6dfbeb3ba7d4b7158d17213 to your computer and use it in GitHub Desktop.
Bundling remote dependencies with rollup
const http = require("http");
const https = require("https");
const isRemote = path =>
path.startsWith("http://") || path.startsWith("https://");
const protocol = url =>
url.startsWith("https://") ? https : http;
const fetch = url =>
new Promise((resolve, reject) =>
protocol(url).get(url, response => {
let output = "";
response.on("data", chunk => output += chunk);
response.on("end", () => resolve(output));
}).on("error", err => reject(err)));
const resolveURL = {
name: "URL Resolver",
resolveId(importee) {
if (isRemote(importee))
return importee;
},
load(id) {
if (isRemote(id))
return fetch(id);
}
};
export default {
entry: "plugins/dashboard/public/index.js",
dest: "plugins/dashboard/public/bundle.js",
format: "es",
plugins: [resolveURL]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment