News for hackers. Stuff that matters.
Re:Vite – Next Generation Front End Tooling by dfee on Sunday July 03, 2022 @11:31AM (#31968455)
I can’t find a vite solution for NodeJS which is disappointing. If anyone has figured out a way to ship the minimal amount of code from a NodeJS monorepo (ideally with web and server code, but generally decoupled) I’d enjoy seeing the solution!
Re:Vite – Next Generation Front End Tooling by lioeters on Sunday July 03, 2022 @12:17PM (#31968791)
I'd recommend using ESBuild directly. The following article helped me recently to figure out how to build a browser-side library to publish to NPM, as well as bundling a Node.js server to deploy.

Build A Library With esbuild - How to bundle ESM, IIFE or CommonJS libraries with esbuild

https://medium.com/geekculture/build-a-library-with-esbuild-...

---

I had to figure out a trick for Node side to exclude external modules. In my build script:

  const esbuild = require('esbuild')
  const { dependencies, peerDependencies } = require('./package.json')

  const external = [
    ...Object.keys(dependencies),
    ...Object.keys(peerDependencies)
  ]

  await esbuild
    .build({
      entryPoints: ['src/index.ts'],
      outfile: 'lib/index.mjs',
      bundle: true,
      sourcemap: false,
      minify: false,
      splitting: false,
      format: 'esm',
      target: ['esnext'],
      external
    }),
Re:Vite – Next Generation Front End Tooling by somishere on Sunday July 03, 2022 @12:28PM (#31968894)
It's possible. I often use vite with multiple build targets (decoupled but with code sharing) .. this can be specified in the rollup config options but my specific build process uses two separate vite configs to resolve some chunking challenges. Everything is parallelised for dev/build in an npm script. From memory there's a bunch of conversations relating to this kind of setup in the GitHub issues.

Edit: vite allows you to specify (e.g. node specific) exclusions/globals in the config, it also allows you to specify a 'library' build if that's what you're interested in .. with named exports, etc.

Re:Vite – Next Generation Front End Tooling by gkiely on Monday July 04, 2022 @01:04AM (#31973655)
There is vite-node: https://www.npmjs.com/package/vite-node

Here's a monorepo example, it's using cloudflare workers instead of node. But you could set up a vite-node server using concurrently or create a vite plugin.

https://github.com/gkiely/vite-app-starter