浏览路径和Webstorm配置(Browserify paths and Webstorm configuration)

编程入门 行业动态 更新时间:2024-10-24 09:30:25
浏览路径和Webstorm配置(Browserify paths and Webstorm configuration)

我用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.

更多推荐

本文发布于:2023-08-03 00:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1382478.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   Webstorm   Browserify   paths   configuration

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!