import module from directory with index.js
Quick, short summary:
As I understand it after several tests, it is now impossible to import a module from directory with index.js without specifying the file. I'm right?
If I do import like this:
import gallery from './blocks/gallery';
then CK does not find the file and does not display it in the ES6 Imports list.
If I do the import like this:
import gallery from './blocks/gallery/index.js';
then everything works.
Or am I missing something in the settings?
As far as I know, I’ve never supported that. My general philosophy is to remove as much “implicit magic” as possible and favor explicitly declaring intent.
If “index.js” is left off the import path, it’s not immediately clear (especially to folks who are new to JS modules) what’s being imported. Additionally, there’s overhead added to the compiling as CodeKit has to search for a file to resolve that statement. Explicitly specifying the file removes that overhead and speeds up compiling, project re-indexing, and so forth.
I’m not unpersuadable on the issue, but in general I encourage people to remove as much magic as possible from their code. This is especially true once folks start using a package.json file to specify import locations, etc. It becomes a game of trying to remember how you set something up and trying to figure out how stuff is working when it doesn’t look like it should.
Thanks for the explanation. I just decided to transfer one of my projects to CK to get away from compilation through the Terminal and ran into this. Your position is clear and well founded.
Thanks for the wonderful product!