Skip to content

[Feature]: Support run SWC transform via a standalone API #8998

@9aoy

Description

@9aoy

What problem does this feature solve?

Currently, to utilize the builtin:swc-loader transformation capability in rspack, a complete rspack bundling compilation is required.

If rspack provides a standalone transform API, it can be used directly to invoke rspack's builtin:swc-loader for some file transformations.

Potential scenarios:

  • Loading of some configuration files. When rsbuild loads the configuration file, it needs to transform the configuration file from typescript to javascript.
  • Rslib's bundleless scenario, currently requires a complete rspack compilation. However, it seems that only rspack's resolve and transform capabilities are needed.

What does the proposed API of configuration look like?

It may be an API on the rspack instance that reads rspack's configuration. Or a util method that calls rspack builtin:swc-loader alone.

import { rspack } from '@rspack/core';
import fs from 'node:fs'

const compiler = rspack({
  // ...
});
const code = await compiler.transform('./index.ts');

fs.writeFileSync('./dist/index.js', code);

or

import { swcTransform } from '@rspack/core';
import fs from 'node:fs'

const code = await swcTransform('./index.ts', swcLoaderOptions);

fs.writeFileSync('./dist/index.js', code);

Metadata

Metadata

Assignees

Labels

featNew feature or requestteamThe issue/pr is created by the member of Rspack.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions