0.1.16 • Published 12 months ago
live-elements-js-compiler v0.1.16
Live Elements Js Compiler
This compiler translates live elements code into javascript module files.
Install
Using npm:
npm i live-elements-js-compilerUsage
This module exports a single function which does the translation:
const {compile} = require("live-elements-js-compiler");
compile(pathToLvFile, options, callback)The
pathToLvFileis the absolute path to an lv file. All of the file module dependencies will automatically be compiled, and all of it's imports paths will be resovled as well.The
optionsis an object with the following properties:baseComponentis the base component name. By default, this should beBaseElement.baseComponentPathis the import path to the base component. By default, this should belive-elements-core/baseelement.jsimplicitTypesare the implicit types that don't need importing inside the lv files.importLocalPathis the default import path for other lv packages.packageBuildPathis the build path for each package, where all thejsmodules are build.outputExtensionis the output extension for each of thejsmodule files. By default, this ismjslogis an object defining log options. (i.e.log: { level: "verbose" }))
The
callbackis a function with 2 arguments, aresult, which is the path to the compiled js file, and anerrorobject, which is a data object containing different parameters depending on the error that was generated.
This is an example on how to use the compiler:
const {compile} = require("live-elements-js-compiler");
const options = {
baseComponent : "BaseElement",
baseComponentPath : "live-elements-core/baseelement.js",
implicitTypes : ["document", "Error", "Object", "Math"],
importLocalPath : "node_modules",
packageBuildPath : "build",
outputExtension : "mjs"
}
compile('main.lv', options, (result, err) => {
if ( err ){
console.log("Error:" + err.message)
return
}
console.log("Compiled file at: " + result)
})