mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-23 12:57:04 +00:00
WIP: bundle the lsp wasm inside browserServerMain.js
* Use wasm-pack's web mode to create a .wasm file and an ESM module for the glue code * Import the .wasm file directly in browserServerMain.ts * And process it all with esbuild, which succeeds in seeing the .wasm import in browserServerMain.ts and then bundles it inline.
This commit is contained in:
parent
8f03e2cff1
commit
1437648df1
3 changed files with 77 additions and 29 deletions
|
|
@ -6,7 +6,10 @@ import { createConnection, BrowserMessageReader, BrowserMessageWriter } from 'vs
|
|||
import { Color, ColorInformation, Range, InitializeParams, InitializeResult, ServerCapabilities, TextDocuments, ColorPresentation, TextEdit, TextDocumentIdentifier } from 'vscode-languageserver';
|
||||
import { TextDocument } from 'vscode-languageserver-textdocument';
|
||||
|
||||
import * as slint_lsp from "../../../tools/lsp/pkg";
|
||||
import { default as slint_lsp_init } from "../../../tools/lsp/pkg/index.js";
|
||||
import slint_wasm_data from "../../../tools/lsp/pkg/index_bg.wasm";
|
||||
|
||||
slint_lsp_init(slint_wasm_data).then((slint_lsp) => {
|
||||
|
||||
console.log('Hello from the worker', slint_lsp);
|
||||
|
||||
|
|
@ -38,3 +41,5 @@ connection.onDidOpenTextDocument((param) => {
|
|||
// Listen on the connection
|
||||
connection.listen();
|
||||
|
||||
})
|
||||
|
||||
|
|
|
|||
41
editor/vscode/esbuild.js
Normal file
41
editor/vscode/esbuild.js
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
let wasmPlugin = {
|
||||
name: 'wasm',
|
||||
setup(build) {
|
||||
let path = require('path')
|
||||
let fs = require('fs')
|
||||
|
||||
// Resolve ".wasm" files to a path with a namespace
|
||||
build.onResolve({ filter: /\.wasm$/ }, args => {
|
||||
return {
|
||||
path: path.isAbsolute(args.path) ? args.path : path.join(args.resolveDir, args.path),
|
||||
namespace: 'wasm-binary',
|
||||
}
|
||||
})
|
||||
|
||||
// Virtual modules in the "wasm-binary" namespace contain the
|
||||
// actual bytes of the WebAssembly file. This uses esbuild's
|
||||
// built-in "binary" loader instead of manually embedding the
|
||||
// binary data inside JavaScript code ourselves.
|
||||
build.onLoad({ filter: /.*/, namespace: 'wasm-binary' }, async (args) => {
|
||||
return ({
|
||||
contents: await fs.promises.readFile(args.path),
|
||||
loader: 'binary',
|
||||
});
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
require('esbuild').build({
|
||||
entryPoints: ['src/browser.ts'],
|
||||
bundle: true,
|
||||
external: ['vscode'],
|
||||
outfile: 'out/browser.js',
|
||||
}).catch(() => process.exit(1))
|
||||
|
||||
|
||||
require('esbuild').build({
|
||||
entryPoints: ['browser-language-server/browserServerMain.ts'],
|
||||
bundle: true,
|
||||
outfile: 'out/browserServerMain.js',
|
||||
plugins: [wasmPlugin],
|
||||
}).catch(() => process.exit(1))
|
||||
|
|
@ -89,7 +89,7 @@
|
|||
"scripts": {
|
||||
"vscode:prepublish": "npm run compile",
|
||||
"compile": "tsc -p ./",
|
||||
"compile-web": "webpack",
|
||||
"compile-web": "wasm-pack build --target web --out-name index ../../tools/lsp && node ./esbuild.js",
|
||||
"local-package": "mkdir -p bin && cp ../../target/debug/slint-lsp bin/ && npx vsce package",
|
||||
"watch": "tsc -watch -p ./",
|
||||
"pretest": "npm run compile && npm run lint",
|
||||
|
|
@ -101,19 +101,21 @@
|
|||
"@types/mocha": "^8.0.4",
|
||||
"@types/node": "^12.11.7",
|
||||
"@types/vscode": "^1.52.0",
|
||||
"@types/webpack-env": "^1.16.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.9.0",
|
||||
"@typescript-eslint/parser": "^4.9.0",
|
||||
"@wasm-tool/wasm-pack-plugin": "github:wasm-tool/wasm-pack-plugin",
|
||||
"esbuild": "^0.14.39",
|
||||
"eslint": "^7.15.0",
|
||||
"glob": "^7.1.6",
|
||||
"mocha": "^8.1.3",
|
||||
"typescript": "^4.1.2",
|
||||
"vscode-test": "^1.4.1",
|
||||
"ts-loader": "^9.2.2",
|
||||
"webpack": "^5.38.1",
|
||||
"webpack-cli": "^4.7.0",
|
||||
"@types/webpack-env": "^1.16.0",
|
||||
"path-browserify": "^1.0.1",
|
||||
"@wasm-tool/wasm-pack-plugin": "github:wasm-tool/wasm-pack-plugin"
|
||||
"ts-loader": "^9.2.2",
|
||||
"typescript": "^4.1.2",
|
||||
"vscode-languageserver": "^8.0.1",
|
||||
"vscode-test": "^1.4.1",
|
||||
"webpack": "^5.38.1",
|
||||
"webpack-cli": "^4.7.0"
|
||||
},
|
||||
"__metadata": {
|
||||
"id": "73b2e4cc-8183-4df0-bc22-29b5f748d788",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue