Skip to content

[FR] Allow opting out of Babel transpilation for prebuilt/vendor JavaScript modules #55

Description

@Artechyro

Description

Codescript Toolkit currently runs imported modules through Babel before executing them. This works well for TypeScript files and source modules that need import/export transformation, but it introduces significant overhead when importing large prebuilt JavaScript bundles that are already executable as-is.

I created a sample vault to reproduce this with a ~500 KB bundled JavaScript file (Eruda). Importing the file through the normal loader takes several seconds, and Babel emits warnings such as:

[BABEL] Note: The code generator has deoptimised the styling of ... as it exceeds the max of 500KB.

For comparison, loading the same file directly as a CommonJS module (without Babel processing) reduces load time from roughly 5 seconds to well under 200 ms on my machine.

I would like a way to explicitly mark certain modules as already-transpiled so that Codescript Toolkit can skip Babel processing for those files.

Use case

A user wants to include large third-party libraries such as Eruda, Monaco Editor, bundled SDKs, or other vendor files in their vault.

These files are already distributed as JavaScript bundles and do not require TypeScript stripping or module transformation. Running Babel on them adds a large startup cost while providing little or no benefit.

Having a way to mark such files as prebuilt would make it practical to use large vendor libraries from Codescript Toolkit scripts.

Desired behavior

Provide a mechanism to opt specific modules out of Babel transpilation.

The exact API is flexible, but examples could include:

  • A special import/require query parameter.
  • A requireAsync option.
  • A configurable folder or glob pattern (for example, a vendor directory).
  • Another explicit mechanism chosen by the maintainer.

When a module is marked as prebuilt, Codescript Toolkit should load and execute it directly instead of passing it through the Babel pipeline.

Current behavior

All imported modules are processed through Babel before execution, including large prebuilt JavaScript bundles.

For large vendor files this can result in multi-second load times and Babel warnings about deoptimized code generation for files larger than 500 KB, even though the files are already executable JavaScript and do not require transformation.

Plugin version

13.1.1

Obsidian version

1.12.7

Attachments

sample-vault.zip

The sample vault contains two Code Buttons:

  • Test default import (with transpilation) – imports vendor/eruda.cjs (~500 KB) through the normal Codescript Toolkit pipeline. On my machine this takes approximately 5 seconds.
  • Test modified import (without transpilation) – loads the same file without Babel processing. This takes approximately 150 ms on first run (and often less on subsequent runs due to file caching).

Both buttons load the same library and display the elapsed time, making it easy to compare the overhead introduced by the Babel/transpilation pipeline.

Video

Not attached. ⚠️ Providing a video helps the maintainer understand the request and speeds up implementation.

Sample vault

Attached

Confirmations

  • I have checked the plugin's GitHub repository and haven't found any similar feature requests

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions