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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ yarn-debug.log*
yarn-error.log*
.DS_Store
webroot
dist
dist
bin
24 changes: 24 additions & 0 deletions build-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

set -euo pipefail

SERVER_JS_OUTPUT=bin/index.cjs
OUTPUT_BUNDLE=dist/main.bundle.json

# This should spit out a bundle using the classic bundler approach
npx devvit bundle actor main

# Build the server bundle using esbuild
./esbuild.mjs

# Create a temporary directory
TEMP_DIR=$(mktemp -d)
trap 'rm -rf "$TEMP_DIR"' EXIT

jq --rawfile code "$SERVER_JS_OUTPUT" \
--rawfile sourcemap "${SERVER_JS_OUTPUT}.map" \
'.standaloneServerCode = $code | .standaloneServerSourceMap = $sourcemap | .actor.name = "main" | .actor.version = "0.0.0"' \
${OUTPUT_BUNDLE} > bin/bundle.combined.json

echo "Bundle created at bin/bundle.combined.json"

99 changes: 99 additions & 0 deletions bundle.server.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"actor": {
"name": "main",
"owner": "snoo",
"version": "0.0.0"
},
"code": "",
"sourceMap": "",
"devvitJson": { "name": "abc", "server": {} },
"hostname": "main.local",
"provides": [
{
"fullName": "devvit.actor.hello.Hello",
"methods": [
{
"fullName": "/devvit.actor.hello.Hello/Ping",
"name": "Ping",
"requestType": "devvit.actor.hello.PingMessage",
"responseType": "devvit.actor.hello.PingMessage"
}
],
"name": "Hello"
}
],
"uses": [
{
"actor": {
"name": "default",
"owner": "devvit",
"version": "1.0.0"
},
"hostname": "wrappertypes.plugins.local",
"provides": [
{
"fullName": "devvit.actor.test.WrapperTypes",
"methods": [
{
"fullName": "/devvit.actor.test.WrapperTypes/StringRequest",
"name": "StringRequest",
"requestType": "google.protobuf.StringValue",
"responseType": "google.protobuf.StringValue"
},
{
"fullName": "/devvit.actor.test.WrapperTypes/BoolRequest",
"name": "BoolRequest",
"requestType": "google.protobuf.BoolValue",
"responseType": "google.protobuf.BoolValue"
},
{
"fullName": "/devvit.actor.test.WrapperTypes/Int32Request",
"name": "Int32Request",
"requestType": "google.protobuf.Int32Value",
"responseType": "google.protobuf.Int32Value"
},
{
"fullName": "/devvit.actor.test.WrapperTypes/UInt32Request",
"name": "UInt32Request",
"requestType": "google.protobuf.UInt32Value",
"responseType": "google.protobuf.UInt32Value"
},
{
"fullName": "/devvit.actor.test.WrapperTypes/Int64Request",
"name": "Int64Request",
"requestType": "google.protobuf.Int64Value",
"responseType": "google.protobuf.Int64Value"
},
{
"fullName": "/devvit.actor.test.WrapperTypes/UInt64Request",
"name": "UInt64Request",
"requestType": "google.protobuf.UInt64Value",
"responseType": "google.protobuf.UInt64Value"
},
{
"fullName": "/devvit.actor.test.WrapperTypes/FloatRequest",
"name": "FloatRequest",
"requestType": "google.protobuf.FloatValue",
"responseType": "google.protobuf.FloatValue"
},
{
"fullName": "/devvit.actor.test.WrapperTypes/DoubleRequest",
"name": "DoubleRequest",
"requestType": "google.protobuf.DoubleValue",
"responseType": "google.protobuf.DoubleValue"
}
],
"name": "WrapperTypes"
}
]
}
],
"buildInfo": {
"created": "2025-03-17T17:25:08.874Z",
"dependencies": {
"node": "22.6.0",
"@devvit/protos": "0.11.11-dev",
"@devvit/public-api": "0.11.11-dev"
}
}
}
4 changes: 2 additions & 2 deletions devvit.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name: YOUR_APP_NAME
version: 0.0.0.0
name: ss-webbit-tests
version: 0.0.1.5
53 changes: 53 additions & 0 deletions esbuild.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env node

