Search code examples
webpackwebpack-2

How to add to `externals` all modules names that contain common name


In webpack I can add the following to externals:

externals: {
    'lib/@angular/core': 'common lib/@angular/core',
    'lib/@angular/platform-browser': 'common lib/@angular/platform-browser',
    'lib/@angular/platform-browser-dynamic': 'common lib/@angular/platform-browser-dynamic'
},

Is there any way to specify that everything starting from lib should be added to externals, so that the above configuration can be shortened to the following:

externals: {
    'lib/*': 'common lib/*',
},

Solution

  • You can use regexp option:

    externals: [
        /lib/'
    ]
    

    However, there is currently no way to specify mapping to 'common lib/*'. See this issue for more details.