-
-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Shiki] no CDN provider found #216
Comments
Can you say what you did about the error message? |
@orta Can we load all resources manually? I don't want to provide static resource path but bundled by vite/webpack. |
When using vite/webpack, there is a hint of |
cc @octref |
Please provide a minimal, reproducible example. Link to a repo would be great. |
@jiankafei Your example is showing this for error me: |
+1 for this, CDN feature should be optional in my opinion. especially for desktop apps created with electron, it's not feasible to connect CDN everytime. for now using setCDN("/node_modules/shiki/"); with vite worked for me, since vite serves the root directory. but this is temporary and will only work with vite-like bundlers AND in dev mode. in prod you will manually (somehow) have to copy shiki/dist to your dist. |
Agree with @Sparkenstein. For now, as is written in this file, we can load assets by |
|
If you are using vite, you can serve shiki assets with https://github.com/sapphi-red/vite-plugin-static-copy to make them both available in dev mode and production. // vite.config.*
import { viteStaticCopy } from 'vite-plugin-static-copy'
export default {
plugins: [
viteStaticCopy({
targets: [
{
src: 'node_modules/shiki',
dest: '.'
}
]
})
]
} Set CDN to the assets served by yourself before get the setCDN('/shiki/') |
I am still having an issue with the following setup: import * as shiki from "shiki";
shiki.setCDN("https://unpkg.com/shiki/");
const highlighter = await shiki.getHighlighter({ theme: "nord" }); // <-- This line is causing the error
const shikiOptions = { lang: "js" };
document.addEventListener("DOMContentLoaded", async event => {
const $codeBlocks = document.querySelectorAll(".code");
for (const $codeBlock of $codeBlocks) {
const content = "console.log('shiki');"; // Test
const renderedHtml = highlighter.codeToHtml(content, shikiOptions);
$codeBlock.innerHTML = renderedHtml;
}
}) The error: Has anyone got shiki running client-side? |
Thank you @kingyue737 for the hint. It works by setting both import { getHighlighter, setCDN, setWasm } from "shiki";
document.addEventListener("DOMContentLoaded", async event => {
// setWasm(new Response(await fetch("https://unpkg.com/shiki/dist/onig.wasm"))); // <- Didn't work although this is recommended per README
const responseWasm = await fetch("https://unpkg.com/shiki/dist/onig.wasm");
const wasmArrayBuffer = await responseWasm.arrayBuffer();
setWasm(wasmArrayBuffer);
setCDN("https://unpkg.com/shiki/");
const highlighter = await getHighlighter({ theme: "nord", langs: ["js", "php", "python"] });
// container.innerHTML = highlighter.codeToHtml(someCode, {lang: "js"})
}) |
FWIW, if you want to use the prebuild packages from And thanks for the pointer with the |
code
result
The text was updated successfully, but these errors were encountered: