0
Fork 0
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:
Bjorn Lu 2022-12-19 21:44:15 +08:00 committed by GitHub
parent 53e0c98dae
commit 1ac1ed86e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix `client:only` imports with `"importsNotUsedAsValues": "error"` tsconfig

View file

@ -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);

View file

@ -0,0 +1,5 @@
{
"compilerOptions": {
"importsNotUsedAsValues": "error"
}
}

View file

@ -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({

View file

@ -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,