dotnet-websharper / core

WebSharper - Full-stack, functional, reactive web apps and microservices in F# and C#
https://websharper.com
Apache License 2.0
589 stars 52 forks source link

Rollup/ESBuild bundling support #1369

Closed Jand42 closed 7 months ago

Jand42 commented 7 months ago

For #1361, bundling STEP 1, WS creates a root.js if a new "preBundle": true config is set, which can be bundled into a bundle.js (these names are hardcoded atm, to be configured better) and then Sitelets runtime will use this. TODO fix C# tests not passing yet.

Look at Web project for a sample how it works. Project file has

<Target Name="RollupBundle" AfterTargets="WebSharperCompile">
    <Exec Command="npx rollup -c" />
</Target>

While rollup.config.mjs has:

export default {
    input: 'wwwroot/Scripts/WebSharper/Web/root.js',
    output: {
        file: 'wwwroot/Scripts/WebSharper/bundle.js',
        format: 'iife',
        name: 'wsbundle'
    }
};
Jand42 commented 7 months ago

Same with esbuild:

import { build } from 'esbuild'

var options =
{
  entryPoints: ['./wwwroot/Scripts/WebSharper/Web/root.js'],
  bundle: true,
  minify: true,
  format: 'iife',
  outfile: 'wwwroot/Scripts/WebSharper/bundle.js',
  globalName: 'wsbundle'
};

build(options);