protected virtual async Task AggregateAsync(IBundleTransformContext context, IReadOnlyList <IBundleTransform> transforms)
        {
            if (transforms != null)
            {
                for (int i = 0, n = transforms.Count; i < n; i++)
                {
                    if (transforms[i] is IAggregatorBundleTransform aggregatorTransform)
                    {
                        await aggregatorTransform.AggregateAsync(context);

                        if (context.Content != null)
                        {
                            return;
                        }

                        aggregatorTransform.Aggregate(context);
                        if (context.Content != null)
                        {
                            return;
                        }
                    }
                }
            }

            // falling back to simple concatenation when aggregation was not handled by the transforms
            context.Content = string.Join(context.BuildContext.Bundle.ConcatenationToken, context.TransformedItemContexts.Select(itemContext => itemContext.Content));
        }
        public override async Task AggregateAsync(IBundleTransformContext context)
        {
            IModuleBundler bundler = _moduleBundlerFactory.Create(_options);

            ModuleFile[] rootFiles = context.TransformedItemContexts
                                     .Select((itemContext, i) =>
                                             itemContext is IFileBundleItemTransformContext fileItemContext ?
                                             new ModuleFile(fileItemContext.FileProvider, fileItemContext.FilePath, fileItemContext.CaseSensitiveFilePaths)
            {
                Content = fileItemContext.Content
            } :
                                             new ModuleFile()
            {
                Content = itemContext.Content
            })
                                     .ToArray();

            ModuleBundlingResult result = await bundler.BundleAsync(rootFiles, context.BuildContext.CancellationToken);

            context.Content = result.Content ?? string.Empty;
            if (result.Imports != null && result.Imports.Count > 0)
            {
                context.BuildContext.ChangeSources?.UnionWith(result.Imports);
            }
        }
        protected virtual async Task <string> ApplyTransformsAsync(IBundleTransformContext context, IReadOnlyList <IBundleTransform> transforms)
        {
            if (transforms != null)
            {
                for (int i = 0, n = transforms.Count; i < n; i++)
                {
                    context.BuildContext.CancellationToken.ThrowIfCancellationRequested();

                    IBundleTransform transform = transforms[i];
                    await transform.TransformAsync(context);

                    transform.Transform(context);
                }
            }

            return(context.Content);
        }
Beispiel #4
0
 public virtual Task AggregateAsync(IBundleTransformContext context)
 {
     return(Task.CompletedTask);
 }
Beispiel #5
0
 public virtual void Aggregate(IBundleTransformContext context)
 {
 }
Beispiel #6
0
 public virtual void Transform(IBundleTransformContext context)
 {
 }
        public override void Transform(IBundleTransformContext context)
        {
            var filePath = context is IFileBundleItemTransformContext fileItemContext ? fileItemContext.FilePath : null;

            context.Content = _minifier.Process(context.Content, filePath);
        }