RequireJS compilation UglifyJS optimization - fruitflybrain/ffbo.neuronlp GitHub Wiki
Given file structure
.
├── NeuroNLP
│ ├── img
│ ├── index.html
│ ├── js
│ │ ├── NeuroNLP.js
│ │ └── app.build.js
│ └── lib
├── NeuroNLP-build
├── node_modules
│ └── uglify-es
│ └── bin
│ └── Uglify.js
└── r.js
We first compile scriptrs in NeuroNLP
to NeuroNLP-build
without optimization as follows:
cd NeuroNLP/js/
node ../../r.js -o app.build.js
The content of app.build.js
will configure the compilation process, see next section for details.
We then minify the output js file in the NeuroNLP-build/js
folder as follows:
cd ../NeuroNLP-build/
../node_modules/uglify-es/bin/uglifyjs ./js/NeuroNLP.js -c -o ./js/NeuroNLP.min.js
The resulting folder should be as follows:
.
├── NeuroNLP
│ ├── img
│ ├── index.html
│ ├── js
│ │ ├── NeuroNLP.js
│ │ └── app.build.js
│ └── lib
├── NeuroNLP-build
│ ├── build.txt
│ ├── img
│ ├── index.html
│ └── js
│ ├── NeuroNLP.js // compiled file
│ └── NeuroNLP.min.js // minified fill
├── node_modules
│ └── uglify-es
│ └── bin
│ └── Uglify.js
└── r.js
app.build.js
content to configure requireJS compilation
({
appDir: "../", // application directory, everything is with respect to this directory
baseUrl: "js", // folder that contains the module
dir: "../../NeuroNLP-build", // output folder
waitSeconds: 180, // compilation wait time required for large files
modules: [ // modules to be compiled in the baseUrl folder
{
name: "NeuroNLP", // this mean 'appDir/baseUrl/NeuroNLP.js'
}
],
optimize: "none", // do no minify with requireJS, use UglifyJS instead
mainConfigFile: 'NeuroNLP.js' // Configurations for requireJS are also stored in NeuroNLP.js
})