question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use `create-index`

See original GitHub issue

Add https://github.com/gajus/create-index and autogenerate index.js files for each component folder.


@bpierre and I were also discussing what we should do when we need to use “internal” components in more than one place. One idea would be to allow named exports (i.e. export { ... }) from a component so that internal components could access them, but then to not export them to consumers by only re-exporting the default export from each component.

An example, for better clarity:

// in component.js
const InternalComponent = {}
const Component = {} // requires InternalComponent

export { InternalComponent } // this export would be accessible to components inside the library, in case they wanted to restyle it slightly or reuse it
export default Component // this export would be the only component available to outside consumers of the library
// in index.js
export { default as Component } from "component.js"

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
onbjergcommented, Aug 21, 2019

No 😊

1reaction
bpierrecommented, Nov 27, 2017

Agree, we could also only generate the file src/components/index.js, and keep src/index.js as a non-generated file to have some control over it:

// src/components/index.js

// DO NOT EDIT: file generated by “npm run update-index”; any edit will be lost.
export { default as ComponentA } from "./ComponentA"
export { default as ComponentB } from "./ComponentB"
// src/index.js
export * from './components'
export { something, somethingElse } from './some-module'
export { anotherThing } from './another-module'

Also, if we strictly follow the rule of one default export per component, we probably don’t even need create-index, we could do something like this instead:

#!/bin/sh
# scripts/update-index.sh

# Generates components/index.js and components/*/index.js files.

ls -d src/components/*/ \
  | xargs basename \
  | awk '{
      print "export * from \"./"$1"\"\nexport default from \"./"$1"\"" > "src/components/"$1"/index.js"
      print "export { default as "$1" } from \"./"$1"\""
    }' \
  > src/components/index.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

db.collection.createIndex() — MongoDB Manual
2. Creates indexes on collections. To minimize the impact of building an index on replica sets and sharded clusters, use a ...
Read more >
MongoDB - db.collection.CreateIndex() Method - GeeksforGeeks
Using this method we can create different types of indexes like text index, 2dsphere index, 2d index, etc. It takes three parameters first...
Read more >
MongoDB Indexing Tutorial – createIndex ... - Guru99
Creating an Index in MongoDB is done by using the “createIndex” method. The following example shows how add index to collection. Let's assume ......
Read more >
IDBObjectStore.createIndex() - Web APIs | MDN
The createIndex() method of the IDBObjectStore interface creates and returns a new IDBIndex object in the connected database.
Read more >
MongoDB: db.collection.createIndex () method - w3resource
If true, the index only references documents with the specified field. These indexes use less space but behave differently in some situations ( ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found