Building DataTables
DataTables is essentially one large Javascript file, but its source is split into manageable individual files that are combined to create the main library file. This is DataTables build process and if you'd like to modify DataTables from source you'll need to go through this process.
Environment and software
The DataTables build process is supported on Mac, Linux and Windows (WSL). The following software is required to be able to build DataTables:
- Bash
- Node.js
- PHP 7+
Obtaining the source
The DataTables source is available on GitHub which means obtaining the code is as simple as:
git clone https://github.com/DataTables/DataTablesSrc.git
You'll then need to install the build dependencies:
cd DataTablesSrc
npm install
Building
To build the code run:
npm run build
The debug
part is optional (which is why it is shown in square brackets). When debug is enabled the minification process using Closure compiler is skipped resulting in faster build times, but no minified file is produced, meaning it is only useful for debugging.
The build process output will look something like:
DataTables build (2.1.4) - branch: master
Deploying to build repo
JS js
Minification - js
File size: 93174
JS mjs
Minification - mjs
File size: 104504
Styling frameworks JS
JS processing dataTables.bootstrap5
Creating ES module
Minification - mjs
File size: 1102
Creating UMD
Minification - js
File size: 1470
Linting UMD
...
Types
Examples
Lint
Pass
Updating package descriptors
Done
Output
The output files (Javascript, CSS, images and examples) are placed into the built/DataTables
directory. To load them in a browser run:
npm run serve
Extensions
DataTables extensions also go through the same build process using this script, although in this case:
./make.sh extension {name} [debug]
where, again debug
is optional and in this case {name}
is the name of the extension. The script will automatically clone the extension from the DataTables repositories and then built it and its examples.
Output
The built extensions are placed into built/DataTables/extensions
where the examples can immediately be run from a localhost.