To give you some context, I'm working on a .NET core app, and in one of the cshtml I'm injecting a react mini app like this:
<div id="workshop" data-id=@Model></div>
<script src="~/bundles/js/workshop-bundle.js"></script>
It was working well, but when I compile with webpack, the workshop bundle was too big (800kb) and I was receiving a warning. The workshop-bundle was including some dependencies, like axios, highcharts-react-official and highcharts/highmaps. So I tried to split the bundles.
On the webpack.config.js I'm trying to use DependOn in one of the entries. In this case, the workshop depends on axios, highcharts-react-official and highcharts/highmaps, so based on the webpack doc I tried this:
webpack.config.js
entry: {
workshop: {
import: "./wwwroot/component/WorkshopApp.tsx",
dependOn: ["axios", "highmaps", "highchartreact"],
},
highchartreact: "highcharts-react-official",
highmaps: "highcharts/highmaps",
axios: "axios",
},
.cshtml:
<div id="workshop" data-id=@Model></div>
<script src="~/bundles/js/axios-bundle.js"></script>
<script src="~/bundles/js/highchartreact-bundle.js"></script>
<script src="~/bundles/js/highmaps-bundle.js"></script>
<script src="~/bundles/js/workshop-bundle.js"></script>
It generates the 4 bundles, but the app is not displayed and I'm not getting any error.
However, if I put the dependencies in one entry, it works well:
webpack.config.js
entry: {
workshop: {
import: "./wwwroot/component/WorkshopApp.tsx",
dependOn: ["workshopVendor"],
},
workshopVendor: [
"axios",
"highcharts-react-official",
"highcharts/highmaps",
],
},
.cshtml:
<div id="workshop" data-id=@Model></div>
<script src="~/bundles/js/workshopVendor-bundle.js"></script>
<script src="~/bundles/js/workshop-bundle.js"></script>
This is not a solution, because I want the dependencies in separate bundles, any idea? Thanks in advance!