alloy-compiler

raw JSON →
0.2.7 verified Fri May 01 auth: no javascript

Compiler for Appcelerator Titanium Alloy components, enabling standalone compilation of controllers and views. Current version 0.2.7, updated periodically. Unlike the full Alloy CLI, this package can be integrated into custom build toolchains, including Webpack-based setups. It provides createCompiler and createCompileConfig functions for programmatic use, with support for platform-specific output and source maps. Requires Node >=10.

error TypeError: createCompiler is not a function
cause Wrong import pattern (e.g., import instead of require for CommonJS module).
fix
Use const { createCompiler } = require('alloy-compiler');
error TypeError: compiler.compileComponent is not a function
cause Attempted to import compileComponent directly from package instead of calling it on a compiler instance.
fix
First create compiler with createCompiler, then call compiler.compileComponent().
error Error: "projectDir" is required
cause createCompileConfig or createCompiler called without projectDir in options.compileConfig.
fix
Add projectDir to the options object: { compileConfig: { projectDir: '/path' } }
gotcha The package uses CommonJS; direct ESM imports may fail in Node.js versions that support ES modules.
fix Use require() or transpile with a bundler like Webpack.
gotcha createCompiler requires compileConfig option even if you pass webpack: true.
fix Always provide compileConfig object with projectDir and alloyConfig.
gotcha compileComponent expects file path; if the file does not exist and content is not provided, it will throw.
fix Ensure the file exists or provide content option.
npm install alloy-compiler
yarn add alloy-compiler
pnpm add alloy-compiler

Shows basic usage to compile an Alloy controller using createCompileConfig and createCompiler.

const { createCompiler, createCompileConfig } = require('alloy-compiler');

const compileConfig = createCompileConfig({
  projectDir: '/path/to/project',
  alloyConfig: {
    platform: 'ios',
    deploytype: 'development'
  }
});

const compiler = createCompiler({
  compileConfig,
  webpack: false
});

const result = compiler.compileComponent({
  file: '/path/to/project/app/controllers/index.js'
});

console.log(result.code);