discourse/app/assets/javascripts/theme-transpiler/build.js
David Taylor 1b28b8e169
DEV: Upgrade babel & remove vendored safari-bugfix transformation (#28208)
The Safari 15 bugfix has been rolled into @babel/preset-env in the most recent version, so we no longer need to carry our vendored copy.

This commit updates @babel/preset-env, runs npx yarn-deduplicate yarn.lock, and removes the vendored transform.

This commit also refactors our theme transpiler to use @babel/preset-env, with the same list of target browsers as our ember-cli build uses. This means we no longer need to maintain a separate list of babel transforms for themes.
2024-08-05 10:35:26 +01:00

62 lines
1.4 KiB
JavaScript

// 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: true,
alias: {
util: "./node_modules/@zxing/text-encoding",
},
define: {
process: `{ "env": { "EMBER_ENV": "production" } }`,
},
external: ["fs", "path"],
entryPoints: ["./app/assets/javascripts/theme-transpiler/transpiler.js"],
plugins: [wasmPlugin],
})
.then(() => {});