Skip to content

Conversation

@Andarist
Copy link
Member

No description provided.

@Andarist Andarist requested a review from s0 May 11, 2025 07:42
@changeset-bot
Copy link

changeset-bot bot commented May 11, 2025

🦋 Changeset detected

Latest commit: 54cdcaf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@changesets/action Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Base automatically changed from tsc-on-ci to main May 11, 2025 09:01
@Andarist Andarist merged commit cf373e4 into main May 11, 2025
1 check passed
@Andarist Andarist deleted the use-esbuild branch May 11, 2025 18:55
@github-actions github-actions bot mentioned this pull request May 11, 2025
},
"scripts": {
"build": "ncc build src/index.ts -o dist --transpile-only --minify",
"build": "esbuild src/index.ts --bundle --platform=node --target=node20 --minify --outfile=dist/index.js",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to use Vite but I couldn't quickly figure out the correct set of options to bundle a node script alone, without index.html etc. cc @bluwy - you might know how to do that ;p

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably best to use esbuild directly. Personally Vite isn't the best or most flexible when bundling libraries.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This here is not quite a library - it's an executable script. I was hoping to get better tree-shaking from Vite than from esbuild

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has the same-ish issue with setting up bundling that too. I think esbuild is pretty good for this and treeshaking, but you could use rollup to match with vite's. Vite doesn't add anything on top of rollup that improves its treeshaking though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I have just wanted to use Vite as a pre-configured Rollup in this case. FWIW, I ran an experiment with raw Rollup now and for gzip -c dist/index.js | wc -c I got 377840 -> 366375 improvement. That sits at 3% and given I had to put together multiple plugins manually... I think it's not quite worth it 📦

Config for reference:

import { defineConfig } from "rollup";
import commonjs from "@rollup/plugin-commonjs";
import nodeResolve from "@rollup/plugin-node-resolve";
import terser from "@rollup/plugin-terser";
import json from "@rollup/plugin-json";
import { transform } from "esbuild";

export default defineConfig({
  input: "src/index.ts",
  output: {
    dir: "dist",
    format: "esm",
  },
  plugins: [
    nodeResolve({
      preferBuiltins: false,
    }),
    json(),
    commonjs(),
    {
      name: "esbuild",
      async transform(code, id) {
        if (!/\.(mts|cts|ts|tsx)$/.test(id)) {
          return null;
        }
        const result = await transform(code, {
          loader: "ts",
        });
        return result.code;
      },
    },
    terser(),
  ],
});

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I might have to roll with the above if I want to test out ESM output. esbuild's ESM output doesn't quite work - from what I can tell... it doesn't even quite output ESM in my case, despite --format=esm 🤷

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I got further with Vite but it just ignores both external and minify in this config. I don't know why

import { defineConfig } from "vite";

export default defineConfig({
  build: {
    ssr: true,
    lib: {
      entry: ["src/index.ts"],
      formats: ["es"],
    },
    minify: "terser",
    rollupOptions: {
      external: (id) => id.startsWith("node:"),
    },
  },
});

valpinkman added a commit to LedgerHQ/changeset-action-ledger that referenced this pull request Aug 4, 2025
* upstream/main: (28 commits)
  Version Packages (changesets#480)
  Fixed missed `__dirname` reference (changesets#496)
  Switch to bundling with Rollup (changesets#495)
  Migrate to ESM (changesets#484)
  Fixed situations in which `cwd` was specified as a relative path and used with (default) `commitMode: git-cli` (changesets#486)
  Add LICENSE file (changesets#491)
  Fix PRs sometimes not getting reopened with `commitMode: github-api` (changesets#488)
  Removed `fs-extra` dependency (changesets#481)
  Setup Git user in `release-pr` workflow (changesets#493)
  Use proper ndoe version in `release-pr` workflow (changesets#492)
  Add `release-pr` workflow (changesets#490)
  Migrate to Vitest (changesets#483)
  Switch to `esbuild` for bundling (changesets#479)
  Import only for `semver/functions/lt` (changesets#482)
  Avoid hitting a deprecation warning when encountering errors from `@octokit/request-error` (changesets#461)
  Run typecheck on CI (changesets#478)
  Updated `@actions/*` and `@octokit/*` dependencies (changesets#477)
  Bump @babel/runtime from 7.21.5 to 7.27.1 (changesets#464)
  Version Packages (changesets#476)
  Make git add work consistently with subdirectories (changesets#473)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants