Complex Applications (e.g., Vite)
To create a more complex Node.js-based client-side application as a rescile module with a build step, follow this standard pattern:
- Initialize the Project: Use a build tool like Vite to manage your application source code.
- Configure the Output Directory:
rescileexpects web assets to be served from theapp/directory. Configure your build tool to output its production build toapp/. - Set Relative Base Paths: Since modules are served under a dynamic subpath, ensure your build tool generates relative asset paths (e.g.,
./). - Create the Manifest: Include a
module.tomlmanifest at the project root to define your module’s identity. - Package the Module: Combine the generated
app/directory and themodule.tomlinto a.ziparchive for distribution.
Example: Vite Configuration
In vite.config.js (or .mjs):
import { defineConfig } from 'vite';
export default defineConfig({
base: './', // 3. Set relative base paths
build: {
outDir: 'app', // 2. Configure output directory
emptyOutDir: true,
},
});
Example: Package Scripts
Automate the build and packaging process in your package.json:
{
"scripts": {
"dev": "vite",
"build": "vite build",
"package": "npm run build && zip -r my-app-module.zip app module.toml"
}
}