Skip to content

Commit

Permalink
feat: use react import map only when build is not for connect studio
Browse files Browse the repository at this point in the history
  • Loading branch information
gpuente committed Oct 28, 2024
1 parent 8bfe962 commit 954379f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Powerhouse Connect</title>
<base href="/">
%VITE_IMPORT_REACT_SCRIPT%
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/renderer.ts"></script>
</body>
</html>
</html>
1 change: 1 addition & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
type ImportMetaEnv = {
// Auto-generated by `npx vite-envs update-types` and hot-reloaded by the `vite-env` plugin
// You probably want to add `/src/vite-env.d.ts` to your .prettierignore
VITE_IMPORT_REACT_SCRIPT: string
BASE_URL: string
MODE: string
DEV: boolean
Expand Down
18 changes: 17 additions & 1 deletion vite.renderer.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,23 @@ import { externalIds, viteConnectDevStudioPlugin } from './studio/vite-plugin';
const isBuildStudio = process.env.BUILD_STUDIO === 'true';
const buildStudioExternals = isBuildStudio
? [externalIds, '@powerhousedao/studio', '@powerhousedao/design-system']
: [];
: [externalIds];

const reactImportScript = `
<script type="importmap">
{
"imports":
{
"react": "https://esm.sh/react",
"react/": "https://esm.sh/react/",
"react-dom": "https://esm.sh/react-dom",
"react-dom/": "https://esm.sh/react-dom/"
}
}
</script>
`;

process.env.VITE_IMPORT_REACT_SCRIPT = isBuildStudio ? '' : reactImportScript;

export default defineConfig(({ mode }) => {
const isProd = mode === 'production';
Expand Down

0 comments on commit 954379f

Please sign in to comment.