Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
9aoy opened this issue Jan 13, 2025 · 1 comment
Open

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

9aoy opened this issue Jan 13, 2025 · 1 comment
Assignees
Labels
feat New feature or request team The issue/pr is created by the member of Rspack.

Comments

@9aoy
Copy link
Contributor

9aoy commented Jan 13, 2025

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);
@9aoy 9aoy added feat New feature or request pending triage The issue/PR is currently untouched. labels Jan 13, 2025
@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label Jan 13, 2025
@chenjiahan chenjiahan removed the pending triage The issue/PR is currently untouched. label Jan 13, 2025
@9aoy 9aoy changed the title [Feature]: Support run builtin:swc-loader via a standalone API [Feature]: Support run swc transform via a standalone API Jan 13, 2025
@chenjiahan chenjiahan changed the title [Feature]: Support run swc transform via a standalone API [Feature]: Support run SWC transform via a standalone API Jan 13, 2025
@chenjiahan
Copy link
Member

We can align the API interface with @swc/core.

For example:

import { rspack } from '@rspack/core';

rspack.util.swc.transform("source code", {
  // some options
});

rspack.util.swc.parse("source code", {
  // some options
});

rspack.util.swc.minify("source code", {
  // some options
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New feature or request team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

No branches or pull requests

3 participants