How to use the assetgraph/lib/assetGraphConditions.stringify function in assetgraph

To help you get started, we’ve selected a few assetgraph examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github assetgraph / assetgraph-builder / lib / transforms / cloneForEachConditionValue.js View on Github external
(options.conditions && options.conditions[splitCondition]) ||
          Object.keys(isSeenByConditionValue);
        if (typeof conditionValues === 'string') {
          conditionValues = [conditionValues];
        }
        if (conditionValues.length > 0) {
          for (const conditionValue of conditionValues) {
            const clonedHtmlAsset = htmlAsset.clone();
            const documentElement = clonedHtmlAsset.parseTree.documentElement;
            if (documentElement) {
              const htmlSystemJsConditionals =
                assetGraphConditions.parse(documentElement) || {};
              htmlSystemJsConditionals[splitCondition] = conditionValue;
              documentElement.setAttribute(
                'data-assetgraph-conditions',
                assetGraphConditions.stringify(htmlSystemJsConditionals)
              );
              clonedHtmlAsset.markDirty();
            }
            const targetUrl = htmlAsset.url.replace(
              /(\.\w+)?$/,
              '.' + conditionValue + '$1'
            );
            clonedHtmlAsset.url = targetUrl;

            for (const relation of assetGraph.findRelations({
              from: clonedHtmlAsset
            })) {
              const dataSystemJsConditions =
                relation.node && assetGraphConditions.parse(relation.node);
              if (dataSystemJsConditions) {
                let key = splitCondition + '.js|default';
github assetgraph / assetgraph-builder / lib / transforms / cloneForEachConditionValue.js View on Github external
let value = dataSystemJsConditions[key];
                if (!value) {
                  key = splitCondition + '|default';
                  value = dataSystemJsConditions[key];
                }
                if (value) {
                  if (value === conditionValue) {
                    delete dataSystemJsConditions[key];
                    if (Object.keys(dataSystemJsConditions).length === 0) {
                      relation.node.removeAttribute(
                        'data-assetgraph-conditions'
                      );
                    } else {
                      relation.node.setAttribute(
                        'data-assetgraph-conditions',
                        assetGraphConditions.stringify(dataSystemJsConditions)
                      );
                    }
                    relation.from.markDirty();
                  } else {
                    relation.detach();
                  }
                  continue;
                }
              }
            }
          }
          assetGraph.removeAsset(htmlAsset);
        }
      }
    }
  };

assetgraph

An auto discovery dependency graph based optimization framework for web pages and applications

BSD-3-Clause
Latest version published 7 months ago

Package Health Score

56 / 100
Full package analysis

Similar packages