chore: add node toolchain + esbuild config
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.
This commit is contained in:
parent
6dbdc2d408
commit
ef4c7f40b0
3 changed files with 152 additions and 0 deletions
9
.gitignore
vendored
9
.gitignore
vendored
|
|
@ -6,6 +6,15 @@ src/*/obj/
|
||||||
test/*/bin/
|
test/*/bin/
|
||||||
test/*/obj/
|
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
|
# Exclure les caches lourds
|
||||||
**/.playwright/
|
**/.playwright/
|
||||||
.git/
|
.git/
|
||||||
|
|
|
||||||
113
esbuild.config.mjs
Normal file
113
esbuild.config.mjs
Normal file
|
|
@ -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);
|
||||||
|
});
|
||||||
30
package.json
Normal file
30
package.json
Normal file
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue