4
我的文件夹结构如下:解决ES6导入路径2
- test
- scripts
index.js
user.js
- default
- scripts
index.js
api.js
user.js
我需要在本地解决的导入路径(‘测试’的目录),而在发生故障时的备用应通过“默认”目录解决。
测试/脚本/ index.js的代码是:
import api from 'scripts/api'; // should be taken from 'default'
import user from 'scripts/user; // should take the local 'user.js'
...
我使用的WebPack 2.1.0具有以下配置:
...
resolve: {
modules: [
path.resolve('./default')
]
}
...
这种结构使的WebPack解决所有模块'script/*'
通过“默认”路径,而相对的'./script/*'
路径永远不会从模块的目录中跳出,因此不能使用相对路径作为回退。
好像resolve.fallback
不受的WebPack 2
支持我试图插件写normal-module-factory->before-resolve
,但我收到的唯一路径是进入通道。
是否有任何可能的配置来解决这个问题? 正在编写自定义加载器可能是解决方案吗?
感谢
可以['resolve.modulesDirectories'](http://webpack.github.io /docs/configuration.html#resolve-modules目录)的帮助? –
@CD ..恐怕不是。我不是在寻找一个祖先,而是在一定程度上寻找一个兄弟姐妹。此外,它被告知webpack 2的解析配置与1.x不同。 –