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

后端 未结 4 764
既然无缘
既然无缘 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条回答
  •  旧时难觅i
    2020-12-08 02:36

    These answers depend on how the rest of your project is setup, but maybe it's a good starting point. Also, you will need to use current v2 beta of grunt-browserify for this to actually work (npm install grunt-browserify@2).

    1.

    You can use aliasMapping to create some dynamic aliases for your modules. Just for clarity, lets move all your modules to src/modules/. Then, aliasMapping configuration could be something like this:

    options: {
      aliasMappings: {
        cwd: 'src',
        src: ['modules/**/*.js']
      }
    }
    

    Lets suppose you have a module in src/modules/magic/stuff.js, then you can require it like this, regardless of where the .js file that's doing the require is located:

    var magicStuff = require('modules/magic/stuff.js');
    

    2.

    Not sure about this one. Your project structure shows a spec/index.js, but you mention spec/specs.js. Are they supposed to be the same file?

    Anyways, what duplicate work are you talking about? Because ./index.js has a different entry file than spec/index.js. If you are looking for a way to include ./index.js in specs/, then maybe you can copy it before running the tests instead of building it from scratch.

提交回复
热议问题