discourse/app/assets/javascripts/theme-transpiler/build.js
David Taylor 834ea70b1c
DEV: Improve postcss error handling (#31420)
Followup to 087e8e4bdb

- Fixes the variable-prefixer so it doesn't explode when the input is
unparseable
- Add URL polyfills so that postcss can print its errors properly
- Catch postcss errors in the same way as sass errors
2025-02-20 16:48:22 +00:00

64 lines
1.5 KiB
JavaScript
Vendored

// See: https://esbuild.github.io/plugins/#webassembly-plugin
const esbuild = require("esbuild");
const path = require("node:path");
const fs = require("node:fs");
let wasmPlugin = {
name: "wasm",
setup(build) {
build.onResolve({ filter: /\.wasm$/ }, (args) => {
if (args.namespace === "wasm-stub") {
return {
path: args.path,
namespace: "wasm-binary",
};
}
if (args.resolveDir === "") {
return;
}
return {
path: path.isAbsolute(args.path)
? args.path
: path.join(args.resolveDir, args.path),
namespace: "wasm-stub",
};
});
build.onLoad({ filter: /.*/, namespace: "wasm-stub" }, async (args) => {
return {
contents: `export { default } from ${JSON.stringify(args.path)};`,
};
});
build.onLoad({ filter: /.*/, namespace: "wasm-binary" }, async (args) => {
return {
contents: await fs.promises.readFile(args.path),
loader: "binary",
};
});
},
};
esbuild
.build({
logLevel: "warning",
bundle: true,
minify: false,
alias: {
util: "./node_modules/@zxing/text-encoding",
path: "path-browserify",
url: "./url-polyfill",
"source-map-js": "source-map-js",
},
banner: {
js: `var process = { "env": { "EMBER_ENV": "production" }, "cwd": () => "/" };`,
},
external: [],
entryPoints: ["./transpiler.js"],
plugins: [wasmPlugin],
})
.then(() => {});