Webpack alias import with fallback

Viewed 23

Let's in the project i install 2 dependencies @library-a and @library-b. And i use

import { Button } From '@library-a'

So normally without any webpack configuration, it will import the button from @library-a.

Now what I want is

  1. instead of import Button from @library-a, it will try/prioritize to import from @library-b .
  2. however, it is not a complete replacement, if @library-b doesn't have Button, it will fallback back to import Button from @library-a
  3. No direct code change in business, just change in webpack configuration

I have a look via webpack resolve, but i am a bit confused with it, appreaciate all helps . Thanks

P/s: a Bit of explanation why I need this, is I'm trying to build a library (@library-a), and a supplement plugin for the library (@library-b) for only some of the components in the library. So if the user install the library with the plugin, expectedly some of the components will have some customized logic from the plugin

0 Answers
Related