mirror of
https://github.com/acedanger/pokemon.git
synced 2025-12-05 14:40:14 -08:00
feat: add vite-plugin-node-polyfills to support Node.js globals in Vite
This commit is contained in:
11
README.md
Normal file
11
README.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
# This script is used to deploy the Pokemon Finder application using Docker.
|
||||||
|
# It stops any existing container, builds a new Docker image, and runs the container.
|
||||||
|
# Ensure the script is run from the directory containing the Dockerfile
|
||||||
|
# and the application code.
|
||||||
|
|
||||||
|
# This script also includes a testing stage using Playwright.
|
||||||
|
# It builds the application using Vite, starts a preview server, and runs Playwright tests.
|
||||||
|
# If the tests pass, it proceeds with the Docker deployment.
|
||||||
|
|
||||||
|
# Usage: ./deploy.sh
|
||||||
74
deploy.sh
74
deploy.sh
@@ -2,16 +2,7 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# This script is used to deploy the Pokemon Finder application using Docker.
|
# filepath: /home/acedanger/dev/pokemon/deploy.sh
|
||||||
# It stops any existing container, builds a new Docker image, and runs the container.
|
|
||||||
# Ensure the script is run from the directory containing the Dockerfile
|
|
||||||
# and the application code.
|
|
||||||
|
|
||||||
# This script also includes a testing stage using Playwright.
|
|
||||||
# It builds the application using Vite, starts a preview server, and runs Playwright tests.
|
|
||||||
# If the tests pass, it proceeds with the Docker deployment.
|
|
||||||
|
|
||||||
# Usage: ./deploy.sh
|
|
||||||
|
|
||||||
# Define container and image names
|
# Define container and image names
|
||||||
CONTAINER_NAME="pokemon-app"
|
CONTAINER_NAME="pokemon-app"
|
||||||
@@ -19,6 +10,14 @@ IMAGE_NAME="pokemon-finder"
|
|||||||
HOST_PORT=8080
|
HOST_PORT=8080
|
||||||
CONTAINER_PORT=80
|
CONTAINER_PORT=80
|
||||||
PREVIEW_PORT=4173 # Default Vite preview port
|
PREVIEW_PORT=4173 # Default Vite preview port
|
||||||
|
RUN_TESTS=false # Default: do not run tests
|
||||||
|
|
||||||
|
# --- Argument Parsing ---
|
||||||
|
# Check if the first argument is --test or -t
|
||||||
|
if [[ "$1" == "--test" || "$1" == "-t" ]]; then
|
||||||
|
RUN_TESTS=true
|
||||||
|
echo "Test flag provided. Tests will be run before deployment."
|
||||||
|
fi
|
||||||
|
|
||||||
# --- Pre-checks and Build ---
|
# --- Pre-checks and Build ---
|
||||||
echo "Ensuring dependencies are installed..."
|
echo "Ensuring dependencies are installed..."
|
||||||
@@ -35,34 +34,49 @@ if [ $? -ne 0 ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- Testing Stage ---
|
# --- Testing Stage (Conditional) ---
|
||||||
echo "Starting Vite preview server for testing..."
|
if [ "$RUN_TESTS" = true ]; then
|
||||||
# Start in background and get PID
|
echo "--- Running Testing Stage ---"
|
||||||
npm run preview -- --port $PREVIEW_PORT &
|
echo "Starting Vite preview server for testing..."
|
||||||
PREVIEW_PID=$!
|
# Start in background and get PID
|
||||||
|
npm run preview -- --port $PREVIEW_PORT &
|
||||||
|
PREVIEW_PID=$!
|
||||||
|
|
||||||
# Wait a moment for the server to start (adjust sleep time if needed)
|
# Wait a moment for the server to start (adjust sleep time if needed)
|
||||||
sleep 5
|
echo "Waiting for preview server to start (PID: $PREVIEW_PID)..."
|
||||||
|
sleep 5 # Adjust as necessary
|
||||||
|
|
||||||
echo "Running Playwright tests..."
|
# Check if server is running (optional but good practice)
|
||||||
# Run tests; Playwright will use http://localhost:4173 based on test config/defaults
|
if ! kill -0 $PREVIEW_PID 2>/dev/null; then
|
||||||
npx playwright test
|
echo "Preview server failed to start!"
|
||||||
|
# Attempt to kill if PID exists but process doesn't respond to -0
|
||||||
|
kill $PREVIEW_PID 2>/dev/null || true
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
TEST_RESULT=$?
|
echo "Running Playwright tests..."
|
||||||
|
# Run tests; Playwright will use http://localhost:4173 based on test config/defaults
|
||||||
|
npx playwright test
|
||||||
|
TEST_RESULT=$?
|
||||||
|
|
||||||
echo "Stopping Vite preview server (PID: $PREVIEW_PID)..."
|
echo "Stopping Vite preview server (PID: $PREVIEW_PID)..."
|
||||||
kill $PREVIEW_PID
|
# Send SIGTERM first for graceful shutdown, then SIGKILL if needed
|
||||||
# Wait for the process to terminate
|
kill $PREVIEW_PID || true
|
||||||
wait $PREVIEW_PID 2>/dev/null
|
# Wait for the process to terminate
|
||||||
|
wait $PREVIEW_PID 2>/dev/null
|
||||||
|
|
||||||
if [ $TEST_RESULT -ne 0 ]; then
|
if [ $TEST_RESULT -ne 0 ]; then
|
||||||
echo "Playwright tests failed! Aborting deployment."
|
echo "Playwright tests failed! Aborting deployment."
|
||||||
exit 1
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Playwright tests passed."
|
||||||
|
fi
|
||||||
|
echo "--- Testing Stage Complete ---"
|
||||||
else
|
else
|
||||||
echo "Playwright tests passed."
|
echo "Skipping testing stage (run with --test or -t to include)."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- Deployment Stage (Only if tests passed) ---
|
# --- Deployment Stage ---
|
||||||
echo "Proceeding with Docker deployment..."
|
echo "Proceeding with Docker deployment..."
|
||||||
|
|
||||||
# Stop the existing container (ignore errors if it doesn't exist)
|
# Stop the existing container (ignore errors if it doesn't exist)
|
||||||
|
|||||||
1556
package-lock.json
generated
1556
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -25,6 +25,7 @@
|
|||||||
"autoprefixer": "^10.4.21",
|
"autoprefixer": "^10.4.21",
|
||||||
"postcss": "^8.5.3",
|
"postcss": "^8.5.3",
|
||||||
"tailwindcss": "^3.4.17",
|
"tailwindcss": "^3.4.17",
|
||||||
"vite": "^6.3.2"
|
"vite": "^6.3.2",
|
||||||
|
"vite-plugin-node-polyfills": "^0.23.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,26 @@
|
|||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
|
// Import the new plugin
|
||||||
|
import { nodePolyfills } from "vite-plugin-node-polyfills";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
// Keep build target reasonable, 'modules' is often a good balance
|
||||||
build: {
|
build: {
|
||||||
target: "es2020", // Or try 'es2020' or 'modules' if 'esnext' doesn't work
|
target: "modules",
|
||||||
|
// Rollup options are not needed for this plugin
|
||||||
},
|
},
|
||||||
|
plugins: [
|
||||||
|
// Add the plugin to Vite's plugins array
|
||||||
|
nodePolyfills({
|
||||||
|
// Options (optional):
|
||||||
|
// - 'true'/'false' to include/exclude specific polyfills.
|
||||||
|
// - 'build' to only include polyfills for the build.
|
||||||
|
// - 'dev' to only include polyfills for the dev server.
|
||||||
|
// By default, it polyfills globals like `Buffer` and `process`.
|
||||||
|
// You might need to explicitly enable others if errors persist.
|
||||||
|
// Example: globals: { Buffer: true, global: true, process: true },
|
||||||
|
// Example: protocolImports: true, // If you need imports like 'node:fs'
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
// optimizeDeps and resolve.alias sections related to polyfills
|
||||||
|
// are likely no longer needed with this plugin.
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user