Add vite build (#53)

* Add vite build - baseline

* Fix build output folder structure

Matches pre-vite output

* Fix litegraph errors introduced by vite process

- Remove pre-written encapsulating iife (one is injected by vite)
- Replace all references to the global "this" with globalThis
This commit is contained in:
filtered
2024-08-06 23:14:17 +10:00
committed by GitHub
parent d2c72243f8
commit ddd1ac4f99
7 changed files with 135 additions and 73 deletions

32
.gitignore vendored
View File

@@ -1,12 +1,32 @@
node_modules/
node_modules/*
npm-debug.log
temp/
temp/*
coverage/
# Editors
/.vscode/*
!/.vscode/extensions.json
*.bak
.project
.project
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

View File

@@ -1,52 +1,42 @@
{
"name": "@comfyorg/litegraph",
"version": "0.7.35",
"description": "A graph node editor similar to PD or UDK Blueprints. It works in an HTML5 Canvas and allows to export graphs to be included in applications.",
"main": "src/litegraph.js",
"types": "src/litegraph.d.ts",
"directories": {
"doc": "doc"
},
"private": false,
"scripts": {
"prebuild": "rimraf build",
"build": "grunt build",
"start": "nodemon utils/server.js",
"test": "jest",
"test:allVersions": "./utils/test.sh",
"prettier": "npx prettier --write src/**/*.* css/**/*.*",
"lint": "npx eslint src",
"lint:fix": "npx eslint --fix src"
},
"repository": {
"type": "git",
"url": "git@github.com:Comfy-Org/litegraph.js.git"
},
"author": "comfyorg",
"license": "MIT",
"files": [
"src/litegraph.js",
"css/litegraph.css",
"src/litegraph.d.ts"
],
"bugs": {
"url": "https://github.com/Comfy-Org/litegraph.js/issues"
},
"homepage": "https://github.com/Comfy-Org/litegraph.js",
"devDependencies": {
"@types/jest": "^28.1.3",
"eslint": "^8.37.0 ",
"eslint-plugin-jest": "^27.2.1",
"express": "^4.17.1",
"google-closure-compiler": "^20230411.0.0",
"grunt": "^1.1.0",
"grunt-cli": "^1.2.0",
"grunt-closure-tools": "^1.0.0",
"grunt-contrib-concat": "^2.1.0",
"jest": "^28.1.3",
"jest-cli": "^28.1.3",
"nodemon": "^2.0.22",
"rimraf": "^5.0.0",
"yuidocjs": "^0.10.2"
}
}
"name": "@comfyorg/litegraph",
"version": "0.7.35",
"type": "module",
"description": "A graph node editor similar to PD or UDK Blueprints. It works in an HTML5 Canvas and allows to export graphs to be included in applications.",
"main": "src/litegraph.js",
"types": "src/litegraph.d.ts",
"directories": {
"doc": "doc"
},
"private": false,
"scripts": {
"build": "tsc && vite build",
"dev": "vite",
"preview": "vite preview",
"deprecated-prebuild": "rimraf build",
"deprecated-start": "nodemon utils/server.js",
"deprecated-test": "jest",
"deprecated-test:allVersions": "./utils/test.sh",
"deprecated-prettier": "npx prettier --write src/**/*.* css/**/*.*",
"deprecated-lint": "npx eslint src",
"deprecated-lint:fix": "npx eslint --fix src"
},
"repository": {
"type": "git",
"url": "git@github.com:Comfy-Org/litegraph.js.git"
},
"author": "comfyorg",
"license": "MIT",
"files": [
"dist"
],
"bugs": {
"url": "https://github.com/Comfy-Org/litegraph.js/issues"
},
"homepage": "https://github.com/Comfy-Org/litegraph.js",
"devDependencies": {
"@types/node": "^22.1.0",
"typescript": "^5.2.2",
"vite": "^5.3.4"
}
}

0
css/litegraph.css → public/css/litegraph.css Executable file → Normal file
View File

0
src/litegraph.d.ts → public/src/litegraph.d.ts vendored Executable file → Normal file
View File

View File

