How do I manage relative path aliasing in multiple grunt-browserify bundles?

后端 未结 4 753
既然无缘
既然无缘 2020-12-08 02:28

This is tad long but I\'ll need the code example to illustrate my confusion. After which I am interested to the answer for the following:

  1. How do I use re
4条回答
  •  南方客
    南方客 (楼主)
    2020-12-08 02:46

    All the answers here about aliases and opts.paths/$NODE_PATH are not great because that approach is a deprecated part of the module system in node and browserify, so it could stop working at any time.

    You should learn how the node_modules algorithm works so you can effectively organize your code in a way that plays well with nested node_modules directories.

    There is a section in the browserify handbook that covers avoiding ../../../../../../.. relative path issues. It can be summarized as:

    • Put your internal modular code in node_modules/ or node_modules/app so that you can require('yourmodule') or require('app/yourmodule') depending on which you prefer.
    • You can use a symlink if you're developing for non-windows platforms and that is what you prefer.

    Don't use opts.path/$NODE_PATH. It makes your project:

    • implicitly depend on a non-obvious configuration or environment setting
    • harder to make work in both node and the browser
    • vulnerable to changes in the module system since array paths are deprecated in node and browserify

提交回复
热议问题