Skip to content
Closed
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
6 changes: 6 additions & 0 deletions .changeset/tangy-candles-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@workflow/builders": patch
"@workflow/next": patch
---

Support esbuild loaders
4 changes: 4 additions & 0 deletions packages/builders/src/base-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export abstract class BaseBuilder {
logLevel: 'silent',
// External packages that should not be bundled during discovery
external: this.config.externalPackages || [],
loader: this.config.esbuildLoaders,
Comment thread
gdaybrice marked this conversation as resolved.
});
} catch (_) {}

Expand Down Expand Up @@ -364,6 +365,7 @@ export abstract class BaseBuilder {
'.mjs',
'.cjs',
],
loader: this.config.esbuildLoaders,
// Inline source maps for better stack traces in step execution.
// Steps execute in Node.js context and inline sourcemaps ensure we get
// meaningful stack traces with proper file names and line numbers when errors
Expand Down Expand Up @@ -537,6 +539,7 @@ export abstract class BaseBuilder {
'.mjs',
'.cjs',
],
loader: this.config.esbuildLoaders,
plugins: [
createSwcPlugin({
mode: 'workflow',
Expand Down Expand Up @@ -718,6 +721,7 @@ export const POST = workflowEntrypoint(workflowCode);`;
'.mjs',
'.cjs',
],
loader: this.config.esbuildLoaders,
plugins: [createSwcPlugin({ mode: 'client' })],
});

Expand Down
5 changes: 5 additions & 0 deletions packages/builders/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Loader } from 'esbuild';

export const validBuildTargets = [
'standalone',
'vercel-build-output-api',
Expand Down Expand Up @@ -27,6 +29,9 @@ interface BaseWorkflowConfig {

// Optional prefix for debug files (e.g., "_" for Astro to ignore them)
debugFilePrefix?: string;

// Custom esbuild loaders for non-standard file extensions (e.g., { '.md': 'text' })
esbuildLoaders?: Record<string, Loader>;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions packages/next/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Loader } from 'esbuild';
import type { NextConfig } from 'next';
import semver from 'semver';
import { getNextBuilder } from './builder.js';
Expand All @@ -11,13 +12,16 @@ export function withWorkflow(
) => Promise<NextConfig>),
{
workflows,
esbuildLoaders,
}: {
workflows?: {
local?: {
port?: number;
dataDir?: string;
};
};
/** Custom esbuild loaders for non-standard file extensions (e.g., { '.md': 'text' }) */
esbuildLoaders?: Record<string, Loader>;
} = {}
) {
if (!process.env.VERCEL_DEPLOYMENT_ID) {
Expand Down Expand Up @@ -137,6 +141,7 @@ export function withWorkflow(
'client-only',
...(nextConfig.serverExternalPackages || []),
],
esbuildLoaders,
});

await workflowBuilder.build();
Expand Down
79 changes: 79 additions & 0 deletions pnpm-lock.yaml

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

4 changes: 4 additions & 0 deletions workbench/nextjs-turbopack/md.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '*.md' {
const content: string;
export default content;
}
14 changes: 13 additions & 1 deletion workbench/nextjs-turbopack/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@ import { withWorkflow } from 'workflow/next';
const nextConfig: NextConfig = {
/* config options here */
serverExternalPackages: ['@node-rs/xxhash'],
turbopack: {
rules: {
'*.md': {
loaders: ['raw-loader'],
as: '*.js',
},
},
},
};

// export default nextConfig;
export default withWorkflow(nextConfig);
export default withWorkflow(nextConfig, {
esbuildLoaders: {
'.md': 'text',
},
});
1 change: 1 addition & 0 deletions workbench/nextjs-turbopack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@types/react-dom": "^19",
"@vercel/blob": "2.0.0",
"@workflow/world-postgres": "workspace:*",
"raw-loader": "4.0.2",
"tailwindcss": "^4",
"typescript": "catalog:"
}
Expand Down
7 changes: 7 additions & 0 deletions workbench/nextjs-turbopack/workflows/11_custom_loader.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Test Prompt

This is a test markdown file to verify the esbuildLoaders feature works.

## Instructions
- Step 1: Do something
- Step 2: Do something else
23 changes: 23 additions & 0 deletions workbench/nextjs-turbopack/workflows/11_custom_loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Test for custom esbuild loaders feature.
* Verifies that non-standard file extensions (like .md) can be imported
* when configured via esbuildLoaders in withWorkflow options.
*/
import PROMPT from '@/workflows/11_custom_loader.md';

async function logPrompt(): Promise<string> {
'use step';

console.log('Loaded prompt:', PROMPT.slice(0, 50));

return PROMPT;
}

export async function customLoader() {
'use workflow';

const prompt = await logPrompt();
console.log('Custom loader test completed. Prompt length:', prompt.length);

return { success: true, promptLength: prompt.length };
}