checktheroads 0b80d85c6c #6797: Fix API select styles 4 лет назад
..
dist 0b80d85c6c #6797: Fix API select styles 4 лет назад
docs 7058d6ca5a Closes #6328: Local docs build (#6769) 4 лет назад
img ce98957be0 remove old files 4 лет назад
src 0b80d85c6c #6797: Fix API select styles 4 лет назад
styles 0b80d85c6c #6797: Fix API select styles 4 лет назад
.eslintignore 0572d03003 Migrate from ParcelJS to esbuild for UI bundling 4 лет назад
.eslintrc 6fe2f83435 scaffold new ui directory 5 лет назад
.prettierignore 0572d03003 Migrate from ParcelJS to esbuild for UI bundling 4 лет назад
.prettierrc 6fe2f83435 scaffold new ui directory 5 лет назад
.sassrc 6fe2f83435 scaffold new ui directory 5 лет назад
README.md 0572d03003 Migrate from ParcelJS to esbuild for UI bundling 4 лет назад
bundle.js bf2d535356 Fix incorrect rack elevation file name regression from 0572d03 4 лет назад
package.json 0572d03003 Migrate from ParcelJS to esbuild for UI bundling 4 лет назад
tsconfig.json 2b159fc40f implement dark mode 4 лет назад
yarn.lock 0572d03003 Migrate from ParcelJS to esbuild for UI bundling 4 лет назад

README.md

NetBox UI Development

Introduction

The following tools and languages are used during the build process:

Languages

Sass

Sass is similar to CSS, but has variables, functions, utilities, mixins, and other nice syntax additions. With Sass, we can import Bootstrap's Sass files, override or extend variables, and add classes of our own using Bootstrap's variables (as well as other CSS libraries used).

TypeScript

TypeScript is a strict static-typed superset of JavaScript. In development, it's an extremely effective tool for accurately describing and checking the code, which leads to significantly fewer bugs, a better development experience, and more predictable/readable code.

Tools

esbuild

esbuild is a bundling tool that takes given input files of most front-end languages (Sass and TypeScript, in our case), follows each of their dependencies (via import statements), and bundles them into a single minified file.

For JavaScript, every .ts file in netbox/project-static/src is:

  1. Transpiled from TypeScript to JavaScript
  2. Minified
  3. Combined into a single output file at netbox/project-static/dist/netbox.js (this includes any dependant libraries imported in a file)

Likewise, with Sass, every .scss file in netbox/project-static/styles is:

  1. Transpiled from Sass to CSS
  2. Minified
  3. Combined into a single output file at netbox/project-static/dist/netbox.css (this includes any dependant libraries imported in file)

For pre v4 releases, this process will be run in development, and the files in netbox/project-static/dist checked into change control. This is because running Parcel (and installing dependencies via NPM/Yarn, as described below) requires other system dependencies like NodeJS and Yarn, which aren't part of the current v2 dependency list.

Yarn

Yarn is a package manager (think pip in the Python world) for JavaScript packages on the NPM registry (think PyPI in the Python world). Technically, one could simply use NPM's own npm tool as well, however, yarn is widely used because it tends to be significantly faster than npm (and has other cool features, which we aren't using in NetBox).

Installation

NodeJS

If you don't already have it, install NodeJS (the LTS release should be fine).

Yarn

Next, install Yarn:

npm install -g yarn

NetBox Dependencies

From netbox/project-static, run the command yarn — this will install all production and development dependencies to netbox/project-static/node_modules.

Creating dist files

After any changes to TypeScript or Sass files, you'll need to recompile/bundle the dist files.

To bundle only CSS files, run:

# netbox/project-static
yarn bundle:styles

To bundle only JS files, run:

# netbox/project-static
yarn bundle:scripts

Or, to bundle both, run:

# netbox/project-static
yarn bundle

Note: if you're running the development web servermanage.py runserveryou'll need to run manage.py collectstatic to see your changes.