babel-plugin-webpack-alias icon indicating copy to clipboard operation
babel-plugin-webpack-alias copied to clipboard

Support resolve.root

Open paulfalgout opened this issue 9 years ago • 9 comments

Could this plugin be made to support resolve.root? Is there a way to consider it now?

The way I'm doing it now is grabbing my aliases off of my webpack config and prepending the root to them for the aliases I pass to this plugin.

paulfalgout avatar Apr 04 '16 21:04 paulfalgout

Yeah I'll have a look at implementing resolve.root, it shouldn't be too hard.

adriantoine avatar Apr 28 '16 11:04 adriantoine

+1

rochdev avatar Jun 08 '16 18:06 rochdev

The issue I have there is that I'm not sure how the resolve.root option works 🤔 The webpack documentation is unclear.

EDIT: What I really don't get is how doesn't work when you have both a root and aliases 🤔

adriantoine avatar Aug 08 '16 11:08 adriantoine

We're using babel-plugin-webpack-alias for running our tests in Mocha without full build. Today it stopped work for us after dependencies update Upon running tests we've got such error: Error: Cannot find module 'actions/api' throwing from very first test

Here's resolve part of our config:

var path = require('path')

module.exports = {
   "resolve":{
      "root": path.resolve(__dirname),
      "modulesDirectories":[
         "node_modules",
         "actions",
         "components",
         ...
      ],
      "alias":{
         "commonActions":"actions",
         "apiActions":"actions/api",,
         "customFormActions":"actions/formCustom",
         "components":"components",
         "formComponents":"components/form",
         ...
      },
      "extensions": ['', '.json', '.js', '.jsx']
   },
   ...
}

P.S. We finished up in approach from first comment: create separate test config with absolute paths for aliases. That works for us but may confuse other users of this library

vpotravnyy avatar Aug 08 '16 14:08 vpotravnyy

@vpotravnyy Hi! Sorry for the issue, I will look at it

adriantoine avatar Aug 08 '16 14:08 adriantoine

At the moment it doesn't work with extensions and relative aliases... I'm working on a fix right now

adriantoine avatar Aug 08 '16 15:08 adriantoine

@vpotravnyy I'm moving that to another bug as it is not related to the resolve.root support: https://github.com/trayio/babel-plugin-webpack-alias/issues/14 Thanks for raising the issue!

adriantoine avatar Aug 08 '16 15:08 adriantoine

I've been playing around doing something similar to what this plugin seems to do, and I found that the resolveLoader.root was what I had to use instead of resolve.root see this issue for more info: https://github.com/webpack/webpack/issues/207

jharris4 avatar Aug 24 '16 13:08 jharris4

In case anyone's interested, I just published the utility I've been using to get webpack to play nice with aliases here: https://www.npmjs.com/package/webpack-local-libs

jharris4 avatar Aug 24 '16 15:08 jharris4