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

Generate static imports for correct indexing #113

Closed
advance512 opened this issue Feb 18, 2017 · 2 comments
Closed

Generate static imports for correct indexing #113

advance512 opened this issue Feb 18, 2017 · 2 comments

Comments

@advance512
Copy link

An issue I have encountered is that because of arc's dynamic style of importing:

const req = require.context('.', true, /\.\/[^/]+\/[^/]+\/index\.js$/)

req.keys().forEach((key) => {
  const componentName = key.replace(/^.+\/([^/]+)\/index\.js/, '$1')
  module.exports[componentName] = req(key).default
})

WebStorm (and I am sure other IDEs) completely loses its ability index the source, hence to "Go To Definition", "Auto Import" etc - which is highly annoying and costs productivity.

A simple way to fix it would be to add a:

export * from './index.optimized'

This index.optimized.js will basically be a "dump" of the output of the module dynamically generated:

export Header from './organisms/Header'
export Footer from './organisms/Footer'
..
..

So importing it will change nothing. This file can quite easily be generated, and should be generated on instantiation of the arc-generator when working in dev mode.

What do you think?

@diegohaz
Copy link
Owner

Please, take a look at the project on this commit: https://github.com/diegohaz/arc/tree/0b9cacb2767a77ac4ea55f0a8c8c5b6c757ebac0/src/components

It had had an index.js file on each component type folder exporting all components inside that folder (at that time we still didn't have generator-arc so adding components was a pain in the ass).

I'm aware of this problem with tooling and I find your solution very elegant. We just need to improve generator-arc to handle this.

@diegohaz
Copy link
Owner

diegohaz commented Mar 1, 2017

Closing this in favor to #131

@diegohaz diegohaz closed this as completed Mar 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants