The following are currently supported methods of installing Lucy.
curl -sSf https://lucy.spooky.click/install.sh | bash
This will install the lucyc binary to your $HOME/.lucy folder. Open a new terminal and run:
lucyc --help
Then compile a Lucy file to a JavaScript module with:
lucyc --out-file toggle.js toggle.lucy
The installer downloads the latest release, which predates the plain JavaScript compiler that these docs describe and still outputs XState machines. Until the next release, you can build
lucycfrom source withmake bin/lucyc; see Contributing.
The compiler is also available as a JavaScript package, @lucy/liblucy, which runs the compiler as WebAssembly in Node.js or the browser. This is what build tool plugins use, and you can use it directly:
npm install @lucy/liblucy
import { ready, compile } from '@lucy/liblucy';
await ready;
const { js } = compile(source, 'toggle.lucy');
compile(source, filename, options) returns an object whose js is the compiled module. Pass { dts: true } as the options to also get TypeScript declarations as dts (experimental). If the source doesn't compile, compile prints the errors to the console and throws an error whose diagnostics lists them, each with a severity, message, line and column.
As with the installer, the version of
@lucy/liblucyon npm is older and has a different API (compileXstate).compilewill be there in the next release.
Lucy is available for the following build tools:
These plugins haven't been updated for the plain JavaScript compiler yet. They use an older version of liblucy, so they produce XState machines rather than the output described in these docs.
Snowpack users can use the @lucy/snowpack-plugin package to load .lucy files.
First install the plugin:
npm install @lucy/snowpack-plugin
Then add it to your snowpack.config.js configuration in the plugins section like so:
module.exports = {
// ... Other configuration
plugins: [
'@lucy/snowpack-plugin'
]
};
Rollup users can use the @lucy/rollup-plugin package to load .lucy files. Install the plugin:
npm install @lucy/rollup-plugin --save-dev
And use it in your Rollup config:
rollup.config.mjs
import lucy from '@lucy/rollup-plugin';
export default ({
input: 'entry.js',
plugins: [lucy()],
output: [{
file: 'bundle.js',
format: 'es'
}]
});
Vite supports Rollup plugins out of the box, so you can use the @lucy/rollup-plugin package in a Vite project.
Install:
npm install @lucy/rollup-plugin --save-dev
And in your config:
vite.config.mjs
import lucy from '@lucy/rollup-plugin';
export default {
plugins: [
lucy()
]
}