/* eslint-disable no-console */
import * as esbuild from "esbuild";
import { nodeExternalsPlugin } from "esbuild-node-externals";

import path from "path";

/**
* @param {boolean} watch
* @returns {Promise<esbuild.BuildResult<esbuild.BuildOptions>> | undefined}
*/
async function build(watch) {
/** @type {esbuild.BuildOptions} */
const opts = {
entryPoints: ["src/server/index.ts"],
outdir: "bin",
format: "cjs",
entryNames: "[name]",
outExtension: { ".js": ".cjs" },
plugins: [
nodeExternalsPlugin({
packagePath: path.resolve("./package.json"),
allowList: [
'express',
/^@devvit\//
],
}),
],
sourcemap: true,
bundle: true,
platform: "node",
};

if (!watch) {
await esbuild.build(opts);
console.log(
`[esbuild/server] Build finished. Output is in ${path.resolve("bin")}`
);
return;
}

console.log("[esbuild/server] Starting watch mode...");
const ctx = await esbuild.context(opts);
await ctx.watch();
}

async function main() {
const enableWatchMode = process.argv.includes("--watch");
await build(enableWatchMode);
}

await main();
17 changes: 11 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
{
"private": true,
"name": "devvit-hello-world-experimental",
"name": "ss-webbit-testing",
"version": "0.0.0",
"license": "BSD-3-Clause",
"type": "module",
"scripts": {
"build:client": "cd src/client && vite build",
"build:server": "./build-server.sh",
"deploy": "npm run build:client && devvit upload",
"dev": "concurrently -p \"[{name}]\" -n \"VITE,DEVVIT,GAME\" -c \"blue,green,magenta\" \"npm run dev:vite\" \"npm run dev:devvit\" \"npm run dev:client\" --restart-tries 2",
"dev:client": "cd src/client && vite build --watch",
"dev:devvit": "devvit playtest YOUR_SUBREDDIT_NAME",
"dev:devvit": "MY_PORTAL=0 mydevvit playtest SnooSnekTest",
"dev:vite": "cd src/client && vite --port 7474",
"login": "devvit login",
"type-check": "tsc --build"
},
"dependencies": {
"@devvit/client": "next",
"@devvit/public-api": "next",
"@devvit/server": "next",
"devvit": "next",
"@devvit/client": "../../devvit/packages/client",
"@devvit/public-api": "../../devvit/packages/public-api",
"@devvit/server": "../../devvit/packages/server",
"@devvit/redis": "../../devvit/packages/redis",
"@devvit/reddit": "../../devvit/packages/reddit",
"devvit": "../../devvit/packages/devvit",
"express": "5.1.0"
},
"devDependencies": {
"@types/express": "5.0.1",
"concurrently": "9.1.2",
"esbuild": "0.23.0",
"esbuild-node-externals": "1.15.0",
"typescript": "5.8.2",
"vite": "6.2.4"
}
Expand Down
39 changes: 28 additions & 11 deletions src/devvit/main.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
import { Devvit } from "@devvit/public-api";

// Side effect import to bundle the server. The /index is required for server splitting.
import "../server/index";
import { defineConfig } from "@devvit/server";
// import "../server/index";
// import { defineConfig } from "@devvit/server";

defineConfig({
// defineConfig({
// name: "Hello World",
// description: "Hello World",
// entry: "index.html",
// height: "tall",
// inline: true,
// menu: {
// enable: true,
// label: "[Webbit] New Hello World Post",
// postTitle: "Hello World",
// },
// });

Devvit.addCustomPostType({
name: "Hello World",
description: "Hello World",
entry: "index.html",
height: "tall",
inline: true,
menu: {
enable: true,
label: "New Hello World Post",
postTitle: "Hello World",
description: "A simple hello world post type",
render: (context) => {
if (context.postId === "t3_THROW_ERROR") {
throw new Error("Test error.");
}

console.log("Post ID!!:", context.postId);
console.log("App Name!!:", context.appName);
console.log("User ID!!:", context.userId);
console.log("Subreddit ID!!:", context.subredditId);
console.log("App version!!:", context.appVersion);
return <blocks></blocks>;
},
});

Expand Down
Loading