mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
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';
|
||||
|
||||
// accessing browser globals as side effects is allowed if the component is client:only
|
||||
console.log(document.title)
|
||||
|
||||
/** a counter written in React */
|
||||
export function Counter({ children, id }) {
|
||||
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',
|
||||
target: 'esnext',
|
||||
sourcemap: 'external',
|
||||
tsconfigRaw: {
|
||||
compilerOptions: {
|
||||
// Ensure client:only imports are treeshaken
|
||||
importsNotUsedAsValues: 'remove',
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (err: any) {
|
||||
await enhanceCompileError({
|
||||
|
|
|
@ -140,6 +140,12 @@ export default function jsx({ settings, logging }: AstroPluginJSXOptions): Plugi
|
|||
loader: getEsbuildLoader(id),
|
||||
jsx: 'preserve',
|
||||
sourcemap: 'inline',
|
||||
tsconfigRaw: {
|
||||
compilerOptions: {
|
||||
// Ensure client:only imports are treeshaken
|
||||
importsNotUsedAsValues: 'remove',
|
||||
},
|
||||
},
|
||||
});
|
||||
return transformJSX({
|
||||
code: jsxCode,
|
||||
|
|
Loading…
Reference in a new issue