Browserify basedir option (RequireJS-like)

后端 未结 1 1543
孤街浪徒
孤街浪徒 2021-02-08 00:47

I cannot figure out how the browserify basedir option works..

Note: I may be wrong in my understanding of the whole basedir concept because I\'m co

1条回答
  •  后悔当初
    2021-02-08 01:25

    It turns out that basedir is not the same as RequireJS's baseUrl. As stated by @Ben in the comment above, the official docs says:

    opts.basedir is the directory that browserify starts bundling from for filenames that start with ..

    (source)

    Meaning that basedir only applies to the entry files. Further require calls deep in the file tree structure will always be resolved relatively to the file currently being parsed.

    Answer to my question

    The paths option of browser-resolve (which is used by browserify under the hood) is what I was looking for:

    paths - require.paths array to use if nothing is found on the normal node_modules recursive walk

    (source)

    Just pass this option along with other browserify options when instantiating the bundler.

    Note: It looks like it is messing up things when using together with browserify-shim transform.

    0 讨论(0)
提交回复
热议问题