NetJs.Compiler
1.0.10
dotnet tool install --global NetJs.Compiler --version 1.0.10
dotnet new tool-manifest
dotnet tool install --local NetJs.Compiler --version 1.0.10
#tool dotnet:?package=NetJs.Compiler&version=1.0.10
nuke :add-package NetJs.Compiler --version 1.0.10
Build C# into native javascript with official dotnet runtime and aspnetcore support.
USAGE
Enter the directory where the project is and execute dotnet build first to make sure project builds. Then execute NetJs build.
Supports and tested with Sdks Microsoft.NET.Sdk.BlazorWebAssembly, Microsoft.NET.Sdk.Razor, Microsoft.NET.Sdk
NOTES
If building a razor project or any project with source generators, you must have <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> in your PropertyGroup or execute dotnet build -p:EmitCompilerGeneratedFiles=true first.
This ensures that the csharp code files are generated into the obj directory first. They are picked up by NetJs for traspilation.
CODE SIZE AND MINIFICATION
By default, identifiers for namespace, class and members are maintained as is.
Given
namespace Long.Namespace
{
static class LongClassName
{
static void VeryVeryLongMemberName()
{
}
}
}
Accessing VeryVeryLongMemberName will will emit $assembly.Long.Namespace.LongClassName.VeryVeryLongMemberName. This can make the js file heavy.
You can enable name minification using <NetJsBuildFlags>Global,InlineConstants,SingleFile,MinifyNamespaces,MinifyTypeNames,MinifyMemberNames,ShortNamesCreateFromCamelCase</NetJsBuildFlags>
This is now emitted like $assembly.LN.L.V
More details later...
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.