When running tsc
how do we exclude the src
folder (Root containing folder) from output? I have the outDir
set to target
and instead of target/src/file.ts
I would like target/file.ts
?
Excluding the 'src' folder from output during typescript compilation?
Asked Answered
Your probably looking for the rootDir tsconfig option. Specifically, in your case: rootDir: 'src/'
, supposing your keeping all source files under ./src/ and your tsconfig.json at the level above src/.
Note however, tsc
may silently ignore this setting if your actually importing files that aren't under src/
, say for example you import your package.json from top level.
Do have any way to do exclude
src
if I want to import file outside rootDir
except use config devtool: source-map
in webpack.config.js
. –
Unchaste Yeah you can generally do it via a build tool like webpack, vite, rollup. I don't use webpack so can't help further than that. Another alternative is to get your build tool to inject a global variable instead on import if you just need something like the version from package.json. –
Screw
I really doesn't want to use build tool. It make build time more slow. –
Unchaste
© 2022 - 2024 — McMap. All rights reserved.
dist or target
directory to publish from...Would be a lot easier if there was abase
package.json property though ... :) – Summitsrc
folder. I'm planning on building it all into atarget
folder and then copying package.json into that folder so that I can run npm publish from the target folder and have all the typescript modules be importable from there. – Summitdist
folder to runnpm publish
from. – Summittsc src/*
– ShandishandierootDir
options in tsconfig.json, but when I use that typescript complains that it does not contain thetest
directory ... – Summit"include"
option in your tsconfig? So something like{"compilerOptions": { ... }, "include": [ "./src/" ]}
? – Englut