Meta Spark Studio TypeScript Bundler
sparkar-bundler is a command-line interface (CLI) tool designed to bundle TypeScript projects specifically for use within Meta Spark Studio. It leverages `esbuild` for high-performance bundling, enabling developers to write Spark AR scripts in TypeScript while benefiting from features like IntelliSense for both Meta Spark API definitions and external Node.js modules. This tool aims to streamline the development workflow by abstracting away complex bundling configurations. Currently at version 0.3.0, it is in active development with a focus on providing a seamless experience for integrating modern JavaScript/TypeScript practices into the Spark AR ecosystem. Its primary differentiator is the specialized handling of Meta Spark API type definitions, which is crucial for developer tooling in a proprietary environment. The release cadence is currently irregular as it's an early-stage project.
Common errors
-
'sparkar-bundler' is not recognized as an internal or external command, operable program or batch file.
cause The package was not installed globally, or the global `node_modules` bin directory is not in your system's PATH.fixEnsure you install the package globally using `npm install -g sparkar-bundler`. Verify your PATH includes the global npm bin directory. -
Error: Could not find a suitable script target in the project.
cause The bundler could not locate a JavaScript file within your Spark AR project's `scripts/` directory that is referenced in the `.arproj` file. Or you did not save the empty JavaScript file after creation in Meta Spark Studio.fixOpen your Meta Spark Studio project, create a new JavaScript script (e.g., `script.js`), save the project, and ensure the script is referenced in the project's properties. Then rerun `sparkar-bundler`. -
TypeScript compilation error: Cannot find module 'module-name' or its corresponding type declarations.
cause The TypeScript source code imports a module that is not installed in the project's `node_modules` or does not have corresponding type definitions.fixInstall the missing module using `npm install module-name` and, if necessary, its type definitions with `npm install --save-dev @types/module-name`.
Warnings
- breaking As a pre-1.0 release (v0.3.0), the CLI arguments, configuration file format, and internal project structure assumptions are subject to frequent and breaking changes without prior notice. Backwards compatibility is not guaranteed between minor or even patch versions.
- gotcha The bundler relies on specific Meta Spark Studio project structures and behaviors. Future updates to Meta Spark Studio could introduce incompatibilities, potentially breaking the bundling process or the execution of bundled scripts.
- gotcha For IntelliSense to work correctly with Meta Spark API, the tool resolves specific type definitions. If these definitions change significantly in a Meta Spark Studio update, IntelliSense might become inaccurate or break until the bundler is updated.
Install
-
npm install sparkar-bundler -
yarn add sparkar-bundler -
pnpm add sparkar-bundler
Imports
- sparkar-bundler
npm install -g sparkar-bundler
Quickstart
npm install -g sparkar-bundler # Navigate into your Meta Spark Studio project directory cd ~/mySparkProject # Ensure you have an empty JavaScript file saved in Spark AR Studio # (e.g., scripts/script.js, ensure it's referenced in the project) # Run the bundler, it will guide you to select the target script sparkar-bundler # The bundled output (e.g., main.js) will be written to your selected script file. # You should see 'hello, world' (or your script's output) in Meta Spark Studio console.