title | layout |
---|---|
Using a local environment |
default |
This guide explains how to set up and run your local development environment for Alokai multistore projects, building on the concepts of file-based inheritance.
Let's start with the foundation of your development workflow. Alokai provides essential scripts that will help you develop, test, and deploy your stores efficiently. These scripts are available in your project root's package.json
and form the basis of your daily development tasks:
dev
: Your go-to command for development - starts all your stores in development mode with hot-reloadbuild
: Prepares your stores for production with optimized buildsstart
: Runs your production build locally to verify everything works as expectedtest:integration:pw
: Ensures your stores work correctly by running integration testsstore
: An alias for the./node_modules/.bin/alokai-cli store
. You can use it to run anyalokai-cli store
command.
:::info Scripts are shortcuts for alokai-cli
commands
All of these commands use the @alokai/cli
underneath. For instance, the dev
command is just a shortcut for ./node_modules/.bin/alokai-cli store dev --all --verbose
.
:::
:::warning Using Alokai CLI All store management operations must be performed through the Alokai CLI. Native Next.js/Nuxt commands will not work correctly with the multistore setup, as they don't handle the inheritance and configuration requirements of Alokai stores. :::
The most common way to start development is using the yarn scripts from the root level:
# Start development mode for all stores
yarn dev
# Start development for a specific store
yarn alokai store dev --store-id=my-store
# Alternatively, you may use: ./node_modules/.bin/alokai-cli store dev --store-id=my-store
The dev
command watches for changes in:
- The current store's files
- Parent stores in the inheritance chain
- Base applications (
apps/storefront-unified-nextjs
, etc.)
When a file changes, the CLI automatically:
- Detects which stores are affected by the change
- Moves the affected files to the
.out
directory, so the app's framework can hot-reload the changes
::alert{type="info"}
The applications will run on ports specified in the alokai.config.json
file. For example:
{
"stores": {
"default": {
"localPorts": {
"middleware": 4000,
"nextjs": 3000,
"nuxt": 3333
}
}
}
}
Each store can have its own port configuration to avoid conflicts when running multiple stores simultaneously. ::
Alokai uses Caddy as a reverse proxy to handle local domains. The Caddyfile is automatically generated based on the alokai.config.json
file and the localDomain
property for each store.
- Caddy server installed
- Local domains configured in your hosts file. For example:
- If you have a store with
localDomain
set todefault.local
, add127.0.0.1 default.local
to your hosts file
- If you have a store with
Start all stores with their local domains:
yarn alokai store dev --all --with-local-domains
:::tip HTTPS Caddy automatically generates self-signed SSL certificates for local domains. You can read more about it in the Caddy documentation. :::
To test the production build locally:
- Build all deployable stores:
yarn build
- Start the production server:
yarn start
Note that template stores are not built into the .out
directory, as they only serve as templates for their descendant stores.
Integration tests run against the composed stores, respecting the file inheritance chain:
yarn test:integration:pw
You can also run tests in Playwright's UI mode for better debugging experience:
yarn alokai store test --store-id=my-store --ui
:::warning
The --ui
flag only works when testing a single store. Make sure to specify the store using the --store-id
flag.
:::
For more information on integration tests, refer to the Integration Tests guide.
If you experience unexpected behavior with file inheritance or turbo cache. For example:
- You modify a component in your store, but the changes are not reflected in the browser
- The
.out
directory still contains old versions of your files after making changes
Here's how to fix it:
# Clear Turbo cache
rm -rf .turbo/cache
# Clear composed store outputs
rm -rf .out/*
# Rebuild all stores
yarn build
::alert{type="warning"}
The .out
directory contains the composed stores and is in .gitignore
. If you experience inheritance issues, try clearing this directory and rebuilding.
::
- Use Store-Specific Development
When working on a single store, use the
--store-id
flag to improve build times:
yarn alokai store dev --store-id=my-store
- Test Inheritance Chain When modifying shared code, test all affected stores:
# See which stores are affected by current changes
yarn alokai store changed
# Build and test affected stores
yarn alokai store build --store-id=affected-store-id-1,affected-store-id-2
:::tip In the Continuous Integration and Continuous Deployment pipelines, the affected stores are built and tested automatically. You can read more about it in the CD Pipeline guide. :::
- Debugging Inheritance
Use the
--verbose
flag to see detailed file resolution:
yarn alokai store build --store-id=my-store --verbose
You can also use the DEBUG=*
environment variable to get even more logs:
DEBUG=* yarn alokai store build --store-id=my-store
- Inspect Store Composition
Examine how stores are composed in the
.out
directory:
yarn alokai store build --store-id=my-store --compose-only
This will skip the build and only compose the store into the .out
directory.
::card{title="Next: Development - Writing an integration tests with Playwright" icon="tabler:number-3-small" }
#description Learn how to create and run integration tests using Playwright in your Alokai multistore project.
#cta :::docs-arrow-link{to="/guides/multistore/tooling-and-concepts/integration-tests"} Next ::: ::