vite#Connect TypeScript Examples
The following examples show how to use
vite#Connect.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: workerMiddleware.ts From vite-plugin-monaco-editor with MIT License | 6 votes |
export function workerMiddleware(
middlewares: Connect.Server,
config: ResolvedConfig,
options: IMonacoEditorOpts
): void {
const works = getWorks(options);
// clear cacheDir
if (fs.existsSync(cacheDir)) {
fs.rmdirSync(cacheDir, { recursive: true, force: true } as fs.RmDirOptions);
}
for (const work of works) {
console.log(config.base + options.publicPath + '/' + getFilenameByEntry(work.entry))
middlewares.use(
config.base + options.publicPath + '/' + getFilenameByEntry(work.entry),
function (req, res, next) {
if (!fs.existsSync(cacheDir + getFilenameByEntry(work.entry))) {
esbuild.buildSync({
entryPoints: [resolveMonacoPath(work.entry)],
bundle: true,
outfile: cacheDir + getFilenameByEntry(work.entry),
});
}
const contentBuffer = fs.readFileSync(cacheDir + getFilenameByEntry(work.entry));
res.setHeader('Content-Type', 'text/javascript');
res.end(contentBuffer);
}
);
}
}