Skip to content
Closed
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
9 changes: 8 additions & 1 deletion src/generators/web/utils/bundle.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { join } from 'node:path';

import virtual from '@rollup/plugin-virtual';
import { build } from 'rolldown';

import cssLoader from './css.mjs';
import getStaticData from './data.mjs';
import getConfig from '../../../utils/configuration/index.mjs';
import { lazy } from '../../../utils/misc.mjs';

// Resolve node_modules relative to this package (doc-kit), not cwd.
// This ensures modules are found when running from external directories.
Expand All @@ -14,6 +14,11 @@ const DOC_KIT_NODE_MODULES = join(
'../../../../node_modules'
);

// TODO(@avivkeller): Until we can use Rolldown's bindings in node-core,
// we have to dynamically import it, as to not have it imported in core
// at all.
const rolldown = lazy(() => import('rolldown'));

/**
* Asynchronously bundles JavaScript source code (and its CSS imports),
* targeting either browser (client) or server (Node.js) environments.
Expand All @@ -25,6 +30,8 @@ const DOC_KIT_NODE_MODULES = join(
export default async function bundleCode(codeMap, { server = false } = {}) {
const config = getConfig('web');

const { build } = await rolldown();

const result = await build({
// Entry points: array of virtual module names that the virtual plugin provides
input: Array.from(codeMap.keys()),
Expand Down
Loading