Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"workspaces": [
"plugins/plugin-tools",
"plugins/vite-plugin",
"plugins/nextjs-plugin"
"plugins/nextjs-plugin",
"plugins/esbuild-plugin"
],
"scripts": {
"build": "npm run build --workspaces",
Expand Down
21 changes: 21 additions & 0 deletions plugins/esbuild-plugin/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 David Dal Busco

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
100 changes: 100 additions & 0 deletions plugins/esbuild-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
[![npm][npm-badge]][npm-badge-url]
[![license][npm-license]][npm-license-url]

[npm-badge]: https://img.shields.io/npm/v/@junobuild/esbuild-plugin
[npm-badge-url]: https://www.npmjs.com/package/@junobuild/esbuild-plugin
[npm-license]: https://img.shields.io/npm/l/@junobuild/esbuild-plugin
[npm-license-url]: https://github.com/junobuild/plugins/blob/main/LICENSE

# Juno Esbuild Plugin

An esbuild plugin for [Juno].

## Getting started

The plugin automatically loads your Satellite and Orbiter IDs.

With these values, you can instantiate Juno in your code without the need to manually define environment variables.

```javascript
await Promise.all([initSatellite(), initOrbiter()]);
```

## Environment variables

Those following environment variables are injected by this plugin:

| Environment variable | Value |
| ------------------------- | ------------------------------------------------------------------------ |
| VITE_SATELLITE_ID | Satellite ID from Juno config (per `mode`) |
| VITE_ORBITER_ID | `undefined` in development, Orbiter ID from Juno config. |
| VITE_INTERNET_IDENTITY_ID | `rdmx6-jaaaa-aaaaa-aaadq-cai` |
| VITE_ICP_LEDGER_ID | `ryjl3-tyaaa-aaaaa-aaaba-cai` |
| VITE_ICP_INDEX_ID | `qhbym-qaaaa-aaaaa-aaafq-cai` |
| VITE_NNS_GOVERNANCE_ID | `rrkah-fqaaa-aaaaa-aaaaq-cai` |
| VITE_CMC_ID | `rkp4c-7iaaa-aaaaa-aaaca-cai` |
| VITE_REGISTRY_ID | `rwlgt-iiaaa-aaaaa-aaaaa-cai` |
| VITE_CYCLES_LEDGER_ID | `um5iw-rqaaa-aaaaq-qaaba-cai` |
| VITE_CYCLES_INDEX_ID | `ul4oc-4iaaa-aaaaq-qaabq-cai` |
| VITE_SNS_WASM_ID | `qaa6y-5yaaa-aaaaa-aaafa-cai` |
| VITE_NNS_DAPP_ID | `qoctq-giaaa-aaaaa-aaaea-cai` |
| VITE_CONTAINER | Container URL (emulator or custom); `undefined` by default in production |

> `VITE_` is the default prefix used by Vite. It can be customized as described in Vite's [documentation](https://vitejs.dev/guide/env-and-mode).

## Installation

```bash
npm i @junobuild/esbuild-plugin -D
```

## Usage

```javascript
// vite.config.js
import juno from '@junobuild/esbuild-plugin';

export default defineConfig({
plugins: [juno()]
});
```

## Options

The plugin can be customized using the optional `juno` configuration object. This allows you to control how the Juno Docker container is used in your project, especially during local development or end-to-end (E2E) testing.

### `juno.container`

Use the container option to enable, disable, or fine-tune the use of [Juno Docker](https://github.com/junobuild/juno-docker).

You can provide:

- `false` — to disable the container entirely.
- `true` — to enable the container with default settings (only in development mode), which is also the default behavior.
- An object with the following fields:
- `url` (`string`, optional): A custom container URL, including the port. Example: http://127.0.0.1:8000
- `modes` (`string[]`, optional): An array of modes (e.g., ['development', 'test']) during which the container should be used.

By default, the container is mounted only in `development` mode.

```javascript
// vite.config.js
import juno from '@junobuild/esbuild-plugin';

export default defineConfig({
plugins: [
juno({
container: {
url: 'http://127.0.0.1:8000',
modes: ['development', 'test']
}
})
]
});
```

## License

MIT © [David Dal Busco](mailto:[email protected])

[juno]: https://juno.build
5 changes: 5 additions & 0 deletions plugins/esbuild-plugin/esbuild.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

import {build} from '../../scripts/esbuild.mjs';

build();
39 changes: 39 additions & 0 deletions plugins/esbuild-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@junobuild/esbuild-plugin",
"version": "0.0.1",
"description": "An esbuild plugin for Juno",
"author": "David Dal Busco (https://daviddalbusco.com)",
"license": "MIT",
"type": "module",
"main": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist",
"README.md",
"LICENSE"
],
"scripts": {
"rmdir": "node ../../scripts/rmdir.mjs",
"ts-declaration": "tsc --emitDeclarationOnly --outDir dist",
"build": "tsc --noEmit && npm run rmdir && mkdir -p dist && node esbuild.mjs && npm run ts-declaration"
},
"repository": {
"type": "git",
"url": "git+https://github.com/junobuild/plugins.git",
"directory": "plugins/esbuild-plugin"
},
"bugs": {
"url": "https://github.com/junobuild/plugins"
},
"keywords": [
"env",
"environment",
"variables",
"esbuild",
"esbuild-plugin"
],
"homepage": "https://juno.build",
"dependencies": {
"@junobuild/plugin-tools": "*"
}
}
98 changes: 98 additions & 0 deletions plugins/esbuild-plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import {
type ConfigArgs,
type JunoParams,
JunoPluginError,
initConfig
} from '@junobuild/plugin-tools';
import type {Plugin, PluginBuild} from 'esbuild';

