ecmascript 6 - avoiding deep nested module imports in an ES6 JavaScript web project -


i trying tackle have javascript project structure. writing es6 syntax webpack. current directory structure looks this

project-dir   |_ packages.json   |_ webpack.config.js   |_ html   |  |_ ***   |  |_ ***   |_ js      |_ app.js      |_ routes         |_ abc-component         |  |_ components         |  |  |_ abc1.js         |  |  |_ abc2.js         |  |_ index.js         |         |_ xyz-component         |  |_ components         |  |  |_ xyz1.js         |  |  |_ xyz2.js         |  |_ index.js         |_ reducers.js 

this simpler structure. problem "reducers.js" , "abc1.js/xyz1.js" need access same functionality. so, if functionality lives in "reducers.js" "abc1.js/xyz1.js" have import "../../reducers.js". if functionality lives split in "abc1.js" , "xyz1.js" etc, "reducers.js" have import each 1 of them ".\abc-component\components\abc1.js" , ".\xyz-component\component\xyz1.js". first way, feels reaching way , second way, feels reaching way up. code constrained structure of file layout. directory structure go deeper down , end ugly imports.

so, makes sense me pull out functionality shared reducers.js , "abc1/js/xyz1.js" different module. in doing thought putting in git repo, functionality project specific , didn't want hassle of putting in repo.

i tried creating "lib" folder under "js" folder , put common functionality in folder along packages.json file. way, thought add "dependencies" in project's package.json file "file:\lib\common" value. way, reference module locally. landed me in load of trouble. problems encountering 1) couldn't write es6 in common module since webpack not processing 2) everytime change in common.js, have run "npm install" 3) npm seems caching old version of common module ever after change , run "npm install". not sure comes from, did clean npm cache running "npm cache clean" 4) when write old javascript in common module , not es6, webpack watch not pick on changes file , re-render app.

i wondering if thoughts on how best go solving problem. also, thoughts how tried , exceptionally failed in solving problem local module helpful.

one way deal put common code node module , import other library.

this work "lib" idea suggested without needing relative imports.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -