../
来require()
文件。我的目录结构包括这些:
I find that I need to type ../
a lot to require()
files. My directory structure includes these:
js/
components/
...
actions/
...
从components文件夹中,我需要执行import foo from '../actions/fooAction'
。是否可以将根目录设置为项目的根目录?也就是说,我希望执行import foo from '/actions/fooAction'
。我尝试设置Webpack的resolve.root
选项,但好像没有起作用。
resolve['root']
需要一个数组:https://github.com/webpack/docs/wiki/configuration#resolveroot - Kevinroot
选项,现在您需要将一个数组传递给resolve.modules
选项——resolve: { modules: [path.resolve(__dirname, 'src'), 'node_modules'] }
。 - Dmitry Sokurenkoroot
选项已被淘汰,取而代之的是roots
(复数)选项,可以接受多个根目录。roots
与modules
的作用不同,它改变了如何解析_绝对_路径。 - zeptonaut