Commit 3798f4da authored by nanahira's avatar nanahira

fix browser build

parent 38cbcf13
Pipeline #42811 passed with stages
in 1 minute and 23 seconds
......@@ -19,12 +19,6 @@
"options": {
"browser": "src/main.ts",
"tsConfig": "tsconfig.app.json",
"externalDependencies": [
"fs",
"path",
"crypto",
"util"
],
"assets": [
{
"glob": "**/*",
......
......@@ -21,6 +21,12 @@
}
]
},
"browser": {
"fs": false,
"path": false,
"crypto": false,
"util": false
},
"private": true,
"packageManager": "npm@11.6.2",
"dependencies": {
......
export function randomBytes(length: number): Uint8Array {
const bytes = new Uint8Array(length);
if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {
crypto.getRandomValues(bytes);
return bytes;
}
for (let i = 0; i < length; i += 1) {
bytes[i] = Math.floor(Math.random() * 256);
}
return bytes;
}
export type PathLike = string;
export function existsSync(): boolean {
return false;
}
export function readFileSync(): Uint8Array {
throw new Error('fs.readFileSync is not available in the browser.');
}
export function dirname(path: string): string {
const normalized = path.replace(/\\/g, '/');
const idx = normalized.lastIndexOf('/');
if (idx <= 0) {
return '.';
}
return normalized.slice(0, idx);
}
export function join(...parts: string[]): string {
return parts
.filter((part) => part.length > 0)
.join('/')
.replace(/\\/g, '/')
.replace(/\/+/g, '/');
}
export function inspect(value: unknown): string {
try {
return typeof value === 'string' ? value : JSON.stringify(value);
} catch {
return String(value);
}
}
......@@ -13,7 +13,22 @@
"experimentalDecorators": true,
"importHelpers": true,
"target": "ES2022",
"module": "preserve"
"module": "preserve",
"baseUrl": ".",
"paths": {
"fs": [
"src/shims/node/fs.ts"
],
"path": [
"src/shims/node/path.ts"
],
"crypto": [
"src/shims/node/crypto.ts"
],
"util": [
"src/shims/node/util.ts"
]
}
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment