Make absolute paths relative to the project root in Webpack -
i find need type ../
lot require()
files. directory structure includes these:
js/ components/ ... actions/ ...
from components folder, need import foo '../actions/fooaction'
. possible make root directory root of project? i.e. want import foo '/actions/fooaction'
instead. tried setting webpack's resolve.root
option, didn't seem anything.
the resolve.root
option not modifiy how file modules resolved.
a required module prefixed '/' absolute path file. example, require('/home/marco/foo.js') load file @ /home/marco/foo.js.
the /
resolves root of file system.
maybe want resolve js
folder modules directory.
webpack.config.js
resolve: { root: path.resolve('./js') }
with configuration added config file tell webpack resolve import
or require
relative js
folder. then, instead of using
import foo '../actions/fooaction'
you able to:
import foo 'actions/fooaction`
mind lack of /
@ beginning.
Comments
Post a Comment