Use tsconfig.json

This commit is contained in:
Adria Navarro 2023-05-03 14:04:54 +01:00
parent d7f7ad5b5f
commit 561cd40666
4 changed files with 10 additions and 6 deletions

View File

@ -15,7 +15,7 @@
"license": "GPL-3.0", "license": "GPL-3.0",
"scripts": { "scripts": {
"prebuild": "rimraf dist/", "prebuild": "rimraf dist/",
"build": "node ../../scripts/build.js -p tsconfig.build.json --outdir dist/mjs/src && node ../../scripts/build.js -p tsconfig-cjs.build.json --outdir dist/cjs/src", "build": "node ../../scripts/build.js && node ../../scripts/build.js -p tsconfig-cjs.build.json",
"build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput", "build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput",
"dev:builder": "yarn prebuild && concurrently \"tsc -p tsconfig.build.json --watch\" \"tsc -p tsconfig-cjs.build.json --watch\"" "dev:builder": "yarn prebuild && concurrently \"tsc -p tsconfig.build.json --watch\" \"tsc -p tsconfig-cjs.build.json --watch\""
}, },

View File

@ -2,6 +2,7 @@
"extends": "./tsconfig-base.build.json", "extends": "./tsconfig-base.build.json",
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "module": "commonjs",
"outDir": "dist/cjs/src",
"target": "es2015" "target": "es2015"
} }
} }

View File

@ -2,6 +2,7 @@
"extends": "./tsconfig-base.build.json", "extends": "./tsconfig-base.build.json",
"compilerOptions": { "compilerOptions": {
"module": "esnext", "module": "esnext",
"outDir": "dist/mjs/src",
"target": "esnext" "target": "esnext"
} }
} }

View File

@ -15,12 +15,15 @@ var argv = require("minimist")(process.argv.slice(2))
function runBuild(entry, outfile) { function runBuild(entry, outfile) {
const isDev = process.env.NODE_ENV !== "production" const isDev = process.env.NODE_ENV !== "production"
const tsconfig = argv["p"] || `tsconfig.build.json`
const tsconfigContent = require(`${process.cwd()}/${tsconfig}`)
const sharedConfig = { const sharedConfig = {
entryPoints: [entry], entryPoints: [entry],
bundle: true, bundle: true,
minify: !isDev, minify: !isDev,
tsconfig: argv["p"] || `tsconfig.build.json`, tsconfig,
plugins: [ plugins: [
sveltePlugin(), sveltePlugin(),
NodeResolve({ NodeResolve({
@ -40,12 +43,12 @@ function runBuild(entry, outfile) {
external: isDev ? ["@budibase/client"] : [], external: isDev ? ["@budibase/client"] : [],
} }
const outdir = argv["outdir"] const outdir = tsconfigContent.compilerOptions?.outDir
build({ build({
...sharedConfig, ...sharedConfig,
platform: "node", platform: "node",
outdir, outdir,
outfile: outdir ? undefined : outfile, outfile,
}).then(() => { }).then(() => {
glob(`${process.cwd()}/src/**/*.hbs`, {}, (err, files) => { glob(`${process.cwd()}/src/**/*.hbs`, {}, (err, files) => {
for (const file of files) { for (const file of files) {
@ -62,8 +65,7 @@ function runBuild(entry, outfile) {
if (require.main === module) { if (require.main === module) {
const entry = argv["e"] || "./src/index.ts" const entry = argv["e"] || "./src/index.ts"
const outfile = `dist/${entry.split("/").pop().replace(".ts", ".js")}` runBuild(entry)
runBuild(entry, outfile)
} else { } else {
module.exports = runBuild module.exports = runBuild
} }