Skip to content

Commit

Permalink
Merge pull request #424 from l3vels/fix/embedded-src
Browse files Browse the repository at this point in the history
Fix/embedded src
  • Loading branch information
okradze authored Jan 26, 2024
2 parents ad96755 + 2d146f1 commit c6f713e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion apps/ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<script
type="module"
id="myWidgetScript"
src="/src/TestComp.tsx?widgetId=66c9972f-7e36-41b2-a202-a64d760b6092"
src="https://dev.l3agi.com/assets/widget.js?widgetId=66c9972f-7e36-41b2-a202-a64d760b6092"
></script>
</body>
</html>
17 changes: 11 additions & 6 deletions apps/ui/src/TestComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ import ReactDOM from 'react-dom'
import './TestComp.css'
import ChatWidget from 'ChatWidget'

const renderTestComp = () => {
const divElement = document.createElement('div')
divElement.id = 'test'
document.body.appendChild(divElement)
const renderTestComp = async () => {
const response = await fetch('https://dev.l3agi.com/manifest.json')
// const response = await fetch('http://localhost:3000/dist/manifest.json')
const manifest = await response.json()
const hashedFilename = manifest['style.css'].file

const linkElement = document.createElement('link')
linkElement.rel = 'stylesheet'
linkElement.type = 'text/css'
linkElement.href = 'http://localhost:3000/dist/assets/style-cc379c0c.css'
linkElement.href = `https://dev.l3agi.com/${hashedFilename}`
// linkElement.href = `http://localhost:3000/dist/${hashedFilename}`
document.head.appendChild(linkElement)

const divElement = document.createElement('div')
divElement.id = 'test'
document.body.appendChild(divElement)

ReactDOM.render(<ChatWidget />, document.getElementById('test'))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const CopyScript = () => {
<script
type="module"
id="myWidgetScript"
src="${appDomainName}/dist/assets/widget.js?widgetId=${agentId}"
src="${appDomainName}/assets/widget.js?widgetId=${agentId}"
defer
></script>`

Expand Down
14 changes: 3 additions & 11 deletions apps/ui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,21 @@ export default defineConfig({
// cssCodeSplit: false,
cssCodeSplit: false,
sourcemap: true,
manifest: true,
rollupOptions: {
input: {
main: './src/index.tsx', // Main app entry point
widget: './src/TestComp.tsx', // Widget entry point
index: 'index.html',
},
// external: ['react', 'react-dom'],

output: {
entryFileNames: 'assets/[name].js',
chunkFileNames: 'assets/[name].js',
format: 'es', // or 'cjs' for CommonJS, or 'umd' for UMD
// globals: {
// react: 'React',
// 'react-dom': 'ReactDOM',
// },

dir: 'dist',
},
},
// lib: {
// name: 'widget',
// entry: './src/TestComp.tsx', // Widget entry point
// formats: ['es'], // Output format, you can add more formats if needed
// fileName: 'widget', // Output file name
// },
},
})

0 comments on commit c6f713e

Please sign in to comment.