From 7d6240e28a049c7611d8174e09d3c97e61766f62 Mon Sep 17 00:00:00 2001 From: Jan Andrle Date: Wed, 20 May 2026 14:40:00 +0200 Subject: [PATCH] :bug: :tv: fixes dev server --- bs/start | 12 +++++---- tsconfig.json | 55 ++++++++++++++++++++++++++-------------- web-dev-server.config.js | 26 +++++++++++-------- 3 files changed, 59 insertions(+), 34 deletions(-) diff --git a/bs/start b/bs/start index 8c8b7f6..b88fd2f 100755 --- a/bs/start +++ b/bs/start @@ -9,15 +9,17 @@ set -eo pipefail # this can be harmful, see https://www.youtube.com/watch?v=4Jo3 # depends on declare -r server='node_modules/.bin/web-dev-server' declare -r lint='bs/lint' -declare -r index='index.html' +declare -r server_config='web-dev-server.config.js' help(){ if ! isHelp "${@}"; then return 0; fi echoReadmeInfo cat <<-EOF - Options: ./src Starts the development server (default) ./dist Starts the production server + + Defaults: + See server config file: '$server_config' EOF $server --help exit 0 @@ -26,12 +28,12 @@ main(){ help "${@}" local -r target="${1:-./src}" # ./src or ./dist - if [[ "$target" == './dist' ]]; then + if [[ "$target" =~ 'dist' ]]; then # console warns because of config file, use npx serve? - $server --root-dir "$target" --app-index $index --open + $server "${@}" else $lint --watch --preserveWatchOutput & - $server & + $server "${@}" & wait fi } diff --git a/tsconfig.json b/tsconfig.json index 432e895..be10b23 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,21 +1,38 @@ { - "compilerOptions": { - "target": "es2021", - "module": "NodeNext", - "moduleResolution": "NodeNext", - "noEmitOnError": true, - "lib": ["es2021", "dom", "DOM.Iterable"], - "strict": true, - "allowSyntheticDefaultImports": true, - "experimentalDecorators": true, - "importHelpers": true, - "outDir": "out-tsc", - "sourceMap": true, - "inlineSources": true, - "rootDir": "./", - "incremental": true, - "skipLibCheck": true, - "types": ["mocha"] - }, - "include": ["**/*.ts"] + "compilerOptions": { + "verbatimModuleSyntax": true, + "noEmitOnError": true, + "target": "es2021", + "skipLibCheck": true, + "module": "NodeNext", + "moduleResolution": "NodeNext", + "isolatedModules": true, + + "strict": true, + "strictBindCallApply": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noUncheckedSideEffectImports": true, + "allowUnreachableCode": false, + "noUncheckedIndexedAccess": true, + "noPropertyAccessFromIndexSignature": true, + "erasableSyntaxOnly": true, + "noImplicitOverride": true, + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "useDefineForClassFields": false, + "experimentalDecorators": true, + "importHelpers": true, + + "noErrorTruncation": false, + + "outDir": "out-tsc", + "sourceMap": true, + "inlineSources": true, + "rootDir": "./", + "incremental": true, + "types": ["mocha"], + "lib": ["es2021", "dom", "DOM.Iterable"] + }, + "include": ["**/*.ts"] } diff --git a/web-dev-server.config.js b/web-dev-server.config.js index dae4d3d..398e55a 100644 --- a/web-dev-server.config.js +++ b/web-dev-server.config.js @@ -1,21 +1,27 @@ // import { hmrPlugin, presets } from "@open-wc/dev-server-hmr"; -/** Use Hot Module replacement by adding --hmr to the start command */ -const hmr = process.argv.includes("--hmr"); +/** Use Hot Module replacement by adding --watch to the start command */ +//const hmr = process.argv.includes("--watch"); +const [ mode ] = process.argv.slice(2); +const target = mode === "src" // OR "dist" + ? { + rootDir: ".", + appIndex: "./index.html", + } + : { + rootDir: "./dist", + appIndex: "./dist/index.html", + }; export default /** @type {import("@web/dev-server").DevServerConfig} */ ({ - open: "/", - watch: !hmr, - /** Resolve bare module imports */ - nodeResolve: { + open: "/", // SPA routing + nodeResolve: { // Resolve bare module imports exportConditions: ["browser", "development"], }, - /** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */ - // esbuildTarget: "auto" + // esbuildTarget: "auto" // Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */ - /** Set appIndex to enable SPA routing */ - appIndex: "./index.html", + ...target, plugins: [ /** Use Hot Module Replacement by uncommenting. Requires @open-wc/dev-server-hmr plugin */