-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Unused component imported #120
Comments
Hey @kevindavee , Can you provide the repo with the issue? |
Hey @alan2207 , I just invited you to the repo because it's a private repo. I gave you read access so you can read the code. Here's the repo https://github.com/kevindavee/icx-app |
@kevindavee Can you send me the link to the test file? |
Try to comment on this line https://github.com/kevindavee/icx-app/blob/bf843adfa016248221163831f1380c2ee961e610/src/tests/jestSetup.ts#L60-L64 And run You'll see a warning like this. As you can see from the stack trace, the hook |
Looks like the tooling won't tree-shake unused imports from the feature, so you will have to specify the exact file. If this happens, avoid using index files from features as the main entry point and just import from files individually. Updating the imports to this made the test succeed without issues: |
Yeah, I understand it works if I import my component directly. But for me, the beauty of this codebase which inspired by yours, is to have feature modules that act like a stand-alone package. Do you know any way to tree-shake the unused components? |
I'm having this issue as well when importing a component from a feature's index.ts file and it importing everything in that index.ts file (even unused one). I guess the only solution right now would be to import directly? |
Hey @prodbygoss @kevindavee I've just published the package https://github.com/pafry7/babel-plugin-bulletproof-features-import. It seems to solve the issue in our two projects. You can give it a try. |
Ooh, this look interesting. So would this work intelligently with different sub directories too? In your example it shows it changing the imports to /views sub directory. If I have a bunch of items in sub directories of the features folder (like /types, /screens, /components, /hooks, etc) that get exported from the barrel file, would it be able to import directly to those paths |
It should work with subfolders as long as you use relative imports in your index file. |
Gotcha, so to confirm: If my import { Foo } from './components/Foo'
import { bar } from './utils/bar'
import { useBaz } from './hooks' It would all work? |
Hey @alan2207 ! Thanks for creating this repository. It's a great starting point for me to build my React App.
I'm currently facing a problem where my unused code is executed in the test. So I'll give an example.
features/order/index.ts
pages/MyPage.tsx
pages/MyPage.test.tsx
I'm testing MyPage component and mock useGetOrderQuery using jest.spyOn()
But somehow, the code inside
useCreateOrderMutation
is executed even though I'm not importing it inMyPage
.Is there any missing setup from my side? I didn't clone this repo but I built my repo from scratch, so maybe I might missed something from the webpack or the other setup.
Thanks!
The text was updated successfully, but these errors were encountered: