build-system/tasks/helpers.js
/**
   * Generates a plugin to remap the dependencies of a JS bundle.
   * @return {Object}
   */
Generates a plugin to remap the dependencies of a JS bundle.
@return {Object}
Generates a plugin to remap the dependencies of a JS bundle . @return { Object }
function remapDependenciesPlugin() {
    const remaps = Object.entries(options.remapDependencies).map(
      ([path, value]) => ({regex: new RegExp(`^${path}$`), value})
    );
    const external = options.externalDependencies;
    return {
      name: 'remap-dependencies',
      setup(build) {
        build.onResolve({filter: /.*/}, (args) => {
          const {path: importPath, resolveDir} = args;
          const dep = importPath.startsWith('.')
            ? path.posix.join(resolveDir, importPath)
            : importPath;
          for (const {regex, value} of remaps) {
            if (!regex.test(dep)) {
              continue;
            }
            const isExternal = external.includes(value);
            return {
              path: isExternal ? value : require.resolve(value),
              external: isExternal,
            };
          }
        });
      },
    };
  }
function remapDependenciesPlugin ( ) { const remaps = Object . entries ( options . remapDependencies ) . map ( ( [ path , value ] ) => ( { regex : new RegExp ( ` ${ path } ` ) , value } ) ) ; const external = options . externalDependencies ; return { name : 'remap-dependencies' , setup ( build ) { build . onResolve ( { filter : / .* / } , ( args ) => { const { path : importPath , resolveDir } = args ; const dep = importPath . startsWith ( '.' ) ? path . posix . join ( resolveDir , importPath ) : importPath ; for ( const { regex , value } of remaps ) { if ( ! regex . test ( dep ) ) { continue ; } const isExternal = external . includes ( value ) ; return { path : isExternal ? value : require . resolve ( value ) , external : isExternal , } ; } } ) ; } , } ; }
Generates a plugin to remap the dependencies of a JS bundle.
Generates a plugin to remap the dependencies of a JS bundle .