While I'm not too familiar with Bundles, have a look at the documentation for attaching to events, that happens during the Initialization of Umbraco so hopefully works for you:
using System.Web.Mvc;
using Umbraco.Core;
using Umbraco.Core.Composing;
namespace MyProject.Components
{
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class MyComposer : IUserComposer
{
public void Compose(Composition composition)
{
composition.Components().Append<MyComponent>();
}
}
public class MyComponent : IComponent
{
public MyComponent()
{
}
public void Initialize()
{
AreaRegistration.RegisterAllAreas();
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new StyleBundle("~/bundles/site.css").Include(
"~/css/style.css"
));
}
}
public void Terminate()
{
}
}
}
Just delete MyComponent, else there will be a return null error:
using NAMESPACE.App_Start;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Optimization;
using Umbraco.Core;
using Umbraco.Core.Composing;
namespace NAMESPACE.Components
{
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class MyComposer : IUserComposer
{
public void Compose(Composition composition)
{
composition.Components().Append<BundleComponent>();
}
}
public class BundleComponent : IComponent
{
public void Initialize()
{
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
public void Terminate()
{
}
}
}
Also place bundleconfig in APP START
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Optimization;
namespace NAMESPACE.App_Start
{
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new StyleBundle("~/bundles/css").Include(
"~/css/screen.css"));
bundles.Add(new ScriptBundle("~/bundles/app").Include(
"~/_publish/scripts/app.js"));
}
}
}
OnApplicationStarted Umbraco 8
How do I register bundle config on application started in Umbraco 8?
Before in Umbraco 7 I used this:
Thanks,
Josefine
While I'm not too familiar with Bundles, have a look at the documentation for attaching to events, that happens during the Initialization of Umbraco so hopefully works for you:
https://our.umbraco.com/documentation/Implementation/Composing/#example---creating-a-component-to-listen-for-contentservicesaving-events
Example code could look a bit like:
Thanks a lot! :)
Regards Josefine
Just delete MyComponent, else there will be a return null error:
Also place bundleconfig in APP START
Remember webconfig:
is working on a reply...