Skip to content
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

Auto-generate imports list from Babel? #41

Open
wmertens opened this issue Nov 19, 2018 · 8 comments
Open

Auto-generate imports list from Babel? #41

wmertens opened this issue Nov 19, 2018 · 8 comments

Comments

@wmertens
Copy link
Contributor

Would it not be possible to automatically update the imported-components.js file that contains all the imports during Babel traversal?

In any case, I had some trouble, it prefixed all node modules with ../. Luckily, since it's just source code I could manually adjust it.

BTW, your project is wonderful 😍 ! It worked as soon as I got the pieces in place. Great approach to the problem IMHO.

@theKashey
Copy link
Owner

Babel has a feature about processing each file in a isolation - there is no good way to process multiple files and create some combined result as a output (or I don't know it)
But I could create babel-plugin or webpack-loader to execute scan when it hit imported-components.js. That would make things easier.

@wmertens
Copy link
Contributor Author

I think the scan as it is now is too primitive; it's finding more or less imports than are being used (since the actual built code can import less, or import in imports from non-src directories), plus, it has to come up with the proper name and that's also not always correct (with the ../ added to my node modules).

When the Babel plugin finds the imports, it finds all of the used ones and only the used ones, and it gets the correct name from the start.

So maybe the babel plugin should use a shared file (or even small sqlite db)? Delete the file at the start of a compile and you won't have old imports.

@theKashey
Copy link
Owner

File path generation should be correct. I just need to add some edge cases for the resolution.
(I never tried to import webpack alias or node_modules)

@wmertens
Copy link
Contributor Author

Yes, but even if the path generation is correct, it will still find all import statements under the given directory, even if they're not used.

@theKashey
Copy link
Owner

That should not be a problem - it does not execute them.

@wmertens
Copy link
Contributor Author

wmertens commented Feb 7, 2019

Found another issue: commented imports are also added, even if they don't exist

And one more question: why are the imports generated as an object instead of a sorted array? It makes git changes bigger…

@theKashey
Copy link
Owner

No real reasons, and I could also generate a sorter object(no keep the current API)

@theKashey
Copy link
Owner

I think this way would not work well with caching, and next year would be a year of caching code compilation.
Let's stick to the current implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants