mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-31 15:47:26 +00:00

This patch has no effect on the currently generated output (apart from a dummy few lines in out/extension.js), but may help to avoid issues in the future like we had last week, where esbuild processed an import from "vscode-languageclient" and due to browser mode it picked the browser version of the languageclient for out/extension.js that's running in the node environment.
84 lines
2.3 KiB
JavaScript
84 lines
2.3 KiB
JavaScript
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
|
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
|
|
|
|
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",
|
|
};
|
|
},
|
|
);
|
|
},
|
|
};
|
|
|
|
let esbuild = require("esbuild");
|
|
esbuild
|
|
.build({
|
|
entryPoints: ["src/browser.ts"],
|
|
bundle: true,
|
|
external: ["vscode"],
|
|
outfile: "out/browser.js",
|
|
format: "cjs",
|
|
platform: "browser",
|
|
})
|
|
.catch(() => process.exit(1));
|
|
|
|
esbuild
|
|
.build({
|
|
entryPoints: ["src/browser-lsp-worker.ts"],
|
|
bundle: true,
|
|
outfile: "out/browserServerMain.js",
|
|
format: "iife",
|
|
platform: "browser",
|
|
plugins: [wasmPlugin],
|
|
})
|
|
.catch(() => process.exit(1));
|
|
|
|
esbuild
|
|
.build({
|
|
entryPoints: ["src/extension.ts"],
|
|
bundle: true,
|
|
external: [
|
|
"vscode",
|
|
"vscode-languageclient",
|
|
"vscode-languageclient/node",
|
|
"path",
|
|
"fs",
|
|
],
|
|
outfile: "out/extension.js",
|
|
platform: "node",
|
|
format: "cjs",
|
|
})
|
|
.catch(() => process.exit(1));
|
|
|
|
esbuild
|
|
.build({
|
|
entryPoints: ["src/propertiesView.ts"],
|
|
bundle: true,
|
|
outfile: "out/propertiesView.js",
|
|
platform: "browser",
|
|
format: "iife",
|
|
})
|
|
.catch(() => process.exit(1));
|