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

Bundling the CLI for reduced footprint failing in v4.x #603

Open
nclsndr opened this issue Jun 21, 2023 · 4 comments
Open

Bundling the CLI for reduced footprint failing in v4.x #603

nclsndr opened this issue Jun 21, 2023 · 4 comments

Comments

@nclsndr
Copy link

nclsndr commented Jun 21, 2023

I previously used [email protected] along with @vercel/ncc to bundle all the deps of a cli, thus reducing the dependency graph within my users' node_modules.

I just upgrade ink to 4.x, and I do not find a way to bundle it without producing a non 0 exit code at runtime. It seems we're conflicting upon the top level await behaviour vs what the process is actually "waiting" for.

Here a bare example using ncc

I also tried: Rollup, a manual Webpack 5 config. They are all having issues in that direction.

Did anyone has this kind of issue already?


Generally speaking, how do you ship CLI in JS when they'll be installed locally in (mono)repos?

@nclsndr nclsndr changed the title Bundling the CLI for reduced footprint Bundling the CLI for reduced footprint failing in v4.x Jun 21, 2023
@ohana54
Copy link

ohana54 commented Jul 19, 2023

We successfully bundle ink 4.x with tsup (which uses esbuild under the hood).
We declare react-devtools-core and yoga-wasm-web as externals.

@yamiteru
Copy link

Declaring react-devtools-core as externals does nothing. It's also impossible for me to build, see #614.

@ohana54
Copy link

ohana54 commented Jul 30, 2023

There might be something wrong with your setup, all I can say is that for us it works - we bundle ink and react-devtools-core stays external.
Here's our tsup config:

{
  entry: ['src/index.{ts,tsx}'],
  target: 'node16.20',
  format: 'esm',
  outDir: 'build',
  sourcemap: true,
  minify: true,
  shims: true,
  // https://github.com/evanw/esbuild/issues/1921
  banner: {
    js: `
      import { createRequire as _createRequire } from 'node:module';
      const require = _createRequire(import.meta.url);
    `,
  },
  external: [
    'react-devtools-core',
    'yoga-wasm-web',
  ],
}

@rafalglowacz
Copy link

I was able to make my build work by commenting out the devtools import after building:

node_modules/.bin/esbuild src/index.js \
  ...
  --external:react-devtools-core \
  --external:yoga-wasm-web \
  --define:process.env.NODE_ENV=\"production\"

sed -i '' 's#^import devtools#//import devtools#' dist/my-cmd.js

Feels like a hack, but I'm happy that after a few hours of tinkering it finally works. I'll see what else breaks tomorrow 😄

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

No branches or pull requests

4 participants