Skip to content

Commit ef09f21

Browse files
AmitMYclaude
andcommitted
Use CDN for SignWriting web components
- Load components from unpkg CDN instead of bundling - Remove complex build plugin that wasn't working with Stencil's lazy loading - Simplify vite config by removing build customizations - Smaller bundle size (205KB vs 229KB) - CDN handles component chunk loading properly 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 84d1a67 commit ef09f21

File tree

2 files changed

+6
-38
lines changed

2 files changed

+6
-38
lines changed

src/main.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { StrictMode } from 'react'
22
import { createRoot } from 'react-dom/client'
33
import './index.css'
44
import App from './App.jsx'
5-
import { defineCustomElements } from '@sutton-signwriting/sgnw-components/loader'
65

7-
// Load SignWriting web components
8-
defineCustomElements()
6+
// Load SignWriting web components from CDN
7+
const script = document.createElement('script')
8+
script.type = 'module'
9+
script.src = 'https://unpkg.com/@sutton-signwriting/[email protected]/dist/sgnw-components/sgnw-components.esm.js'
10+
document.head.appendChild(script)
911

1012
createRoot(document.getElementById('root')).render(
1113
<StrictMode>

vite.config.js

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,12 @@
11
import { defineConfig } from 'vite'
22
import react from '@vitejs/plugin-react'
33
import { VitePWA } from 'vite-plugin-pwa'
4-
import { copyFileSync, mkdirSync, readdirSync } from 'fs'
5-
import { join } from 'path'
6-
7-
// Plugin to copy Stencil web component assets
8-
const copyStencilAssets = () => ({
9-
name: 'copy-stencil-assets',
10-
closeBundle() {
11-
const src = 'node_modules/@sutton-signwriting/sgnw-components/dist/sgnw-components'
12-
const dest = 'dist/assets/sgnw-components'
13-
14-
mkdirSync(dest, { recursive: true })
15-
16-
const files = readdirSync(src)
17-
files.forEach(file => {
18-
copyFileSync(join(src, file), join(dest, file))
19-
})
20-
21-
console.log('✓ Copied Stencil web component assets')
22-
}
23-
})
244

255
// https://vite.dev/config/
266
export default defineConfig({
277
base: '/signwriting-word-processor/',
288
plugins: [
299
react(),
30-
copyStencilAssets(),
3110
VitePWA({
3211
registerType: 'autoUpdate',
3312
manifest: {
@@ -53,18 +32,5 @@ export default defineConfig({
5332
navigateFallback: null
5433
}
5534
})
56-
],
57-
build: {
58-
commonjsOptions: {
59-
include: [/node_modules/]
60-
},
61-
rollupOptions: {
62-
output: {
63-
inlineDynamicImports: true
64-
}
65-
}
66-
},
67-
optimizeDeps: {
68-
include: ['@sutton-signwriting/sgnw-components']
69-
}
35+
]
7036
})

0 commit comments

Comments
 (0)