src/OutputHash.js
function replaceStringInAsset(asset, source, target) {
    const sourceRE = new RegExp(source, 'g');

    if (typeof asset === 'string') {
        return asset.replace(sourceRE, target);
    }

    // ReplaceSource
    if ('_source' in asset) {
        asset._source = replaceStringInAsset(asset._source, source, target);
        return asset;
    }

    // CachedSource
    if ('_cachedSource' in asset) {
        asset._cachedSource = asset.source().replace(sourceRE, target);
        return asset;
    }

    // RawSource / SourceMapSource
    if ('_value' in asset) {
        asset._value = asset.source().replace(sourceRE, target);
        return asset;
    }

    // ConcatSource
    if ('children' in asset) {
        asset.children = asset.children.map(child => replaceStringInAsset(child, source, target));
        return asset;
    }

    throw new Error(
        `Unknown asset type (${asset.constructor.name})!. ` +
            'Unfortunately this type of asset is not supported yet. ' +
            'Please raise an issue and we will look into it asap'
    );
}
function replaceStringInAsset(asset, source, target) {
    const sourceRE = new RegExp(source, 'g');

    if (typeof asset === 'string') {
        return asset.replace(sourceRE, target);
    }

    // ReplaceSource
    if ('_source' in asset) {
        asset._source = replaceStringInAsset(asset._source, source, target);
        return asset;
    }

    // CachedSource
    if ('_cachedSource' in asset) {
        asset._cachedSource = asset.source().replace(sourceRE, target);
        return asset;
    }

    // RawSource / SourceMapSource
    if ('_value' in asset) {
        asset._value = asset.source().replace(sourceRE, target);
        return asset;
    }

    // ConcatSource
    if ('children' in asset) {
        asset.children = asset.children.map(child => replaceStringInAsset(child, source, target));
        return asset;
    }

    throw new Error(
        `Unknown asset type (${asset.constructor.name})!. ` +
            'Unfortunately this type of asset is not supported yet. ' +
            'Please raise an issue and we will look into it asap'
    );
}
function replaceStringInAsset ( asset , source , target ) { const sourceRE = new RegExp ( source , 'g' ) ; if ( typeof asset === 'string' ) { return asset . replace ( sourceRE , target ) ; } // ReplaceSource if ( '_source' in asset ) { asset . _source = replaceStringInAsset ( asset . _source , source , target ) ; return asset ; } // CachedSource if ( '_cachedSource' in asset ) { asset . _cachedSource = asset . source ( ) . replace ( sourceRE , target ) ; return asset ; } // RawSource / SourceMapSource if ( '_value' in asset ) { asset . _value = asset . source ( ) . replace ( sourceRE , target ) ; return asset ; } // ConcatSource if ( 'children' in asset ) { asset . children = asset . children . map ( child => replaceStringInAsset ( child , source , target ) ) ; return asset ; } throw new Error ( ` ${ asset . constructor . name } ` + 'Unfortunately this type of asset is not supported yet. ' + 'Please raise an issue and we will look into it asap' ) ; }
Replaces a string in an asset
Replaces a string in an asset