mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Adds subdirectories section to architecture style guide (#11187)
Adds subdirectories section to architecture style guide
This commit is contained in:
parent
6ecdbd092a
commit
3ff7d5b6fa
1 changed files with 34 additions and 0 deletions
|
@ -34,3 +34,37 @@ plugin_root:
|
|||
<dd>This folder is where code that is useful on both the client and the server belongs. A consistent example of this is constants, but this could apply to helper modules as well.</dd>
|
||||
<dd><strong>NOTE</strong>: If you'd like to avoid adding <code>../common</code> to your public code, you could use <em>webpackShims</em> to resolve the path without traversing backwards.</dd>
|
||||
</dl>
|
||||
|
||||
## Subdirectories
|
||||
|
||||
As code gets more complex, it becomes important to organize it into subdirectories. Each subdirectory should contain an `index.js` file that exposes the contents of that directory.
|
||||
|
||||
```
|
||||
plugin_root:
|
||||
|
||||
.
|
||||
├── common/
|
||||
├── public/
|
||||
├───── component_one/
|
||||
├──────── component_one.js
|
||||
├──────── component_one.html
|
||||
├──────── component_one_helper.js
|
||||
├──────── index.js
|
||||
├───── index.js
|
||||
├── server/
|
||||
└── index.js
|
||||
```
|
||||
|
||||
```
|
||||
public/component_one/index.js:
|
||||
|
||||
import './component_one';
|
||||
```
|
||||
|
||||
```
|
||||
public/index.js (consumer of component_one):
|
||||
|
||||
import './component_one';
|
||||
```
|
||||
|
||||
NOTE: There is currently a Webpack plugin that allows import statements to resolve in multiple ways. The statement `import './component_one'` in the `public/index.js` file above would successfully resolve to both `/public/component_one/component_one.js` and `/public/component_one/index.js`. If there is both a named file and an `index.js` file, Webpack will resolve to the `index.js` file. This functionality will be removed in the future, and when that happens, Webpack will only resolve to the `index.js` file.
|
Loading…
Add table
Add a link
Reference in a new issue