Skip to content

Commit cb0e385

Browse files
committed
chore: try full bundle
1 parent 87f6911 commit cb0e385

File tree

6 files changed

+140
-6
lines changed

6 files changed

+140
-6
lines changed

docs/guide/getting-started.md

+8
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ const App = () => {
6868
};
6969
```
7070

71+
## Import full bundle
72+
73+
- There are error when install by yarn, you can import full bundle by using `bundle/full` path
74+
75+
```tsx
76+
import RichTextEditor from 'reactjs-tiptap-editor/bundle/full'
77+
```
78+
7179
## Props
7280

7381
```ts

package.json

+15-5
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,30 @@
22
"name": "reactjs-tiptap-editor",
33
"type": "module",
44
"version": "0.1.11",
5-
"main": "./lib/reactjs-tiptap-editor.cjs",
6-
"module": "./lib/reactjs-tiptap-editor.js",
5+
"main": "./lib/index.cjs",
6+
"module": "./lib/index.js",
77
"types": "./lib/index.d.ts",
88
"description": "A modern WYSIWYG rich text editor based on tiptap and shadcn ui for React",
99
"packageManager": "[email protected]",
1010
"exports": {
1111
".": {
1212
"import": {
1313
"types": "./lib/index.d.ts",
14-
"default": "./lib/reactjs-tiptap-editor.js"
14+
"default": "./lib/index.js"
1515
},
1616
"require": {
1717
"types": "./lib/index.d.cts",
18-
"default": "./lib/reactjs-tiptap-editor.cjs"
18+
"default": "./lib/index.cjs"
19+
}
20+
},
21+
"./bundle/full": {
22+
"import": {
23+
"types": "./lib/index.d.ts",
24+
"default": "./lib/bundle-full.js"
25+
},
26+
"require": {
27+
"types": "./lib/index.d.cts",
28+
"default": "./lib/bundle-full.cjs"
1929
}
2030
},
2131
"./style.css": {
@@ -35,7 +45,7 @@
3545
"node": ">=18.0.0"
3646
},
3747
"scripts": {
38-
"build:lib": "vite build && pnpm modify-css",
48+
"build:lib": "esno ./scripts/build.ts && pnpm modify-css",
3949
"build:lib:dev": "vite build --mode development --watch",
4050
"build:playground": "pnpm build:lib && pnpm --dir ./playground run build",
4151
"docs:dev": "pnpm --parallel --filter docs... dev",

scripts/build.ts

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import * as path from 'node:path'
2+
import fs from 'node:fs'
3+
import { cwd } from 'node:process'
4+
import { build } from 'vite'
5+
6+
import react from '@vitejs/plugin-react'
7+
import dts from 'vite-plugin-dts'
8+
import tailwind from 'tailwindcss'
9+
import autoprefixer from 'autoprefixer'
10+
import postcssReplace from 'postcss-replace'
11+
12+
const imports = [
13+
{
14+
entry: 'src/index.ts',
15+
fileName: 'index',
16+
},
17+
{
18+
entry: 'src/bundle-full.ts',
19+
fileName: 'bundle-full',
20+
},
21+
]
22+
23+
const __dirname = cwd()
24+
25+
imports.forEach(async ({ entry, fileName }) => {
26+
const plugins: any = [react(), dts({
27+
rollupTypes: true,
28+
afterBuild: (emittedFiles) => {
29+
emittedFiles.forEach((content, filePath) => {
30+
if (filePath.endsWith('.d.ts')) {
31+
const newFilePath = filePath.replace('.d.ts', '.d.cts')
32+
33+
fs.writeFileSync(newFilePath, content)
34+
}
35+
})
36+
},
37+
})]
38+
39+
await build({
40+
configFile: false,
41+
plugins,
42+
resolve: {
43+
alias: [{ find: '@', replacement: path.resolve(__dirname, 'src') }],
44+
},
45+
css: {
46+
postcss: {
47+
plugins: [
48+
tailwind(),
49+
autoprefixer(),
50+
postcssReplace({
51+
pattern: /(--tw|\*, ::before, ::after)/g,
52+
data: {
53+
'--tw': '--richtext', // Prefixing
54+
'*, ::before, ::after': ':root', // So variables does not pollute every element
55+
},
56+
}),
57+
],
58+
},
59+
preprocessorOptions: {
60+
scss: {
61+
charset: false,
62+
api: 'modern-compiler', // or 'modern'
63+
},
64+
},
65+
},
66+
build: {
67+
cssMinify: 'esbuild',
68+
minify: 'esbuild',
69+
outDir: 'lib',
70+
lib: {
71+
entry: path.resolve(__dirname, entry),
72+
formats: ['es', 'cjs'],
73+
fileName,
74+
},
75+
rollupOptions: {
76+
input: {
77+
index: path.resolve(__dirname, entry),
78+
},
79+
output: entry === 'src/index.ts'
80+
? {
81+
manualChunks(id) {
82+
if (id.includes('@tiptap')) {
83+
return 'tiptap'
84+
}
85+
if (id.includes('node_modules')) {
86+
return 'vendor'
87+
}
88+
if (id.includes('src/utils')) {
89+
return 'utils'
90+
}
91+
if (id.includes('src/locales')) {
92+
return 'locales'
93+
}
94+
},
95+
}
96+
: {},
97+
external: entry === 'src/index.ts' ? ['react', 'react-dom', 'react/jsx-runtime', 'katex', 'shiki', 'docx', '@radix-ui/react-dropdown-menu', '@radix-ui/react-icons', '@radix-ui/react-label', '@radix-ui/react-popover', '@radix-ui/react-separator', '@radix-ui/react-slot', '@radix-ui/react-switch', '@radix-ui/react-tabs', '@radix-ui/react-toast', '@radix-ui/react-toggle', '@radix-ui/react-tooltip', '@radix-ui/react-select', '@radix-ui/react-checkbox', 'react-colorful', 'scroll-into-view-if-needed', 'tippy.js', 'lucide-react', 'prosemirror-docx', 're-resizable', '@excalidraw/excalidraw', '@radix-ui/react-dialog', 'react-image-crop', 'mermaid', 'react-tweet', 'reactjs-signal'] : ['react', 'react-dom', 'react/jsx-runtime', 'katex', 'shiki', '@radix-ui/react-dropdown-menu', '@radix-ui/react-icons', '@radix-ui/react-label', '@radix-ui/react-popover', '@radix-ui/react-separator', '@radix-ui/react-slot', '@radix-ui/react-switch', '@radix-ui/react-tabs', '@radix-ui/react-toast', '@radix-ui/react-toggle', '@radix-ui/react-tooltip', '@radix-ui/react-select', '@radix-ui/react-checkbox', 'react-colorful', 'scroll-into-view-if-needed', 'tippy.js', 'lucide-react', 're-resizable', '@excalidraw/excalidraw', '@radix-ui/react-dialog', 'react-image-crop', 'mermaid', 'react-tweet', 'reactjs-signal'],
98+
},
99+
},
100+
})
101+
})

src/bundle-full.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* eslint-disable import/first */
2+
export * from '@/extensions'
3+
4+
export { default } from '@/components/RichTextEditor'
5+
6+
import locale, { en, hu_HU, pt_BR, vi, zh_CN } from './locales'
7+
import { useEditorState } from '@/hooks/useEditorState'
8+
9+
export { locale, en, hu_HU, vi, zh_CN, pt_BR }
10+
11+
export type { UseEditorStateReturn } from '@/hooks/useEditorState'
12+
export { useEditorState }
13+
export type { Editor, UseEditorOptions } from '@tiptap/react'
14+
export { BubbleMenu } from '@tiptap/react'

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ export { locale, en, hu_HU, vi, zh_CN, pt_BR }
1010

1111
export type { UseEditorStateReturn } from '@/hooks/useEditorState'
1212
export { useEditorState }
13-
export type { Editor, UseEditorOptions } from '@tiptap/react'
1413
export { BubbleMenu } from '@tiptap/react'
14+
export type { Editor, UseEditorOptions } from '@tiptap/react'

vite.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export default defineConfig(({ mode }) => {
5959
lib: {
6060
entry: path.resolve(__dirname, 'src/index.ts'),
6161
formats: ['es', 'cjs'],
62+
fileName: 'index',
6263
},
6364
rollupOptions: {
6465
output: {

0 commit comments

Comments
 (0)