Пример #1
0
        public static IApplicationBuilder UseModulesContent(this IApplicationBuilder appBuilder, IBundleManager bundles)
        {
            var hostingEnv = appBuilder.ApplicationServices.GetRequiredService <IHostingEnvironment>();
            var modules    = GetInstalledModules(appBuilder.ApplicationServices);

            var cssBundleItems = modules.SelectMany(m => m.Styles).ToArray();

            var cssFiles = cssBundleItems.OfType <ManifestBundleFile>().Select(x => new CssFile(x.VirtualPath));

            cssFiles = cssFiles.Concat(cssBundleItems.OfType <ManifestBundleDirectory>().SelectMany(x => new WebFileFolder(hostingEnv, x.VirtualPath)
                                                                                                    .AllWebFiles <CssFile>(x.SearchPattern, x.SearchSubdirectories ?  SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)));

            var scriptBundleItems = modules.SelectMany(m => m.Scripts).ToArray();
            var jsFiles           = scriptBundleItems.OfType <ManifestBundleFile>().Select(x => new JavaScriptFile(x.VirtualPath));

            jsFiles = jsFiles.Concat(scriptBundleItems.OfType <ManifestBundleDirectory>().SelectMany(x => new WebFileFolder(hostingEnv, x.VirtualPath)
                                                                                                     .AllWebFiles <JavaScriptFile>(x.SearchPattern, x.SearchSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)));


            //TODO: Test minification and uglification for resulting bundles
            var options = bundles.DefaultBundleOptions;

            options.DebugOptions.FileWatchOptions.Enabled = true;

            bundles.Create("vc-modules-styles", cssFiles.ToArray())
            .WithEnvironmentOptions(options);

            bundles.Create("vc-modules-scripts", jsFiles.ToArray())
            .WithEnvironmentOptions(options);


            return(appBuilder);
        }
        public static IApplicationBuilder UseModulesContent(this IApplicationBuilder appBuilder, IBundleManager bundles)
        {
            var env            = appBuilder.ApplicationServices.GetService <IHostingEnvironment>();
            var modules        = GetInstalledModules(appBuilder.ApplicationServices);
            var modulesOptions = appBuilder.ApplicationServices.GetRequiredService <IOptions <LocalStorageModuleCatalogOptions> >().Value;
            var cssBundleItems = modules.SelectMany(m => m.Styles).ToArray();
            var cssFiles       = cssBundleItems.OfType <ManifestBundleFile>().Select(x => new CssFile(x.VirtualPath));

            cssFiles = cssFiles.Concat(cssBundleItems.OfType <ManifestBundleDirectory>().SelectMany(x => new WebFileFolder(modulesOptions.DiscoveryPath, x.VirtualPath)
                                                                                                    .AllWebFiles <CssFile>(x.SearchPattern, x.SearchSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)));

            var scriptBundleItems = modules.SelectMany(m => m.Scripts).ToArray();
            var jsFiles           = scriptBundleItems.OfType <ManifestBundleFile>().Select(x => new JavaScriptFile(x.VirtualPath));

            jsFiles = modules.Aggregate(jsFiles, (current, module) =>
            {
                return(current.Concat(module.Scripts
                                      .OfType <ManifestBundleDirectory>()
                                      .SelectMany(s =>
                                                  env.IsDevelopment() ?
                                                  new WebFileFolder(modulesOptions.DiscoveryPath, s.VirtualPath, module.ModuleName, module.Assembly.GetName().Name)
                                                  .AllWebFilesForDevelopment <JavaScriptFile>(s.SearchPattern,
                                                                                              s.SearchSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly) :
                                                  new WebFileFolder(modulesOptions.DiscoveryPath, s.VirtualPath)
                                                  .AllWebFilesWithRequestRoot <JavaScriptFile>(s.SearchPattern,
                                                                                               s.SearchSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly))));
            });

            var options = bundles.DefaultBundleOptions;

            options.DebugOptions.FileWatchOptions.Enabled = true;
            options.DebugOptions.ProcessAsCompositeFile   = false;
            options.DebugOptions.CompressResult           = false;
            options.DebugOptions.CacheControlOptions      = new CacheControlOptions()
            {
                EnableETag = false, CacheControlMaxAge = 0
            };

            bundles.Create("vc-modules-styles", cssFiles.ToArray())
            .WithEnvironmentOptions(options);

            bundles.Create("vc-modules-scripts", bundles.PipelineFactory.Create <NuglifyJs>(), jsFiles.ToArray())
            .WithEnvironmentOptions(options);


            return(appBuilder);
        }
    // only issue with creating bundles like this is that we don't have full control over the bundle options, though that could
    public void CreateCssBundle(string bundleName, BundlingOptions bundleOptions, params string[]?filePaths)
    {
        if (filePaths?.Any(f => !f.StartsWith("/") && !f.StartsWith("~/")) ?? false)
        {
            throw new InvalidOperationException("All file paths must be absolute");
        }

        if (_bundles.Exists(bundleName))
        {
            throw new InvalidOperationException($"The bundle name {bundleName} already exists");
        }

        PreProcessPipeline pipeline = bundleOptions.OptimizeOutput
            ? _cssOptimizedPipeline.Value
            : _cssNonOptimizedPipeline.Value;

        Bundle bundle = _bundles.Create(bundleName, pipeline, WebFileType.Css, filePaths);

        bundle.WithEnvironmentOptions(ConfigureBundleEnvironmentOptions(bundleOptions));
    }
Пример #4
0
 /// <summary>
 /// Create a CSS bundle
 /// </summary>
 /// <param name="bundleManager"></param>
 /// <param name="bundleName"></param>
 /// <param name="pipeline"></param>
 /// <param name="paths"></param>
 /// <returns></returns>
 public static Bundle CreateCss(this IBundleManager bundleManager, string bundleName, PreProcessPipeline pipeline, params string[] paths)
 {
     return(bundleManager.Create(bundleName, pipeline, WebFileType.Css, paths));
 }
Пример #5
0
 /// <summary>
 /// Create a JS bundle
 /// </summary>
 /// <param name="bundleManager"></param>
 /// <param name="bundleName"></param>
 /// <param name="paths"></param>
 /// <returns></returns>
 public static Bundle CreateJs(this IBundleManager bundleManager, string bundleName, params string[] paths)
 {
     return(bundleManager.Create(bundleName, WebFileType.Js, paths));
 }