webpack.config.base.js
function filterDepWithoutEntryPoints(dep) {
  // Return true if we want to add a dependency to externals
  try {
    // If the root of the dependency has an index.js, return true
    if (fs.existsSync(path.join(__dirname, `node_modules/${dep}/index.js`))) {
      return false;
    }
    const pgkString = fs
      .readFileSync(path.join(__dirname, `node_modules/${dep}/package.json`))
      .toString();
    const pkg = JSON.parse(pgkString);
    const fields = ['main', 'module', 'jsnext:main', 'browser'];
    return !fields.some(field => field in pkg);
  } catch (e) {
    console.log(e);
    return true;
  }
}
function filterDepWithoutEntryPoints(dep) {
  // Return true if we want to add a dependency to externals
  try {
    // If the root of the dependency has an index.js, return true
    if (fs.existsSync(path.join(__dirname, `node_modules/${dep}/index.js`))) {
      return false;
    }
    const pgkString = fs
      .readFileSync(path.join(__dirname, `node_modules/${dep}/package.json`))
      .toString();
    const pkg = JSON.parse(pgkString);
    const fields = ['main', 'module', 'jsnext:main', 'browser'];
    return !fields.some(field => field in pkg);
  } catch (e) {
    console.log(e);
    return true;
  }
}
function filterDepWithoutEntryPoints ( dep ) { // Return true if we want to add a dependency to externals try { // If the root of the dependency has an index.js, return true if ( fs . existsSync ( path . join ( __dirname , ` ${ dep } ` ) ) ) { return false ; } const pgkString = fs . readFileSync ( path . join ( __dirname , ` ${ dep } ` ) ) . toString ( ) ; const pkg = JSON . parse ( pgkString ) ; const fields = [ 'main' , 'module' , 'jsnext:main' , 'browser' ] ; return ! fields . some ( field => field in pkg ) ; } catch ( e ) { console . log ( e ) ; return true ; } }
Find all the dependencies without a `main` property and add them as webpack externals
Find all the dependencies without a main property and add them as webpack externals