alloy-compiler
Compiler for Alloy components
This packages contains the standalone Alloy compiler. In most cases you should be using it in Webpack powered Alloy projects, you will only need it separately if you are writing build tools with very specific needs.
Installation
npm i alloy-compiler
Usage
const { createCompiler, createCompileConfig } = require('alloy-compiler');
API
createCompiler(options)
Creates a new Alloy compiler instance.
Example
const { createCompiler } = require('alloy-compiler');
const compiler = createCompiler({
compileConfig: {
projectDir: '/path/to/my/project',
alloyConfig: {
platform: 'ios',
deploytype: 'development'
}
},
webpack: true
});
Options
Expects an options
object with the following properties:
-
compileConfig
Configuration that will be passed to the Alloy compiler.
You can either pass an object returned by createCompileConfig
or directly pass the same options accepted by that function. The config object will then be created from the passed options.
-
webpack
- Type:
boolean
- Default:
false
Whether or not to create a special compiler instance that creates optimized output Webpack.
createCompileConfig(options)
Creates a new Alloy compile configuration based on the passed options.
Example
const { createCompileConfig } = require('alloy-compiler');
const compileConfig = createCompileConfig({
projectDir: '/path/to/my/project',
alloyConfig: {
platform: 'ios',
deploytype: 'development'
}
});
Parameters
Expects an options
object with the following properties:
-
projectDir
Path to the root directory of the Alloy project.
-
alloyConfig
Alloy configuration. Expects an object
with the following structure:
{
platform: string
deploytype: string
}
-
logLevel
Log level for the internal logger.
-
buildLog
- Type:
BuildLog
- Default:
BuildLog
for the specified projectDir
compiler.compileComponent(options)
Compiles the controller and view of an Alloy component.
Returns a result object with the following structure:
{
code: string,
map: object,
dependencies: array
}
Example
const { createCompiler } = require('alloy-compiler');
const compiler = createCompiler({
compileConfig: {
projectDir: '/path/to/my/project',
alloyConfig: {
platform: 'ios',
deploytype: 'development'
}
}
});
const result = compiler.compileComponent({
file: '/path/to/my/project/app/controllers/index.js'
});
Parameters
Expects an options
object with the following properties:
-
file
Full path to the controller or view file that should be compiled. The compiler will automatically look for all possible associated files of the component (controller/view/style) and process them.
-
content
Content of file
, if already known. The compiler will automatically read the file
's content if this is omitted.
-
inputSourceMap
Input source map. The compiler will create a new source map if this is omitted.