Files
ComfyUI_frontend/vite.config.mts
Chenlei Hu a28ac0c0fa New searchbox with fuzzy search (WIP) (#83)
* Disable default searchbox

Add headlessui and vue

Add vite's vue plugin

Vue app helloworld

Format vue

Add vue shim

minimal working searchbox

Add primevue dark mode

Use primevue

nit

Add fuse fuzzy search

Add tailwindcss / center searchbox

Fix style

Add node source chip

desc text wrapping

Add placeholder

inputbox filter support wip

Revert some filter designs

Add filter modal

Drop down show all nodes

Change modal font

Add filtered search

nit

Complete on focus

Auto fill filterOption

Fix dropdown

Fix z-index

Fix search bug

Properly remove chip

Adjust node source detection

Resolve merge conflict

nit

* Refactor

* Use badge to display filter type

* nit

* Trigger on canvas event

* nit

* Auto add data type filter when link released

* nit

* Auto focus when shown

* Focus on add/remvoe filter

* close dialog when escape pressed

* Add node at fixed location

* nit

* Update litegraph

* nit

* Change theme

* Increase search limit

* Add node on event location

* Clear filter when dialog closed

* Enable/Disable new search bx

* Improve app loading

* Fix copy node

* Update test expectations

* Update test expectations [skip ci]

---------

Co-authored-by: github-actions <github-actions@github.com>
2024-07-10 19:46:35 -04:00

122 lines
3.3 KiB
TypeScript

import { defineConfig, Plugin } from 'vite';
import vue from '@vitejs/plugin-vue';
import path from 'path';
import dotenv from "dotenv";
dotenv.config();
const IS_DEV = process.env.NODE_ENV === 'development';
interface ShimResult {
code: string;
exports: string[];
}
function comfyAPIPlugin(): Plugin {
return {
name: 'comfy-api-plugin',
transform(code: string, id: string) {
if (IS_DEV)
return null;
// TODO: Remove second condition after all js files are converted to ts
if (id.endsWith('.ts') || (id.endsWith('.js') && id.includes("extensions/core"))) {
const result = transformExports(code, id);
if (result.exports.length > 0) {
const projectRoot = process.cwd();
const relativePath = path.relative(path.join(projectRoot, 'src'), id);
const shimFileName = relativePath.replace(/\.ts$/, '.js');
const shimComment = `// Shim for ${relativePath}\n`;
this.emitFile({
type: "asset",
fileName: shimFileName,
source: shimComment + result.exports.join(""),
});
}
return {
code: result.code,
map: null // If you're not modifying the source map, return null
};
}
}
};
}
function transformExports(code: string, id: string): ShimResult {
const moduleName = getModuleName(id);
const exports: string[] = [];
let newCode = code;
// Regex to match different types of exports
const regex = /export\s+(const|let|var|function|class|async function)\s+([a-zA-Z$_][a-zA-Z\d$_]*)(\s|\()/g;
let match;
while ((match = regex.exec(code)) !== null) {
const name = match[2];
// All exports should be bind to the window object as new API endpoint.
if (exports.length == 0) {
newCode += `\nwindow.comfyAPI = window.comfyAPI || {};`;
newCode += `\nwindow.comfyAPI.${moduleName} = window.comfyAPI.${moduleName} || {};`;
}
newCode += `\nwindow.comfyAPI.${moduleName}.${name} = ${name};`;
exports.push(`export const ${name} = window.comfyAPI.${moduleName}.${name};\n`);
}
return {
code: newCode,
exports,
};
}
function getModuleName(id: string): string {
// Simple example to derive a module name from the file path
const parts = id.split('/');
const fileName = parts[parts.length - 1];
return fileName.replace(/\.\w+$/, ''); // Remove file extension
}
export default defineConfig({
server: {
proxy: {
'/api': {
target: process.env.DEV_SERVER_COMFYUI_URL || 'http://127.0.0.1:8188',
// Return empty array for extensions API as these modules
// are not on vite's dev server.
bypass: (req, res, options) => {
if (req.url === '/api/extensions') {
res.end(JSON.stringify([]));
}
return null;
},
},
'/ws': {
target: 'ws://127.0.0.1:8188',
ws: true,
},
}
},
plugins: [
vue(),
comfyAPIPlugin(),
],
build: {
minify: false,
sourcemap: true,
rollupOptions: {
// Disabling tree-shaking
// Prevent vite remove unused exports
treeshake: false
}
},
define: {
'__COMFYUI_FRONTEND_VERSION__': JSON.stringify(process.env.npm_package_version),
},
resolve: {
alias: {
'@': '/src'
}
}
});