From ef4c7f40b0adb717fb876413dd53559bc538de8b Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 14 Jun 2026 12:32:06 +0100 Subject: [PATCH] chore: add node toolchain + esbuild config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pose les fondations du bundle front unique : - package.json : deps npm (jQuery, jQuery UI, jQuery plugins, Bootstrap 5, SignalR, Moment, Quill, Showdown, To-markdown, Dropzone, eonasdan-datetimepicker) + esbuild. - esbuild.config.mjs : produit src/Yavsc.Org/wwwroot/js/site.bundle.min.js à partir des .js à nous + des libs npm. - .gitignore : exclut node_modules/, wwwroot/lib/, et les *.min.js sous wwwroot/js (générés au build, non versionnés). Le bundle généré sera commité au commit suivant pour que le runtime .NET n'ait pas besoin de node au publish time. --- .gitignore | 9 ++++ esbuild.config.mjs | 113 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 30 ++++++++++++ 3 files changed, 152 insertions(+) create mode 100644 esbuild.config.mjs create mode 100644 package.json diff --git a/.gitignore b/.gitignore index 1712bcc2..33d14ced 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,15 @@ src/*/obj/ test/*/bin/ test/*/obj/ +# Toolchain front (Node / esbuild) +node_modules/ + +# Libs tierces servies par ASP.NET — restaurées via npm + esbuild +src/Yavsc.Org/wwwroot/lib/ +# Versions .min des libs tierces dans wwwroot/js (elles ne sont plus +# versionnées ; la minification est faite par esbuild au build) +src/Yavsc.Org/wwwroot/js/*.min.js + # Exclure les caches lourds **/.playwright/ .git/ diff --git a/esbuild.config.mjs b/esbuild.config.mjs new file mode 100644 index 00000000..7b370d2f --- /dev/null +++ b/esbuild.config.mjs @@ -0,0 +1,113 @@ +// Yavsc front-end bundle config (esbuild). +// +// Produces a single minified bundle at +// src/Yavsc.Org/wwwroot/js/site.bundle.min.js +// that contains both our application code and the third-party libs we +// keep under npm. The bundle is committed to the repo so the .NET +// runtime does not need a node toolchain at publish time. +// +// Usage: +// npm install +// npm run build:js # one-shot +// npm run build:js:watch # rebuild on change +// npm run clean:js # remove the generated bundle + +import { build, context } from 'esbuild'; +import { existsSync, mkdirSync, statSync } from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); + +const isWatch = process.argv.includes('--watch'); + +const outFile = path.resolve( + __dirname, + 'src/Yavsc.Org/wwwroot/js/site.bundle.min.js' +); + +const outDir = path.dirname(outFile); +if (!existsSync(outDir)) { + mkdirSync(outDir, { recursive: true }); +} + +// --- Our code (entry points) -------------------------------------------- +// `site.js` is the bootstrap loaded by _Layout.cshtml. We list every +// .js we own as an entry point so they all end up in the same bundle. +const ourEntries = [ + 'src/Yavsc.Org/wwwroot/js/site.js', + 'src/Yavsc.Org/wwwroot/js/chat.js', + 'src/Yavsc.Org/wwwroot/js/comment.js', + 'src/Yavsc.Org/wwwroot/js/signout-redirect.js', + 'src/Yavsc.Org/wwwroot/js/input-lib.js', + 'src/Yavsc.Org/wwwroot/js/google-geoloc.js', + 'src/Yavsc.Org/wwwroot/js/audiovideoinput.js', + 'src/Yavsc.Org/wwwroot/js/yavsc-remote-fs.js', +]; + +// --- Third-party code we want bundled ---------------------------------- +// Listed by npm package name; resolved via node_modules. +// jQuery, jQuery UI, jQuery plugins, Bootstrap JS bundle, SignalR +// (browser), Moment, Quill, Showdown, To-markdown, Dropzone. +const vendorEntries = [ + 'jquery/dist/jquery.min.js', + 'jquery-ui/dist/jquery-ui.min.js', + 'jquery-validation/dist/jquery.validate.min.js', + 'jquery-validation-unobtrusive/dist/jquery.validate.unobtrusive.min.js', + 'jquery-timepicker/jquery.timepicker.min.js', + 'jquery-datepair/dist/jquery.datepair.min.js', + 'bootstrap/dist/js/bootstrap.bundle.min.js', + '@microsoft/signalr/dist/browser/signalr.min.js', + 'moment/min/moment.min.js', + 'showdown/dist/showdown.min.js', + 'to-markdown/dist/to-markdown.min.js', + 'dropzone/dist/min/dropzone.min.js', + 'quill/dist/quill.min.js', + // eonasdan is registered as a CommonJS package; esbuild handles it. + 'eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js', +]; + +// Our entry points may live alongside the output, so we exclude the +// outDir from the resolver to avoid bundling the previous run. +const entryPoints = [...ourEntries, ...vendorEntries]; + +const buildOptions = { + entryPoints, + outFile, + bundle: true, + minify: true, + sourcemap: false, + target: ['es2018'], + format: 'iife', + legalComments: 'none', + logLevel: 'info', + // jQuery plugins attach themselves to jQuery; we must not shim it. + alias: {}, + nodePaths: ['node_modules'], + loader: { + '.js': 'js', + }, +}; + +async function run() { + if (isWatch) { + const ctx = await context(buildOptions); + await ctx.watch(); + console.log(`[esbuild] watching → ${path.relative(__dirname, outFile)}`); + } else { + const result = await build(buildOptions); + if (result.errors.length) { + process.exitCode = 1; + } else { + const size = statSync(outFile).size; + console.log( + `[esbuild] wrote ${path.relative(__dirname, outFile)} (${size} bytes)` + ); + } + } +} + +run().catch((err) => { + console.error(err); + process.exit(1); +}); diff --git a/package.json b/package.json new file mode 100644 index 00000000..974c4ea0 --- /dev/null +++ b/package.json @@ -0,0 +1,30 @@ +{ + "name": "yavsc", + "version": "0.0.0", + "private": true, + "description": "Yavsc front-end toolchain (esbuild bundle for Yavsc.Org).", + "scripts": { + "build:js": "node esbuild.config.mjs", + "build:js:watch": "node esbuild.config.mjs --watch", + "clean:js": "rm -f src/Yavsc.Org/wwwroot/js/site.bundle.min.js" + }, + "dependencies": { + "@microsoft/signalr": "^8.0.7", + "bootstrap": "^5.3.3", + "dropzone": "^5.9.3", + "eonasdan-bootstrap-datetimepicker": "^0.0.7", + "jquery": "^3.7.1", + "jquery-datepair": "^1.2.0", + "jquery-timepicker": "^1.3.3", + "jquery-ui": "^1.13.3", + "jquery-validation": "^1.20.0", + "jquery-validation-unobtrusive": "^4.0.0", + "moment": "^2.30.1", + "quill": "^1.3.7", + "showdown": "^2.1.0", + "to-markdown": "^8.0.0" + }, + "devDependencies": { + "esbuild": "^0.24.0" + } +}