@@ -1,5 +1,4 @@
(function(global) {
// *************************************************************
// LiteGraph CLASS *******
// *************************************************************
@@ -11,7 +10,7 @@
* @constructor
*/
var LiteGraph = (global.LiteGraph = {
var LiteGraph = (globalThis.LiteGraph = {
VERSION: 0.4,
CANVAS_GRID_SIZE: 10,
@@ -783,7 +782,7 @@
}
}
global.LGraph = LiteGraph.LGraph = LGraph;
globalThis.LGraph = LiteGraph.LGraph = LGraph;
//default supported types
LGraph.supported_types = ["number", "string", "boolean"];
@@ -2411,7 +2410,7 @@
this._ctor(title);
}
global.LGraphNode = LiteGraph.LGraphNode = LGraphNode;
globalThis.LGraphNode = LiteGraph.LGraphNode = LGraphNode;
LGraphNode.prototype._ctor = function(title) {
this.title = title || "Unnamed";
@@ -4904,7 +4903,7 @@ LGraphNode.prototype.executeAction = function(action)
this._ctor(title);
}
global.LGraphGroup = LiteGraph.LGraphGroup = LGraphGroup;
globalThis.LGraphGroup = LiteGraph.LGraphGroup = LGraphGroup;
LGraphGroup.prototype._ctor = function(title) {
this.title = title || "Group";
@@ -5360,7 +5359,7 @@ LGraphNode.prototype.executeAction = function(action)
this.autoresize = options.autoresize;
}
global.LGraphCanvas = LiteGraph.LGraphCanvas = LGraphCanvas;
globalThis.LGraphCanvas = LiteGraph.LGraphCanvas = LGraphCanvas;
LGraphCanvas.DEFAULT_BACKGROUND_IMAGE = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII=";
@@ -14504,7 +14503,7 @@ LGraphNode.prototype.executeAction = function(action)
function clamp(v, a, b) {
return a > v ? a : b < v ? b : v;
};
global.clamp = clamp;
globalThis.clamp = clamp;
if (typeof window != "undefined" && !window["requestAnimationFrame"]) {
window.requestAnimationFrame =
@@ -14514,15 +14513,14 @@ LGraphNode.prototype.executeAction = function(action)
window.setTimeout(callback, 1000 / 60);
};
}
})(this);
if (typeof exports != "undefined") {
exports.LiteGraph = this.LiteGraph;
exports.LGraph = this.LGraph;
exports.LLink = this.LLink;
exports.LGraphNode = this.LGraphNode;
exports.LGraphGroup = this.LGraphGroup;
exports.DragAndScale = this.DragAndScale;
exports.LGraphCanvas = this.LGraphCanvas;
exports.ContextMenu = this.ContextMenu;
exports.LiteGraph = globalThis.LiteGraph;
exports.LGraph = globalThis.LGraph;
exports.LLink = globalThis.LLink;
exports.LGraphNode = globalThis.LGraphNode;
exports.LGraphGroup = globalThis.LGraphGroup;
exports.DragAndScale = globalThis.DragAndScale;
exports.LGraphCanvas = globalThis.LGraphCanvas;
exports.ContextMenu = globalThis.ContextMenu;
}

33
tsconfig.json Normal file
View File

@@ -0,0 +1,33 @@
{
"compilerOptions": {
"target": "ES2022",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
"sourceMap": true,
"esModuleInterop": true,
"moduleResolution": "Node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
/* Linting */
"strict": false,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noFallthroughCasesInSwitch": true,
"downlevelIteration": true,
/* AllowJs during migration phase */
"allowJs": true,
"baseUrl": ".",
"paths": {
"@/*": ["src/*"],
},
// TODO: Remove workaround from initial vite impl: public/src
"typeRoots": ["src/types", "node_modules/@types", "public/src"],
"outDir": "./dist",
"rootDir": "./",
},
"include": ["src/**/*"]
}

21
vite.config.mts Normal file
View File

@@ -0,0 +1,21 @@
import { defineConfig } from 'vite'
import path from 'path'
export default defineConfig({
build: {
lib: {
entry: path.resolve(__dirname, 'src/litegraph.js'),
name: 'litegraph.js',
// TODO: Below workaround ensures output matches pre-vite format. Should be removed.
fileName: (moduleFormat, entryAlias) => 'src/litegraph.js',
formats: ['iife']
},
minify: false,
sourcemap: true,
rollupOptions: {
// Disabling tree-shaking
// Prevent vite remove unused exports
treeshake: false
}
},
})