buildServer scripts

This commit is contained in:
Ulf Gebhardt 2024-01-09 07:10:05 +01:00
parent 3fad56a538
commit b1c18350fe
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
3 changed files with 79 additions and 0 deletions

View File

@ -0,0 +1,56 @@
import path from 'node:path'
import { fileURLToPath } from 'url'
// eslint-disable-next-line import/no-extraneous-dependencies
import { build } from 'esbuild'
// eslint-disable-next-line import/no-extraneous-dependencies
import fs, { ensureDir, remove } from 'fs-extra'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
async function buildServer() {
const result = await build({
absWorkingDir: process.cwd(),
entryPoints: [path.join(path.resolve(__dirname, '../../server/'), 'index.ts')],
outfile: 'index.cjs',
write: false,
minify: true,
platform: 'node',
bundle: true,
format: 'cjs',
sourcemap: false,
treeShaking: true,
define: { 'import.meta.url': 'importMetaUrl', 'process.env.NODE_ENV': '"production"' },
inject: [path.resolve(__dirname, './import.meta.url-polyfill.ts')],
banner: {
js: `/* eslint-disable prettier/prettier */`,
},
tsconfig: path.resolve(__dirname, './tsconfig.buildServer.json'),
plugins: [
{
name: 'externalize-deps',
setup(build) {
build.onResolve({ filter: /.*/ }, (args) => {
const id = args.path
if (id[0] !== '.' && !path.isAbsolute(id)) {
return {
external: true,
}
}
})
},
},
],
})
const { text } = result.outputFiles[0]
const filePath = path.join(path.resolve(__dirname, '../../build/'), 'index.cjs')
if (fs.existsSync(filePath)) {
await remove(filePath)
}
await ensureDir(path.dirname(filePath))
// eslint-disable-next-line import/no-named-as-default-member
await fs.writeFile(filePath, text)
}
void buildServer()

View File

@ -0,0 +1,7 @@
/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-explicit-any */
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
export const importMetaUrl =
typeof document === 'undefined'
? (new (require('url').URL)('file:' + __filename) as URL).href
: (document.currentScript && (document.currentScript as any).src) ||
new URL('main.js', document.baseURI).href

View File

@ -0,0 +1,16 @@
{
"compilerOptions": {
"baseUrl": ".",
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"isolatedModules": true,
"lib": ["esnext", "dom", "DOM.Iterable"],
"strict": false,
"sourceMap": false,
"resolveJsonModule": true,
"skipLibCheck": true,
"esModuleInterop": true,
"declaration": false
}
}