asp.net-core-mvcreactjsreactjs.netcassette

Add ScriptBundle in Cassette wont work


I'm trying to bundle my JSX-files in a asp.net core applikation, but i can't get anything to work... I'm also using ReactJS.NET. At the moment I'm using Cassette to bundle me files and I have followed this guide + the guides on Cassette's own site without luck. It also says in the guide, that a CassetteConfiguration.cs-file should be created, when the React.Cassette NuGet package was installed - this didn't happen, so i created my own CassetteConfiguration.cs-file and it looks like this:

namespace ReactNewTest
{
    public class CassetteBundleConfiguration : IConfiguration<BundleCollection>
    {
        public void Configure(BundleCollection bundles)
        {
            // Configure your bundles here...
            // Please read http://getcassette.net/documentation/configuration

            bundles.Add<ScriptBundle>("main.js", "js/tutorial.jsx", "js/guide.jsx");
        }
    }
}

After this I'm trying to send it to my view - Index.cshtml - and the code in the view looks like this:

@using Cassette.Web
@using Cassette
@using Cassette.Views
@using Cassette.Aspnet
@using Cassette.BundleProcessing
@using Cassette.React
@{
    Layout = null;
    Bundles.Reference("main.js");
}
<html>
<head>
    <title>Hello React</title>
</head>
<body>
    <div id="content"></div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/remarkable/1.7.1/remarkable.min.js"></script>
    @Bundles.RenderScripts()
</body>
</html>

I have also edited the _ViewImports.csHtml to this:

@using React.AspNet
@using ReactNewTest
@using Cassette.React
@using System.Web.Optimization
@using Cassette.Views
@using Cassette
@using Cassette.Aspnet
@using Cassette.BundleProcessing

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@inject Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration TelemetryConfiguration

When I try to run it, it just gives me this NullReferenceException.

I have now tried for days to get this bundleing to work in my asp.net core applikation, but I can't get anything to work... All the documentation is old and leads to the same tutorial wich is 2 years old..

I have tried to bundle with asp.net core's own bundleing, Babel, Webpack ad now Cassette without getting anything to work, and it drives me crazy!

I really hope that someone can help me out with this bundleing.


Solution

  • Cassette is not compatible with ASP.NET Core, and the bundler and minifier that comes with ASP.NET Core (https://github.com/madskristensen/BundlerMinifier) isn't extensible so JSX compilation can't be added to it. You could try using Gulp or Webpack instead.