-
Notifications
You must be signed in to change notification settings - Fork 293
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
dist contains whole typescript lib #642
Comments
I have the same problem. Is there a way to ignore the package? |
append |
@cobraz I think the production environment should not need any help from the const typescript = process.env.NODE_ENV === 'production' ? {} : require('typescript') If one of your dependencies is requiring let content = fs.readFileSync('index.js', "utf-8");
content = content.replace(/require\("typescript"\)/g, "{}")
fs.writeFileSync('index.js', content) I assume this dependency is also requiring it but not using it in the production env. |
@songkeys You can see specifically what it is used for in pulumi/action#50. It's actually a Github Actions I'm trying to compile into one file. Commiting 400+ Typescript files feels wrong, and actually, the underlying package I don't know yet if I actually need If you have any other ideas/approaches; I'd love some feedback! |
Funny enough, I currently face the opposite problem: I do need
I get the following error: |
@songkeys would it be possible to enable this via an Then rather than applying a patch, a similar outcome could be achieved with a single command |
@EvanBoyle It would be much convenient if we have one. I believe many unused dependencies (like But I'm not sure if such a flag is generally reasonable and applicable. But you can patch it yourself anyway. @guybedford @styfle What do you think? Should we provide something like let content = fs.readFileSync('index.js', "utf-8");
content = content.replace(/require\("typescript"\)/g, "{}")
fs.writeFileSync('index.js', content) |
You can't replace like that. Imagine existing code: const typescript = require('typescript')
const result = typescript.compiler.transform('file.ts') If you replaced it with your solution then it would fail at runtime because there would be missing properties: const typescript = {}
const result = typescript.compiler.transform('file.ts') The correct solution is to use See the docs here: https://github.com/vercel/ncc#options |
I knew. It works only when we are certain that it won't break our production code. I.e. we are sure that the code containing missing properties will never run in production environment. But yes. It's not generally a correct solution. |
@styfle this leaves a top level
I would describe it as "manual tree shaking". As a user I know that this dependency is not needed for the specific app I am building, but the compiler won't drop it, and the exclude flag doesn't help because the top level require gets left in the resulting code. I understand that I can accomplish this with a patch on the generated code, but this another manual step I have to maintain. Seems very similar to https://webpack.js.org/configuration/module/#ruleexclude which has first class support in webpack. I also understand that this flag would not be conservatively correct, and would rely on judgement of users to use appropriately. |
ncc is built on webpack so feel free to submit a PR with a test if you want to add this feature 👍 |
When I use

ncc build
, the output contains all typescript/lib, such as below:I try to comment a require statement like
require(someConfigPath)
,it then no longer output typescript/lib. It seems like import a module using "require" has some problems.Is there any workaround to use "require" and the dist dir not contains the whole typescript/lib ?
The text was updated successfully, but these errors were encountered: