我用gulp构建我的项目并使用browserify。 为了使路径解析更容易,我配置了 browserify
var b = browserify('./app', {paths: ['./node_modules','./src/js']});问题是WebStorm IDE不知道这一点,并且在我需要文件时无法帮助我进行智能感知。 例如,intellisense不适用于以下行
var Store = require('lib/account/stores/account-store');有什么方法可以让Webstorm IDE了解我的路径设置吗?
I build my project with gulp and use browserify. To make path resolution easier i configurated browserify
var b = browserify('./app', {paths: ['./node_modules','./src/js']});The problem is that WebStorm IDE don't know about this and doesn't help me with intellisense when i require files. For example intellisense does't work on the following line
var Store = require('lib/account/stores/account-store');Is there any way i can make Webstorm IDE aware of my paths settings?
最满意答案
你无法做到这一点。 甚至标准的RequireJS baseUrl还没有被尊重 - 参见WEB-13463 。 而且你很难指望IDE能够识别某些gulp / grunt任务所增加的技巧。
WebStorm允许将文件夹标记为“资源根” - 以这种方式标记的文件夹被视为根文件夹,以便相对于它们解析路径。 但这仅适用于“绝对”URL(带有前导斜杠 - '/lib/account/stores/account-store' ,但不适用于'lib/account/stores/account-store' )
Solved the issue by using symlinks. Followed the advice from this link https://github.com/substack/browserify-handbook#organizing-modules
symlink
The simplest thing you can do is to symlink your app root directory into your node_modules/ directory.
Did you know that symlinks work on windows too?
To link a lib/ directory in your project root into node_modules, do:
ln -s ../lib node_modules/app and now from anywhere in your project you'll be able to require files in lib/ by doing require('app/foo.js') to get lib/foo.js.
更多推荐
发布评论