Skip to content

Commit

Permalink
Update based on review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp committed Aug 11, 2023
1 parent 66dd04e commit 4b2cc14
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/integrations/preact/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function getRenderer(development: boolean): AstroRenderer {
}

export type Options =Pick<VitePreactPluginOptions, 'include' | 'exclude'> & { compat?: boolean };
// TODO: Add back compat support -- how would this work in the new world?

export default function ({include, exclude, compat}: Options = {}): AstroIntegration {
return {
name: '@astrojs/preact',
Expand Down Expand Up @@ -53,7 +53,7 @@ export default function ({include, exclude, compat}: Options = {}): AstroIntegra
dedupe: ['preact/compat', 'preact'],
};
// noExternal React entrypoints to be bundled, resolved, and aliased by Vite
viteConfig.ssr = {
viteConfig.ssr = {f
noExternal: ['react', 'react-dom', 'react-dom/test-utils', 'react/jsx-runtime'],
};
}
Expand Down
1 change: 1 addition & 0 deletions packages/integrations/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"dev": "astro-scripts dev \"src/**/*.ts\""
},
"dependencies": {
"@astrojs/internal-helpers": "0.2.0-beta.0",
"@vitejs/plugin-react": "^4.0.3"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/integrations/react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AstroIntegration } from 'astro';
import { version as ReactVersion } from 'react-dom';
import react, {type Options as ViteReactPluginOptions} from '@vitejs/plugin-react';
import { appendForwardSlash } from '@astrojs/internal-helpers/path';


const FAST_REFRESH_PREAMBLE = react.preambleCode;
Expand Down Expand Up @@ -64,7 +65,7 @@ export default function ({include, exclude}: Pick<ViteReactPluginOptions, 'inclu
addRenderer(getRenderer());
updateConfig({ vite: getViteConfiguration({include, exclude}) });
if (command === 'dev') {
const preamble = FAST_REFRESH_PREAMBLE.replace(`__BASE__`, config.base)
const preamble = FAST_REFRESH_PREAMBLE.replace(`__BASE__`, appendForwardSlash(config.base))
injectScript('before-hydration', preamble);
}
},
Expand Down
14 changes: 3 additions & 11 deletions packages/integrations/solid/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import type { AstroConfig, AstroIntegration, AstroRenderer } from 'astro';
import type { AstroIntegration, AstroRenderer } from 'astro';
import solid, { type Options as ViteSolidPluginOptions } from 'vite-plugin-solid';

async function getViteConfiguration(
isDev: boolean,
astroConfig: AstroConfig,
{ include, exclude }: Options = {},
) {
// https://github.com/solidjs/vite-plugin-solid
// We inject the dev mode only if the user explicitly wants it or if we are in dev (serve) mode
const nestedDeps = ['solid-js', 'solid-js/web', 'solid-js/store', 'solid-js/html', 'solid-js/h'];
return {
/**
* We only need esbuild on .ts or .js files.
* .tsx & .jsx files are handled by us
*/
resolve: {
conditions: ['solid', ...(isDev ? ['development'] : [])],
dedupe: nestedDeps,
Expand Down Expand Up @@ -59,13 +54,10 @@ export default function (opts: Options = {}): AstroIntegration {
return {
name: '@astrojs/solid-js',
hooks: {
'astro:config:setup': async ({ command, addRenderer, updateConfig, config }) => {
'astro:config:setup': async ({ command, addRenderer, updateConfig }) => {
addRenderer(getRenderer());
updateConfig({
/*vite: {
plugins: [solid({ include, exclude, dev: command === 'dev', ssr: true })]
}*/
vite: await getViteConfiguration(command === 'dev', config, opts),
vite: await getViteConfiguration(command === 'dev', opts),
});
},
},
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4b2cc14

Please sign in to comment.