mirror of
https://github.com/IT4Change/boilerplate-frontend.git
synced 2025-12-13 07:35:53 +00:00
buildServer scripts
This commit is contained in:
parent
3fad56a538
commit
b1c18350fe
56
scripts/buildServer/buildServer.ts
Normal file
56
scripts/buildServer/buildServer.ts
Normal 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()
|
||||
7
scripts/buildServer/import.meta.url-polyfill.ts
Normal file
7
scripts/buildServer/import.meta.url-polyfill.ts
Normal 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
|
||||
16
scripts/buildServer/tsconfig.buildServer.json
Normal file
16
scripts/buildServer/tsconfig.buildServer.json
Normal 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
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user