Fix client only import with importsNotUsedAsValues error (#5639)
This commit is contained in:
parent
53e0c98dae
commit
1ac1ed86e9
5 changed files with 25 additions and 0 deletions
5
.changeset/two-pants-enjoy.md
Normal file
5
.changeset/two-pants-enjoy.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix `client:only` imports with `"importsNotUsedAsValues": "error"` tsconfig
|
|
@ -1,5 +1,8 @@
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
|
// accessing browser globals as side effects is allowed if the component is client:only
|
||||||
|
console.log(document.title)
|
||||||
|
|
||||||
/** a counter written in React */
|
/** a counter written in React */
|
||||||
export function Counter({ children, id }) {
|
export function Counter({ children, id }) {
|
||||||
const [count, setCount] = useState(0);
|
const [count, setCount] = useState(0);
|
||||||
|
|
5
packages/astro/e2e/fixtures/client-only/tsconfig.json
Normal file
5
packages/astro/e2e/fixtures/client-only/tsconfig.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"importsNotUsedAsValues": "error"
|
||||||
|
}
|
||||||
|
}
|
|
@ -41,6 +41,12 @@ export async function cachedFullCompilation({
|
||||||
loader: 'ts',
|
loader: 'ts',
|
||||||
target: 'esnext',
|
target: 'esnext',
|
||||||
sourcemap: 'external',
|
sourcemap: 'external',
|
||||||
|
tsconfigRaw: {
|
||||||
|
compilerOptions: {
|
||||||
|
// Ensure client:only imports are treeshaken
|
||||||
|
importsNotUsedAsValues: 'remove',
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
await enhanceCompileError({
|
await enhanceCompileError({
|
||||||
|
|
|
@ -140,6 +140,12 @@ export default function jsx({ settings, logging }: AstroPluginJSXOptions): Plugi
|
||||||
loader: getEsbuildLoader(id),
|
loader: getEsbuildLoader(id),
|
||||||
jsx: 'preserve',
|
jsx: 'preserve',
|
||||||
sourcemap: 'inline',
|
sourcemap: 'inline',
|
||||||
|
tsconfigRaw: {
|
||||||
|
compilerOptions: {
|
||||||
|
// Ensure client:only imports are treeshaken
|
||||||
|
importsNotUsedAsValues: 'remove',
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
return transformJSX({
|
return transformJSX({
|
||||||
code: jsxCode,
|
code: jsxCode,
|
||||||
|
|
Loading…
Reference in a new issue