-
-
Notifications
You must be signed in to change notification settings - Fork 462
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
Option to reduce bundle size by removing some languages from "Code Block" feature? #1213
Comments
Unfortunately #1216 doesn't solve this, but only makes sure the languages are not part of the @blocknote/core bundle. Your application would still have the language files in the output. Note that for the end-user, this should not be an issue as languages are loaded dynamically However, I understand you might still want to reduce your deployment output. To do this, seems like there are two options: |
Yes I noticed that the lang is loaded dynamically.
Exactly, these assets are significant in terms of size. Our deployment infrastructure charged us to a higher-tier usage plan based on upload size. We could have saved budget if we can reduce this dependencies. Thanks for taking a look at this, though 👍 . I will consider the options. |
@sindras If you're using a Rollup-based bundler (e.g. Vite), you can specify the languages to exclude as external: ...
rollupOptions: {
external: (source) => {
// Exclude JavaScript
if(source.includes("shiki/dist/langs/javascript")) {
return true;
}
return false;
}
}
... Alternatively you should be able to externalize all You'll also have to use Before you use this method though, wait for #1219 to be merged, as it fixes a separate issue that was duplicating the languages in the output bundle (potentially breaking the method above). |
That's super helpful, thank you @areknawo ! I will keep an eye on the next release 👍 Just curious, is this the right way to customize the CodeBlock? I am having a TS error because the default language values are coming as Perhaps the CodeBlockOptions supportedLanguages should be of type import {
BlockNoteSchema,
defaultBlockSpecs,
customizeCodeBlock,
defaultCodeBlockPropSchema,
} from '@blocknote/core';
const schema = BlockNoteSchema.create({
blockSpecs: {
...defaultBlockSpecs,
codeBlock: customizeCodeBlock({
defaultLanguage: 'javascript',
indentLineWithTab: true,
// This currently gives TS error
supportedLanguages: defaultCodeBlockPropSchema.language.values.filter(id => ['javascript', 'html'].includes(id)),
}),
},
});
function MyEditor() {
const editor = useCreateBlockNote({schema});
// ... return <BlockNoteView {...} />
} |
Another question, do we support switching themes of the CodeBlock? If not, we probably should exclude them from build as well |
@sindras My idea behind Here's how you would configure the CodeBlock: customizeCodeBlock({
defaultLanguage: "javascript",
supportedLanguages: [
{
id: "javascript",
match: ["javascript", "js"],
name: "JavaScript",
},
],
}); That said, I see how accepting a list of IDs could make things easier. Perhaps it'd be best to support an array of As for the syntax highlighting themes - we could support them or exclude unused themes by default. That said, per earlier comment, the latter option wouldn't change much for you as the end-user of the package and you will likely still need to externalize them in your bundler. @YousefED Let me know if you have any feedback |
That makes sense, either with Thank you for your support to provide code block in this editor! This is a big, cool feature that convinces me to use BlockNote 😄 |
Is your feature request related to a problem? Please describe.
Follow-up from #1177, is there a way to reduce bundle size by opting out from some languages?
Even though the languages have been filtered out as per discussion in the PR, they are still bundled in the production assets.
Screenshot attached below.
Also there does not seem to be any documentation about configuring the code block in the docs website.
Describe the solution you'd like
Additional context
This is generated by running
npm run build
with Remix framework.Bonus
I am willing to help if someone can point me in the right direction regarding the tree-shaking.
Thank you so much for creating BlockNote! ❤️
The text was updated successfully, but these errors were encountered: