Configuration Object - lewie9021/node-compiler GitHub Wiki
The configuration object is a required part of the compiler and controls how it should behave. The compiler can obtain the configuration via an object literal or via a path to a JSON file. The root of the configuration object is rather simple. The 'name' property defines the name of the project while the 'directory' property is an absolute path to the root of the project (note: other paths defined within the configuration object will base their value from this path).
{
"name": "My Project",
"directory": "C:\\Development\\MyProject",
"modes": [
{..},
{..}
],
"profiles": [
{..},
{..}
]
}
Modes
A project may require more than ones compilation mode. This may be the case when publishing your application live. You may choose to minify your code in a 'live' mode whereas in development, you may want the code to be readable for debugging purposes. An example of a mode can be found below:
{
"id": "dev",
"name": "Development",
"profiles": ["js", "dust", "sass"]
}
The 'id' property is a unique identifier within the project to allow reference when instantiating the compiler. 'name' is currently only used for debugging purposes and can be found within the logs. The 'profiles' property is an array of profile IDs that dictates what profiles should be compiled when the mode is used. In the snippet above, profiles 'js', 'dust', and 'sass' will be used.
Profiles
A profile acts as a wrapper for targets and configures how they are outputted.
{
"id": "js",
"name": "JavaScript",
"output": "public\\app",
"targets": [
{..},
{..}
]
}
The 'id' property is unique and used for reference via compilation modes. 'name' is used for debugging purposes when a compile error occurs. The 'output' property dictates how targets should render the compiled output. The value can either be a path to a directory or file (note: if the path doesn't exist, the required directories will be automatically created). An output path that points to a file will cause the profile to switch to concatenation mode. This means that each file that is compiled within the target(s) will be appended to the single output file. However if the path is a directory, files will be kept individual but a path relative to the target directory. For example a file with the path 'C:\Development\MyProject\src\js\core\app.js' will become 'C:\Development\MyProject\public\js\core\app.js'.
Targets
Targets are contained by Profiles. They are responsible for watching/compiling directories. When a file is added, changed, or deleted within the watched directory, itโs profile will be notified causing the file to be recompiled, cached, and outputted.
{
"directory": "src\\js",
"watch": true,
"ignore": [
"ignore-me.js"
],
"plugin": {..}
}
The 'directory' property defines the path to watch/compile. 'watch' is an option property that dictates whether or not to watch the directory after the initial compile. 'ignore' is a another optional property that is an array of file paths relative to the target's 'directory' property. These files will be ignored when watching/compiling.
Plugins
Plugins define how target files are compiled. The 'name' property is the name of the plugin/integration you wish to use for the target directory. A full list of supported plugins/integrations and their possible options can be found within the 'integrations' Wiki article. 'options' is an optional property that is an object containing key-value pairs that dictate how the plugin should behave. In the snippet below, I've configured the plugin to compile .js files in a minified format with a comment above each file containing it's original path.
{
"name": "JS",
"options": {
"minify": true,
"paths": true
}
}