-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Fix Components script url for production
- Loading branch information
Showing
5 changed files
with
20 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
import { resolve } from "node:path"; | ||
import { defineConfig } from "vite"; | ||
import { createHtmlPlugin } from "vite-plugin-html"; | ||
|
||
const projectRootDir = resolve(__dirname); | ||
const bundleDir = resolve(projectRootDir, "../../sdk/components/cdn"); | ||
const scriptSrc = | ||
process.env.NODE_ENV === "production" | ||
? "https://cdn.jsdelivr.net/npm/@frak-labs/components@latest/dist/bundle/components.js" | ||
: `${bundleDir}/components.js`; | ||
|
||
export default defineConfig({ | ||
server: { | ||
port: 3013, | ||
}, | ||
publicDir: "public", | ||
plugins: [ | ||
{ | ||
name: "html-transform", | ||
transformIndexHtml(html) { | ||
// Replace @/ with the actual path in HTML files | ||
return html.replace( | ||
/<script([^>]*?) src="@\/(.*?)"([^>]*)>/g, | ||
(_match, prefix, path, suffix) => | ||
`<script${prefix} src="${bundleDir}/${path}"${suffix}>` | ||
); | ||
createHtmlPlugin({ | ||
inject: { | ||
data: { | ||
injectScript: `<script src="${scriptSrc}"></script>`, | ||
}, | ||
}, | ||
}, | ||
}), | ||
], | ||
}); |