Skip to content

Commit 8ba8cf2

Browse files
feat: review local-first development (#369)
* feat: review local-first development Signed-off-by: David Dal Busco <david.dalbusco@outlook.com> * feat: more local development Signed-off-by: David Dal Busco <david.dalbusco@outlook.com> --------- Signed-off-by: David Dal Busco <david.dalbusco@outlook.com>
1 parent 8c9690b commit 8ba8cf2

3 files changed

Lines changed: 38 additions & 82 deletions

File tree

docs/build/functions/lifecycle.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Once your project is scaffolded, proceed to define Rust functions and annotate t
1818

1919
### Local Development
2020

21-
For local development and testing, a sandbox environment is essential. With Docker installed and using the CLI, you can establish this environment by running `juno dev start`. Alternatively, manual setup instructions are available in the [documentation](../../guides/local-development.md) for a more customized approach.
21+
For local development and testing, a sandbox environment is essential. With Docker installed and using the CLI, you can establish this environment by running `juno dev start`. Alternatively, manual setup instructions are available in the [documentation](../../guides/local-development.mdx) for a more customized approach.
2222

2323
:::info
2424

Lines changed: 35 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ sidebar_position: 11
77

88
# Local Development
99

10-
When you get started with Juno, you are using your smart contract deployed on the blockchain in production. If you are interested in developing or testing your apps in continuous integration workflows, this guide will show you how you can run a Satellite in a Docker sandbox.
10+
The tooling is designed with local-first development in mind. Whether you're using the official [plugins](../reference/plugins.md) (Next.js, Vite) or creating a new project with `npm create juno@latest`, local development is the default experience.
11+
12+
When running `npm run dev` (or `start`), your app connects to a locally simulated Satellite via the provided emulator — so you can build and test your backend logic without deploying to the live network.
13+
14+
For continuous integration workflows or advanced setups, this guide shows how to run a Docker-based sandbox that closely mirrors the production environment.
1115

1216
---
1317

@@ -25,61 +29,29 @@ For MacBooks with M processors, it is important to use Docker Desktop version 4.
2529

2630
## Getting Started
2731

28-
There are two ways to start a local developer environment:
29-
30-
### Automated
32+
The easiest way to run the local developer environment is through the CLI.
3133

32-
If you've installed Juno's CLI on your machine, you can start a local container by simply running the `juno dev start` command in your terminal.
34+
If you haven’t installed it yet, run:
3335

34-
The first time you execute this command, it will prompt you to automatically populate the required configuration.
36+
import Cli from "./components/cli.mdx";
3537

36-
To start the container, run this command whenever needed. Use `juno dev stop` to halt the container.
38+
<Cli />
3739

38-
### Manually
40+
Then, in your project folder, start the local emulator with:
3941

40-
In a folder, create a `docker-compose.yml` file.
41-
42-
```yml title="docker-compose.yml"
43-
services:
44-
juno-satellite:
45-
image: junobuild/satellite:latest
46-
ports:
47-
- 5987:5987
48-
- 5999:5999
49-
volumes:
50-
- my_dapp:/juno/.juno
51-
- ./juno.dev.config.json:/juno/juno.dev.config.json
52-
- ./target/deploy:/juno/target/deploy/
53-
54-
volumes:
55-
my_dapp:
42+
```bash
43+
juno dev start
5644
```
5745

58-
In addition, create a file named `juno.dev.config.json` next to your Docker Compose file and populate it with the required fields.
46+
This will launch a local Satellite along with a local Internet Identity, allowing you to develop and test without deploying anything live.
5947

60-
```json title="juno.dev.config.json"
61-
{
62-
"satellite": {
63-
"collections": {}
64-
}
65-
}
66-
```
48+
We recommend running this in a dedicated terminal window or tab, while your frontend project (e.g. using Vite or Next.js) runs separately using npm run dev or similar.
6749

68-
Once the configuration is set, start the container using the following Docker command:
50+
To stop the emulator, run:
6951

52+
```bash
53+
juno dev stop
7054
```
71-
docker compose up
72-
```
73-
74-
That's all it takes to run the local environment. At this point, you should have a container that exposes a Satellite and an Internet Identity for local development or end-to-end testing purposes.
75-
76-
:::note
77-
78-
You can run or compose the Juno Docker image from your terminal. This guide explains the latter.
79-
80-
It's worth noting that you can run multiple containers simultaneously, as long as they operate on different ports. Additionally, you can apply various configurations for different projects.
81-
82-
:::
8355

8456
---
8557

@@ -247,39 +219,35 @@ volumes:
247219

248220
## Usage
249221

250-
When integrating your application with the container during Juno initialization, you have two primary options. The first is to set a specific parameter to `true`, which applies the default container configuration. The second option is to provide a custom `string` as the URL of the container, which is especially beneficial if you're using a custom port.
251-
252-
### Plugins
222+
During local development, your app connects to the local emulator (container) by default — no extra configuration needed.
253223

254-
If you are utilizing the [Vite](../reference/plugins.md#vite-plugin) or [NextJS](../reference/plugins.md#nextjs-plugin), you can configure the container directly within the plugin settings:
224+
This is handled automatically when using the [plugins](../reference/plugins.md), or when starting from a template.
255225

256-
```javascript title="vite.config.js"
257-
import juno from "@junobuild/vite-plugin";
258-
259-
export default defineConfig({
260-
plugins: [
261-
juno({
262-
container: true
263-
})
264-
]
265-
});
266-
```
267-
268-
The plugin will automatically load the necessary environment variables for the container configuration so that your app uses it when you develop.
226+
If needed, you can opt out of the container behavior by explicitly setting `container: false`.
269227

270228
### Manual Initialization
271229

272-
If you are not using the plugins, you should set the satellite ID to the static ID used in the container, which is `jx5yt-yyaaa-aaaal-abzbq-cai`. The initialization would look like this:
230+
If you're not using a plugin and are initializing Juno manually, here's how to configure it to use the local container:
273231

274-
```typescript
232+
```javascript
275233
import { initSatellite } from "@junobuild/core";
276234
235+
const container = import.meta.env.DEV === true;
236+
277237
await initSatellite({
278-
// TODO: replace DEV flag according your need and the production satellite ID as well
279-
satelliteId: DEV
238+
satelliteId: container
280239
? "jx5yt-yyaaa-aaaal-abzbq-cai"
281240
: "aaaaa-bbbbb-ccccc-ddddd-cai",
282-
container: true
241+
container
242+
});
243+
```
244+
245+
The SDK will automatically detect the container in local development. If you want to disable that behavior and connect directly to a remote canister (e.g. in CI or production testing), you can do:
246+
247+
```javascript
248+
await initSatellite({
249+
satelliteId: "aaaaa-bbbbb-ccccc-ddddd-cai",
250+
container: false
283251
});
284252
```
285253

docs/intro.mdx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,13 @@ import { Bash } from "./components/bash.mdx";
3737

3838
...and follow the prompts.
3939

40-
:::note
41-
42-
Our CLI tool is compatible with Mac, Linux, and Windows and requires [NodeJS](https://nodejs.org/en) to be installed. It also supports Yarn and pnpm.
43-
44-
:::
45-
4640
---
4741

4842
## Local development
4943

50-
Want to develop locally before going live? Or just want to test out Juno in a non-production environment?
51-
52-
Use our [local development emulator](./guides/local-development.md) to build and test your projects in an environment that closely mirrors production, without needing to deploy live.
53-
54-
:::tip
55-
56-
The emulator comes with all starter templates. Just run `npm create juno@latest` to begin.
44+
Juno's tooling is designed for local-first development. Whether you're using the Next.js or Vite [plugins](reference/plugins.md), or creating a new app with `npm create juno@latest`, your project runs locally by default.
5745

58-
:::
46+
With the provided [emulator](./guides/local-development.md), you can build and test your projects in an environment that closely mirrors production, without the need to deploy live until you're ready.
5947

6048
---
6149

0 commit comments

Comments
 (0)