export interface JunoOptions {
emulator?: JunoParams;
envPrefix?: string;
}

// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
export default function juno(options?: JunoOptions): Plugin {
return {
name: 'esbuild-plugin-juno',
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
setup(build: PluginBuild) {
const mode = process.env.NODE_ENV;

const defineConfig = async () => {
const {emulator, envPrefix} = options ?? {};

const args: ConfigArgs = {params: emulator, mode: mode ?? 'production'};

try {
const {satelliteId, orbiterId, icpIds, container, authClientIds} = await initConfig(args);

const prefix = `process.env.${envPrefix ?? ''}`;

const defines = {
[`${prefix}SATELLITE_ID`]: satelliteId,
...(orbiterId !== undefined && {
[`${prefix}ORBITER_ID`]: orbiterId
}),
...(icpIds?.internetIdentityId !== undefined && {
[`${prefix}INTERNET_IDENTITY_ID`]: icpIds.internetIdentityId
}),
...(icpIds?.icpLedgerId !== undefined && {
[`${prefix}ICP_LEDGER_ID`]: icpIds.icpLedgerId
}),
...(icpIds?.icpIndexId !== undefined && {
[`${prefix}ICP_INDEX_ID`]: icpIds.icpIndexId
}),
...(icpIds?.nnsGovernanceId !== undefined && {
[`${prefix}NNS_GOVERNANCE_ID`]: icpIds.nnsGovernanceId
}),
...(icpIds?.cmcId !== undefined && {
[`${prefix}CMC_ID`]: icpIds.cmcId
}),
...(icpIds?.registryId !== undefined && {
[`${prefix}REGISTRY_ID`]: icpIds.registryId
}),
...(icpIds?.cyclesLedgerId !== undefined && {
[`${prefix}CYCLES_LEDGER_ID`]: icpIds.cyclesLedgerId
}),
...(icpIds?.cyclesIndexId !== undefined && {
[`${prefix}CYCLES_INDEX_ID`]: icpIds.cyclesIndexId
}),
...(icpIds?.snsWasmId !== undefined && {
[`${prefix}SNS_WASM_ID`]: icpIds.snsWasmId
}),
...(icpIds?.nnsDappId !== undefined && {
[`${prefix}NNS_DAPP_ID`]: icpIds.nnsDappId
}),
...(container !== undefined && {
[`${prefix}CONTAINER`]: container
}),
...(authClientIds?.google !== undefined && {
[`${prefix}GOOGLE_CLIENT_ID`]: authClientIds.google
})
};

build.initialOptions.define = {
...build.initialOptions.define,
...Object.entries(defines).reduce(
(acc, [key, value]) => ({
...acc,
[key]: JSON.stringify(value)
}),
{}
)
};
} catch (err: unknown) {
if (err instanceof JunoPluginError && mode !== 'production') {
console.warn(err.message);
return;
}

throw err;
}
};

build.onStart(defineConfig);
}
};
}
Loading