Skip to content

Commit 7275a82

Browse files
authored
chore: Update tsconfig and build script (#981)
### Change list - Various tsconfig and build script updates, mostly prompted by AI feedback
1 parent 64a9fa5 commit 7275a82

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

build.mjs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,29 @@ import tailwindcss from "tailwindcss";
99
// Load environment variables from .env file
1010
dotenv.config();
1111

12+
const node_env = process.env.NODE_ENV || "production";
13+
1214
// List of environment variables to expose to the build
13-
const env = {
15+
const defineEnv = {
16+
// Ref https://github.com/manzt/anywidget/issues/369#issuecomment-1792376003
17+
"define.amd": "false",
18+
"process.env.NODE_ENV": node_env,
1419
"process.env.XSTATE_INSPECT": JSON.stringify(
1520
process.env.XSTATE_INSPECT || "false",
1621
),
1722
};
1823

1924
esbuild.build({
2025
entryPoints: ["./src/index.tsx"],
21-
bundle: true,
22-
minify: true,
23-
target: ["es2022"],
2426
outdir: "lonboard/static/",
27+
bundle: true,
2528
format: "esm",
26-
// Ref https://github.com/manzt/anywidget/issues/369#issuecomment-1792376003
27-
define: {
28-
"define.amd": "false",
29-
...env,
30-
},
29+
target: ["es2022"],
30+
// Build sourcemaps when not in prod
31+
sourcemap: node_env !== "production",
32+
// Minify only in prod
33+
minify: node_env === "production",
34+
define: defineEnv,
3135
plugins: [
3236
sassPlugin({
3337
async transform(source) {
@@ -40,6 +44,7 @@ esbuild.build({
4044
},
4145
}),
4246
],
47+
platform: "browser",
4348
loader: {
4449
".worker.js": "text",
4550
".worker.min.js": "text",

eslint.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import tseslint from "typescript-eslint";
88
export default [
99
{ files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"] },
1010
{ languageOptions: { globals: globals.browser } },
11+
// Esbuild build script should have access to Node globals
12+
{
13+
files: ["build.mjs"],
14+
languageOptions: { globals: globals.node },
15+
},
1116
pluginJs.configs.recommended,
1217
...tseslint.configs.recommended,
1318
pluginReact.configs.flat.recommended,

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@
7373
},
7474
"scripts": {
7575
"build": "node ./build.mjs",
76-
"build:watch": "nodemon --watch src/ --exec \"npm run build\" --ext js,json,ts,tsx,css",
76+
"build:dev": "NODE_ENV=development node ./build.mjs",
77+
"build:watch": "nodemon --watch src/ --exec \"npm run build:dev\" --ext js,json,ts,tsx,css",
7778
"prettier:check": "prettier './src/**/*.{ts,tsx,css}' --check",
7879
"prettier": "prettier './src/**/*.{ts,tsx,css}' --write",
7980
"lint": "eslint src",

tsconfig.json

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,26 @@
22
"include": ["src/**/*"],
33
"exclude": ["node_modules"],
44
"compilerOptions": {
5+
"module": "esnext",
56
"moduleResolution": "node",
6-
"module": "ES2022",
7-
"outDir": "./dist",
8-
"allowJs": true,
97
"target": "ES2022",
8+
9+
"outDir": "./dist",
10+
"rootDir": "src",
1011
"declaration": true,
12+
"declarationMap": true,
13+
"sourceMap": true,
14+
15+
"strict": true,
16+
"skipLibCheck": true,
17+
"strictNullChecks": true,
18+
1119
"noEmit": false,
1220
"noEmitOnError": false,
13-
"esModuleInterop": true,
1421
"forceConsistentCasingInFileNames": true,
15-
"jsx": "react",
16-
"skipLibCheck": true,
17-
"strict": true,
18-
"strictNullChecks": true,
19-
// "lib": [
20-
// "es2019.array", "es6", "dom"
21-
// ],
22-
"rootDir": "."
22+
"esModuleInterop": true,
23+
24+
"jsx": "react-jsx",
25+
"allowJs": true
2326
}
2427
}

0 commit comments

Comments
 (0)