Skip to content

Instantly share code, notes, and snippets.

@mizchi
Created February 26, 2021 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizchi/ae646ae7f1da39e3e37e184f02ec3a34 to your computer and use it in GitHub Desktop.
Save mizchi/ae646ae7f1da39e3e37e184f02ec3a34 to your computer and use it in GitHub Desktop.
/*
Patch typescript to run in snowpack.
I added this workaround for perf_hooks.
Add this task in package.json
"scripts": {
// ...
"postinstall": "node scripts/rewrite-ts.js",
}
*/
const fs = require("fs");
const path = require("path");
const ts_path = path.join(
__dirname,
"../node_modules/typescript/lib/typescript.js"
);
const code = fs.readFileSync(ts_path, "utf-8");
const rewrote = code.replace('require("perf_hooks")', "{}");
fs.writeFileSync(ts_path, rewrote);
console.log("patched", ts_path);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment