Skip to content

Commit ed0ead4

Browse files
authored
feat: split out localization files for optimized bundle (#1533)
Before: ```txt vite v5.3.4 building for production... ✓ 168 modules transformed. dist/webpack-stats.json 14.00 kB │ gzip: 2.39 kB dist/style.css 11.63 kB │ gzip: 2.82 kB dist/comments.js 17.39 kB │ gzip: 3.51 kB │ map: 49.43 kB dist/blocknote.js 416.35 kB │ gzip: 93.27 kB │ map: 1,103.85 kB dist/webpack-stats.json 14.01 kB │ gzip: 2.41 kB dist/style.css 11.63 kB │ gzip: 2.82 kB dist/comments.cjs 11.72 kB │ gzip: 2.85 kB │ map: 47.30 kB dist/blocknote.cjs 273.46 kB │ gzip: 72.57 kB │ map: 1,044.26 kB ✓ built in 506ms ``` After: ```txt vite v5.3.4 building for production... ✓ 170 modules transformed. dist/webpack-stats.json 14.50 kB │ gzip: 2.52 kB dist/style.css 11.63 kB │ gzip: 2.82 kB dist/en-BEb_5vQO.js 7.78 kB │ gzip: 1.91 kB │ map: 14.03 kB dist/comments.js 17.39 kB │ gzip: 3.51 kB │ map: 49.43 kB dist/locales.js 135.64 kB │ gzip: 27.15 kB │ map: 238.90 kB dist/blocknote.js 274.20 kB │ gzip: 65.23 kB │ map: 853.96 kB dist/webpack-stats.json 14.51 kB │ gzip: 2.52 kB dist/style.css 11.63 kB │ gzip: 2.82 kB dist/en-DoDAHwFo.cjs 5.34 kB │ gzip: 1.76 kB │ map: 12.34 kB dist/comments.cjs 11.72 kB │ gzip: 2.85 kB │ map: 47.30 kB dist/locales.cjs 93.50 kB │ gzip: 24.76 kB │ map: 210.56 kB dist/blocknote.cjs 175.52 kB │ gzip: 47.01 kB │ map: 823.91 kB ✓ built in 588ms ``` Shaved ~100kb from cjs & ~140kb from js
1 parent 9cd16c0 commit ed0ead4

File tree

8 files changed

+14
-9
lines changed

8 files changed

+14
-9
lines changed

docs/components/pages/landing/hero/DemoEditor.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import {
22
BlockNoteSchema,
33
combineByGroup,
44
filterSuggestionItems,
5-
locales,
65
uploadToTmpFilesDotOrg_DEV_ONLY,
76
} from "@blocknote/core";
7+
import * as locales from "@blocknote/core/locales";
88
import "@blocknote/core/fonts/inter.css";
99
import {
1010
getDefaultReactSlashMenuItems,

examples/01-basic/03-multi-column/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {
22
BlockNoteSchema,
33
combineByGroup,
44
filterSuggestionItems,
5-
locales,
65
} from "@blocknote/core";
6+
import * as locales from "@blocknote/core/locales";
77
import "@blocknote/core/fonts/inter.css";
88
import { BlockNoteView } from "@blocknote/mantine";
99
import "@blocknote/mantine/style.css";

examples/01-basic/10-localization/App.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { locales } from "@blocknote/core";
1+
import { nl } from "@blocknote/core/locales";
22
import "@blocknote/core/fonts/inter.css";
33
import { BlockNoteView } from "@blocknote/mantine";
44
import "@blocknote/mantine/style.css";
@@ -12,7 +12,7 @@ export default function App() {
1212
// Passes the Dutch (NL) dictionary to the editor instance.
1313
// You can also provide your own dictionary here to customize the strings used in the editor,
1414
// or submit a Pull Request to add support for your language of your choice
15-
dictionary: locales.nl,
15+
dictionary: nl,
1616
// dictionary: locales[lang as keyof typeof locales], // Use the language from the i18n library dynamically
1717
});
1818

examples/01-basic/11-custom-placeholder/App.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { locales } from "@blocknote/core";
1+
import { en } from "@blocknote/core/locales";
22
import "@blocknote/core/fonts/inter.css";
33
import { BlockNoteView } from "@blocknote/mantine";
44
import "@blocknote/mantine/style.css";
55
import { useCreateBlockNote } from "@blocknote/react";
66

77
export default function App() {
88
// We use the English, default dictionary
9-
const locale = locales["en"];
9+
const locale = en;
1010

1111
// Creates a new editor instance.
1212
const editor = useCreateBlockNote({

packages/core/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
"types": "./types/src/comments/index.d.ts",
5050
"import": "./dist/comments.js",
5151
"require": "./dist/comments.cjs"
52+
},
53+
"./locales": {
54+
"types": "./types/src/i18n/index.d.ts",
55+
"import": "./dist/locales.js",
56+
"require": "./dist/locales.cjs"
5257
}
5358
},
5459
"scripts": {

packages/core/src/i18n/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./locales/index.js";
2+
export * from "./dictionary.js";

packages/core/src/index.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as locales from "./i18n/locales/index.js";
21
export * from "./api/blockManipulation/commands/updateBlock/updateBlock.js";
32
export * from "./api/exporters/html/externalHTMLExporter.js";
43
export * from "./api/exporters/html/internalHTMLSerializer.js";
@@ -57,7 +56,6 @@ export * from "./util/table.js";
5756
export * from "./util/string.js";
5857
export * from "./util/typescript.js";
5958
export { UnreachableCaseError, assertEmpty } from "./util/typescript.js";
60-
export { locales };
6159

6260
// for testing from react (TODO: move):
6361
export * from "./api/nodeConversions/blockToNode.js";
@@ -69,4 +67,3 @@ export * from "./extensions/UniqueID/UniqueID.js";
6967
export * from "./api/exporters/markdown/markdownExporter.js";
7068
export * from "./api/parsers/html/parseHTML.js";
7169
export * from "./api/parsers/markdown/parseMarkdown.js";
72-

packages/core/vite.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default defineConfig({
1919
entry: {
2020
blocknote: path.resolve(__dirname, "src/index.ts"),
2121
comments: path.resolve(__dirname, "src/comments/index.ts"),
22+
locales: path.resolve(__dirname, "src/i18n/index.ts"),
2223
},
2324
name: "blocknote",
2425
formats: ["es", "cjs"],

0 commit comments

Comments
 (0)