Skip to content

Using vite dev server to serve bundles #16657

Answered by unshame
unshame asked this question in Q&A
Discussion options

You must be logged in to vote

Ended up writing this plugin:

import { URL, fileURLToPath } from 'node:url'
import * as fs from 'node:fs'
import * as path from 'node:path'

import * as walk from 'acorn-walk'
import { parse } from 'acorn'
import * as resolve from 'resolve.exports'
import findRoot from 'find-root'
import { mergeConfig } from 'vite'

/**
 * Allows other vite apps to load dependencies from this vite app.
 *
 * In serve mode: adds /shared-deps?import=<dep> endpoint to the dev server, redirecting to the path resolved by vite
 * In build mode: bundles each dependency into a separate bundle
 *
 * @param externals {string[]}
 * @param dependencies {Record<string, string>}
 * @param subpaths {Record<string, strin…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by unshame
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant