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

Faster build with SWC or Esbuild #85

Open
eric-burel opened this issue Nov 12, 2021 · 3 comments · May be fixed by #128
Open

Faster build with SWC or Esbuild #85

eric-burel opened this issue Nov 12, 2021 · 3 comments · May be fixed by #128
Labels
enhancement New feature or request

Comments

@eric-burel
Copy link
Collaborator

eric-burel commented Nov 12, 2021

Is your feature request related to a problem? Please describe.
I am exploring modern alternatives to Babel/Webpack for a faster build time.

First experiment is on the react-ui package.

Describe the solution you'd like
- Need to be able to output code for Node (during SSR) and the browser (for React components)
- Need to generate .d.ts?

  • Esbuild and SWC cannot do that, and won't do that, because that's a slow heavy operation.
    However, we could generate those files only when publishing the package on NPM, or by hand. Sadly, I failed to find the right command with tsc or ts-loader. See Generates corresponding .d.ts file swc-project/swc#657

Describe alternatives you've considered

SWC

Next.js is backing SWC, so it's expected to have a lot of updates.

Be careful that SWC is a parser, so a replacement to Babel, not to Webpack. They are building "SWCpack" for this purpose but it's not there yet.

Dumping Babel may have some consequences, see vercel/next.js#30174, as SWC doesn't support all packages yet and have a smaller ecosystem.

It proposes a Webpack loader => great for fast setup by replacing babel-loader.

We need to figure the .d.ts generation thing.

Esbuild

Seems to work ok, very fast. But since Next is preferring SWC, that is written in Rust (Esbuild is in Go, so great language but less relevant for a build tool), we might go the Next.js way.

Not completely sure how it replace Babel/Webpack. But I am sure it doesn't correctly support .d.ts either: evanw/esbuild#95

Additional context
Add any other context or screenshots about the feature request here.

@eric-burel eric-burel added the enhancement New feature or request label Nov 12, 2021
@eric-burel
Copy link
Collaborator Author

This article describe an alternative, using TypeScript "build" option. Maybe it could help getting rid of Babel and Webpack? Or at least improve our Lerna workflow: https://betterstack.dev/blog/lerna-typescript-monorepo/

@eric-burel
Copy link
Collaborator Author

eric-burel commented Mar 11, 2022

About the Express starter

Converting "require" to "esm" is currently not supported
{
  column: 27,
  file: '/code/vulcan-npm/starters/express/.yalc/@vulcanjs/mongo/dist/index.js',
  length: 7,
  line: 36,
  lineText: 'var import_merge = __toESM(require("lodash/merge.js"));',
  namespace: '',
  suggestion: ''
}
Converting "require" to "esm" is currently not supported
{
  column: 19,
  file: '/code/vulcan-npm/starters/express/.yalc/@vulcanjs/mongo/dist/index.js',
  length: 7,
  line: 37,
  lineText: 'var import_utils = require("@vulcanjs/utils");',
  namespace: '',
  suggestion: ''
}
Converting "require" to "esm" is currently not supported
{
  column: 30,
  file: '/code/vulcan-npm/starters/express/.yalc/@vulcanjs/mongo/dist/index.js',
  length: 7,
  line: 38,
  lineText: 'var import_mongoose = __toESM(require("mongoose"));',
  namespace: '',
  suggestion: ''
}

It's often an issue in the way we use the library (eg mongoose should maybe use import * as mongoose because it's default is not setup correctly), but still difficult to bypass

{
  "watch": ["src"],
  "ignore": ["src/**/*.test.ts"],
  "ext": "ts,mjs,js,json,graphql",
  "exec": "yarn run build && node ./dist/app.mjs",
  "legacyWatch": true
}

@eric-burel
Copy link
Collaborator Author

Relevant thread on making the libraries tree-shakeable when they are rebuilt in the end user app (Next) and not just tree-shaked during the publication of the NPM package: egoist/tsup#578

@eric-burel eric-burel linked a pull request Jun 9, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant