Skip to content
Open
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
40 changes: 40 additions & 0 deletions .containerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Container Ignore Datei (analog zu .dockerignore)
# Verhindert, dass unnötige Dateien in den Build-Kontext kopiert werden

# Git
.git
.github
.gitignore

# Node
node_modules
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Build Output
main.js
styles.css
*.map

# OS
.DS_Store
Thumbs.db

# IDE
.vscode
.idea
*.swp
*.swo

# Dokumentation
README.md
LICENSE

# Container files (nicht in sich selbst kopieren)
Containerfile
Dockerfile
compose.yaml
docker-compose.yml
.containerignore
.dockerignore
37 changes: 37 additions & 0 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Podman/Docker Containerfile für tldraw-in-obsidian Entwicklung
# Verwendung: podman build -t tldraw-dev -f Containerfile .
# podman run -it --rm -v .:/app:Z -p 3000:3000 tldraw-dev

FROM node:24-alpine

# Labels für Dokumentation
LABEL maintainer="tldraw-in-obsidian"
LABEL description="Development environment for tldraw-in-obsidian Obsidian plugin"

# Arbeitsverzeichnis setzen
WORKDIR /app

# Abhängigkeiten für native Module (falls benötigt)
RUN apk add --no-cache git python3 make g++

# npm konfigurieren für schnellere Installationen
RUN npm config set progress=false && \
npm config set loglevel=warn

# package.json und package-lock.json kopieren (für besseres Caching)
COPY package*.json ./

# patches Ordner kopieren (für postinstall patch-package)
COPY patches ./patches/

# Abhängigkeiten installieren
RUN npm ci

# Rest des Quellcodes kopieren
COPY . .

# Port für mögliche Entwicklungsserver
EXPOSE 3000

# Standard-Befehl: dev-Server starten
CMD ["npm", "run", "dev"]
27 changes: 27 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Podman Compose / Docker Compose für tldraw-in-obsidian Entwicklung
# Verwendung: podman-compose up
# ODER: podman compose up

services:
dev:
build:
context: .
dockerfile: Containerfile
container_name: tldraw-dev
volumes:
# Source code mounten für Hot-Reload
- .:/app:Z
# node_modules im Container belassen (Performance)
- node_modules:/app/node_modules
ports:
- "3000:3000"
# Interaktives Terminal für Entwicklung
stdin_open: true
tty: true
# Automatisch neu starten falls Container abstürzt
restart: unless-stopped
# Befehl: npm run dev
command: npm run dev

volumes:
node_modules:
20 changes: 16 additions & 4 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import esbuild from "esbuild";
import process from "process";
import builtins from "builtin-modules";
import { readFileSync } from "fs";
// import svgr from "esbuild-plugin-svgr";

const banner = `/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
Expand All @@ -19,6 +18,20 @@ const TLDRAW_VERSION = (() => {

console.log({ TLDRAW_VERSION })

// Plugin to load pdf.worker.min.mjs as text for blob URL creation
const pdfWorkerPlugin = {
name: 'pdf-worker-text',
setup(build) {
build.onLoad({ filter: /pdf\.worker\.min\.mjs$/ }, async (args) => {
const contents = readFileSync(args.path, 'utf8');
return {
contents: `export default ${JSON.stringify(contents)};`,
loader: 'js',
};
});
},
};

Comment on lines +21 to +34
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe refactor into extensions/pdf/esbuild-plugin.mjs?

export default {
	name: 'pdf-worker-blob',
	setup(build) {
		build.onLoad({ filter: /pdf\.worker\.min\.mjs$/ }, async (args) => {
			const contents = readFileSync(args.path, 'utf8');
			return {
				contents: 'export default ${JSON.stringify(contents)};`,
				loader: 'js',
			};
		});
	},
}

Also, I see that the worker code is exported as a string in contents, then made into a blob later on in different places. Perhaps it could be done directly like this?

const pdfWorkerCode = ${JSON.stringify(contents)}
const pdfWorkerBlob = new Blob([pdfWorkerCode], { type: 'application/javascript' })
export default pdfWorkerBlob

This avoid creating multiple blob objects, reusing the one created in this module.

const context = await esbuild.context({
banner: {
js: banner,
Expand Down Expand Up @@ -46,7 +59,6 @@ const context = await esbuild.context({
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
// outfile: "main.js",
loader: {
".js": "jsx",
".woff2": "dataurl",
Expand All @@ -60,8 +72,8 @@ const context = await esbuild.context({
"TLDRAW_COMPONENT_LOGGING": `${!prod}`,
"MARKDOWN_POST_PROCESSING_LOGGING": `${!prod}`,
"TLDRAW_VERSION": `"${TLDRAW_VERSION}"`,
}
// plugins: [svgr({ typescript: true })],
},
plugins: [pdfWorkerPlugin],
});

if (prod) {
Expand Down
Loading