### Install @devvit/start Source: https://github.com/reddit/devvit/blob/main/packages/start/README.md Install the @devvit/start package as a dev dependency. ```sh npm install -D @devvit/start ``` -------------------------------- ### Run development server Source: https://github.com/reddit/devvit/blob/main/packages/start/README.md Start the development server. The plugin automatically builds both client and server in watch mode, triggering a rebuild on changes. ```sh npm run dev ``` -------------------------------- ### Script tag injection example Source: https://github.com/reddit/devvit/blob/main/packages/web-view-scripts/README.md The script tag that is injected into HTML files at web view asset upload time. It loads the devvit.v1.min.js script from the CDN with a client version parameter. ```html ``` -------------------------------- ### One-time preparation commands Source: https://github.com/reddit/devvit/blob/main/packages/cli/README.md One-time preparation steps to set up the local development environment for the CLI. Run these commands in order from the repo root to make the 'mydevvit' command available in your console. ```bash yarn && yarn build ``` ```bash cd packages/cli ``` ```bash yarn install:dev ``` ```bash source ~/.zshrc ``` -------------------------------- ### Run production build Source: https://github.com/reddit/devvit/blob/main/packages/start/README.md Build optimized client and server bundles for production. ```sh npm run build ``` -------------------------------- ### Run mydevvit with production backend Source: https://github.com/reddit/devvit/blob/main/packages/cli/README.md Run the local 'mydevvit' CLI against the production Dev Portal API. Set the MY_PORTAL environment variable to 0 to use the production backend. ```bash MY_PORTAL=0 mydevvit [command] # executes [command] using your local devvit cli, but production backend ``` -------------------------------- ### Configure devvit() options Source: https://github.com/reddit/devvit/blob/main/packages/start/README.md Configure the devvit() plugin with optional settings. All options are optional; the plugin works out of the box with sensible defaults and merges your overrides into each environment's Vite config. ```ts devvit({ logLevel: 'warn', // Vite log level: 'info' | 'warn' | 'error' | 'silent' (default: 'warn') client: {}, // Vite EnvironmentOptions (merged into the client environment) server: {}, // Vite EnvironmentOptions (merged into the server environment) }); ``` -------------------------------- ### Create hard link for overridden content Source: https://github.com/reddit/devvit/blob/main/packages/web-view-scripts/README.md Command to create a hard link for the overridden content file. Symlinks do not work for this purpose. ```bash ln ../../../../work/reddit/src/devvit/packages/web-view-scripts/dist/scripts/devvit.v1.min.js devvit.v1.min.js\? ``` -------------------------------- ### Bundle web-view-scripts Source: https://github.com/reddit/devvit/blob/main/packages/web-view-scripts/README.md Command to bundle the web-view-scripts source into the dist/scripts directory. This is used when overriding Chrome content. ```bash yarn workspace @devvit/web-view-scripts bundle --outfile=dist/scripts/devvit.v1.min.js src/devvit.v1.ts ``` -------------------------------- ### Import web-view-scripts in client entrypoint Source: https://github.com/reddit/devvit/blob/main/packages/web-view-scripts/README.md Import the web-view-scripts package before any other code executes to disable script injection. This is used for local development and playtesting. ```typescript // src/client/index.ts import '@devvit/web-view-scripts/scripts/devvit.v1.min.js'; import { context } from '@devvit/web/client'; ``` -------------------------------- ### Enable Corepack Source: https://github.com/reddit/devvit/blob/main/README.md Command to enable corepack, which is pre-installed on Node v24, to manage yarn. ```sh corepack enable ``` -------------------------------- ### Configure devvit() in vite.config.ts Source: https://github.com/reddit/devvit/blob/main/packages/start/README.md Add the devvit() plugin to your Vite configuration. Place it last in the plugins array to ensure it handles both client and server builds correctly. ```ts import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import tailwind from '@tailwindcss/vite'; import { devvit } from '@devvit/start/vite'; export default defineConfig({ plugins: [react(), tailwind(), devvit()], }); ``` -------------------------------- ### Rebuild CLI after code changes Source: https://github.com/reddit/devvit/blob/main/packages/cli/README.md After code changes, run this command in packages/cli to rebuild the CLI. For changes outside packages/cli, run 'yarn && yarn build' in the repo root. ```bash yarn build ``` -------------------------------- ### Playtest without script injection Source: https://github.com/reddit/devvit/blob/main/packages/web-view-scripts/README.md Commands to build the devvit package and run a playtest with script injection disabled. The environment variable DEVVIT_SKIP_WEB_VIEW_SCRIPT_INJECTION=1 is required. ```bash $ cd devvit $ yarn build $ cd ~/some-test-app $ npm link --save ~/work/reddit/src/devvit/packages/{devvit,public-api,web,web-view-scripts} $ DEVVIT_SKIP_WEB_VIEW_SCRIPT_INJECTION=1 npx devvit playtest r/some-test-sub ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.