Skip to content

Commit

Permalink
support both JavaScript and TypeScript config files in setup script
Browse files Browse the repository at this point in the history
  • Loading branch information
fouteox committed Feb 27, 2025
1 parent 38f8b34 commit aeb150e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions vite/setup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
#ddev-generated
CONFIG_FILE="${DDEV_APPROOT}/vite.config.js"

JS_CONFIG="${DDEV_APPROOT}/vite.config.js"
TS_CONFIG="${DDEV_APPROOT}/vite.config.ts"

sed_inplace() {
if [[ "$(uname)" == "Darwin" ]]; then
Expand All @@ -10,6 +12,14 @@ sed_inplace() {
fi
}

if [ -f "$JS_CONFIG" ]; then
CONFIG_FILE="$JS_CONFIG"
elif [ -f "$TS_CONFIG" ]; then
CONFIG_FILE="$TS_CONFIG"
else
exit 0
fi

if [ -f "$CONFIG_FILE" ]; then
sed_inplace "/export default defineConfig/ i\\
const port = 5173;\\
Expand All @@ -24,7 +34,7 @@ const origin = \`\${process.env.DDEV_PRIMARY_URL}:\${port}\`;\\
strictPort: true,\\
origin: origin,\\
cors: {\\
origin: { origin: process.env.DDEV_PRIMARY_URL },\\
origin: process.env.DDEV_PRIMARY_URL,\\
},\\
},/g" "$CONFIG_FILE"
fi
fi

0 comments on commit aeb150e

Please sign in to comment.