Back to Ntopng

Frontend Development (Javascript/Vue/CSS)

doc/README.frontend.md

6.62.1 KB
Original Source

Frontend Development (Javascript/Vue/CSS)

The ntopng frontend is compiled with Vite. All source lives in http_src/ and assets/; the compiled output goes to httpdocs/dist/ and must be committed alongside code changes.


1. Prerequisites

Node.js ≥ 18.15.0 is required.


2. Install dependencies

Run once after cloning (or after package.json changes):

bash
npm install

3. Daily development, watch mode

Rebuilds ntopng.js automatically on every file save under http_src/:

bash
npm run watch

Watch mode rebuilds only the Vue app bundle (ntopng.js + ntopng.css). Run npm run build once first to produce third-party.js, CSS themes, images, and login.js — watch mode then preserves those files between rebuilds.


4. Build commands

CommandWhen to use
npm run buildFull production build (JS + CSS + assets, minified)
npm run build:devFull development build (unminified, with sourcemaps)
npm run build:ntopngjsRebuild ntopng.js only (fast, preserves rest of dist)

All commands output to httpdocs/dist/. Commit the dist output before opening a pull request.


5. What gets built

npm run build / npm run build:dev runs build.mjs which executes five sequential Vite passes, each producing a self-contained IIFE:

Output fileSource
third-party.js + third-party.cssassets/third-party.js (jQuery, Bootstrap, DataTables, …)
ntopng.js + ntopng.csshttp_src/ntopng.js (Vue app + SCSS)
dark-mode.css / white-mode.css / custom-theme.cssTheme SCSS files
images/flags.png, images/blank.gif, etc.assets/images/images.js
login.jsassets/scripts/login.js (particle animation)

All bundles are plain IIFEs loaded as type="application/javascript" (classic blocking scripts). third-party.js must load first — it sets window.$, window.moment, and other globals that ntopng.js depends on.


6. Linting

bash
npm run css:lint   # SCSS linting (stylelint)
npm run js:lint    # JS linting (eslint)