代码拉取完成,页面将自动刷新
npm install @masx200/rollup-plugin-http-resolve --save
缓存默认为内存缓存, 添加了文件系统缓存的功能,可以按需使用
import { fileCache, httpResolve } from "@masx200/rollup-plugin-http-resolve";
httpResolve({ cache: new fileCache() });
// rollup.config.js
import { httpResolve } from "@masx200/rollup-plugin-http-resolve";
export default {
input: "index.js",
plugins: [
httpResolve({
cache,
}),
],
};
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;
Rewrite https://
code by your self.
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,
};
}
},
},
],
});
MIT
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。