-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: allow stdin to pick up settings from tsconfig.json #2543
Comments
This is because in ts mode all import names coule be a type, esbuild will strip out these names if they are not being used in the code or they work like a type (e.g. If you want to keep unused names in ts mode, you can tweak tsconfig to include preserveValueImports: true and/or importsNotUsedAsValues: preserve. |
Oh, I see. I assumed esbuild would only discard type imports (e.g., Closing this, then. Thanks! |
Reopening because actually, it still doesn't work. 🤣 Keeping the Using the
Edit: tsconfig.json is {
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"importsNotUsedAsValues": "preserve",
"preserveValueImports": true
}
}
|
It seems that the filename import esbuild from "esbuild";
console.log("--- sourcefile: <stdin>");
await esbuild.build({
stdin: {
contents: `import a from 'a'`,
loader: "ts",
},
});
console.log("--- sourcefile: a.ts");
await esbuild.build({
stdin: {
contents: `import a from 'a'`,
sourcefile: "a.ts",
},
}); Outputs:
You can add |
The behavior of removing unused imports is just how TypeScript works. You can see that for yourself here, with the official TypeScript compiler: You have to set Again, this has nothing to do with esbuild. This is how the people who designed TypeScript have decided that TypeScript should work.
I believe you are mistaken. Your first example sets |
Hi @evanw, thanks for joining the party :) The problem here, is that esbuild doesn't seem to look for And when using an actual file as entry point, |
This is a feature request. I can rename this issue to be about this.
This is because you have bundling enabled. Bundling is an additional process that runs after transforming TypeScript to JavaScript. The |
Thank you. It would be great too if the
I would argue that the behavior is different when the js loader is used -- see op :) Unless I'm mistaken, enabling bundling is mandatory in my use case because otherwise esbuild does not fire the I've not shown that plugin code here but what I'm trying to achieve in the first place is to transpile TS code and also rewrite the imports. So I guess having esbuild load |
Hi,
Using
esbuild v0.15.7
onWindows 10
x64
withNode 16.15.0
, the following code:works as expected:
However, if I change loader to
ts
in stdin option, ie.:loader: 'ts'
, then the output is empty:Trying other values for the
platform
,format
,target
,treeShaking
and/orminify
options has no effect.The text was updated successfully, but these errors were encountered: