alamode
alamode
is a RegExp-based transpiler of source code in Node.js. It is a fast, low-weight alternative to AST-based transpilers, such as @babel
.
yarn add -DE alamode
Table Of Contents
Installation
The software can be installed either as a global dependency, or as a project dependency.
Global
When installed globally, it will be used directly via a binary, such as alamode src -o build
.
Package Manager | Installation |
---|
npm | npm i -g alamode |
yarn | yarn add global alamode |
Project
When installed in a project, it will be used via the package.json
script, e.g., yarn build
or npm run build
.
// package.json
{
"name": "project",
"version": "1.0.0",
"description": "An example project",
"main": "build",
"scripts": {
"build": "alamode src -o build"
},
"files": ["build"],
"license": "MIT"
}
Package Manager | Installation |
---|
npm | npm i --save-dev alamode |
yarn | yarn add -DE alamode |
CLI
The binary accepts a path to a single file, or a directory with the source code as the first argument, and a path to the build folder via -o
argument.
alamode src -o build
There are other arguments which can be passed.
Property | Argument | Description |
---|
Output Location | -o , --output | Where to save transpiled code. Passing - will print to stdout . |
Watch Mode | -w , --watch | Keep alamode running and re-build on chages. |
Show Help | -h , --help | Display help information and quit. |
Show Version | -v , --version | Display version number and quit. |
Setting the NODE_DEBUG
environmental variable to alamode
will print the list of processed files to the stderr
.
$ NODE_DEBUG=alamode alamode src -o build
ALAMODE 97955: index.js
ALAMODE 97955: bin/catcher.js
ALAMODE 97955: bin/index.js
ALAMODE 97955: bin/register.js
ALAMODE 97955: lib/index.js
Transforms
There are a number of built-in transforms, which don't need to be installed separetely because their size is small enough to be included as direct dependencies.
@a-la/import
Changes all import
statements into require
statements. Although the specification between the ECMAScript Modules and Modules is different, most developers will prefer to use import
just because of its neater syntax.
import argufy from 'argufy'
import restream, {
Replaceable,
makeMarkers, makeCutRule, makePasteRule,
} from 'restream'
import { resolve, join } from 'path'
import { version } from '../../package.json'
let argufy = require('argufy'); if (argufy && argufy.__esModule) argufy = argufy.default;
let restream = require('restream'); if (restream && restream.__esModule) restream = restream.default;
const {
Replaceable,
makeMarkers, makeCutRule, makePasteRule,
} = restream
const { resolve, join } = require('path')
const { version } = require('../../package.json')
The if (dependency && dependency.__esModule) dependency = dependency.default;
check is there to make alamode
compatible with babel
, which will export default modules in the default
property of module.exports
object and add the __esModule
marker.
@a-la/export
Transforms all export
statements into module.exports
statements.
export async function example () {}
const example2 = () => {}
export default class Example {
constructor() {
example()
}
}
export { example2 as alias }
async function example () {}
const example2 = () => {}
class Example {
constructor() {
example()
}
}
module.exports = Example
module.exports.example = example
module.exports.alias = example2
There are some limitations one should be aware about, however they will not typically cause problems for a Node.JS package.
Copyright
(c) À La Mode 2018