Link Search Menu Expand Document

Compiling Lego component is built-in with no extra installation; pretty straighforward.

npx lego [-w] [source_path] [target_path]
  • -w: watching for changes in components and recreating
  • source_path: (default: ./bricks) either a file or a directory (relative or absolute) where you write your HTML components. If it’s a directory, it will recursively read all the .html files and compile them into the target_file.
  • target_path: (default: ./dist) the path (relative or absolute) where your JS components will be generated. That folder will be created and contain all the components.

Therefore npx lego would compile the source_path files or folder (recursively) into target_file_path js file using lego.min.js (from ./bricks to ./dist by default).

As mentioned before, when developing you probably want to watch for changes with the -w option: npx lego -w <source_path> <target_file_path>

⚠️ the watch (-w) option will refresh the existing components. However in order to refresh the dist/index.js you will need to stop and start the command line or any new component won’t be available!