diff --git a/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/build-app.sh b/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/build-app.sh index 9b72511e..55fa7749 100755 --- a/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/build-app.sh +++ b/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/build-app.sh @@ -46,8 +46,22 @@ determine_webpack_version() { esac } -CERC_WEBPACK_VERSION=$(determine_webpack_version "$CERC_NEXT_VERSION") -echo "Using webpack version: $CERC_WEBPACK_VERSION" +# Check if webpack is already in package.json +if CERC_WEBPACK_VERSION=$(jq -r '.dependencies.webpack // .devDependencies.webpack // empty' package.json); then + if [ -n "$CERC_WEBPACK_VERSION" ]; then + echo "Using existing webpack version: $CERC_WEBPACK_VERSION" + else + CERC_WEBPACK_VERSION=$(determine_webpack_version "$CERC_NEXT_VERSION") + echo "Determined webpack version based on Next.js: $CERC_WEBPACK_VERSION" + # Add webpack to devDependencies + jq ".devDependencies.webpack = \"$CERC_WEBPACK_VERSION\"" package.json > package.json.tmp && mv package.json.tmp package.json + fi +else + CERC_WEBPACK_VERSION=$(determine_webpack_version "$CERC_NEXT_VERSION") + echo "Determined webpack version based on Next.js: $CERC_WEBPACK_VERSION" + # Add webpack to devDependencies + jq ".devDependencies.webpack = \"$CERC_WEBPACK_VERSION\"" package.json > package.json.tmp && mv package.json.tmp package.json +fi # Determine the Next.js config file if [ -f "next.config.mjs" ]; then @@ -151,23 +165,6 @@ mv "${NEXT_CONFIG_JS}.pretty" "$NEXT_CONFIG_JS" # Update package.json [ ! -f "package.dist" ] && cp package.json package.dist -# Check if webpack is already in package.json -if WEBPACK_VERSION=$(jq -r '.dependencies.webpack // .devDependencies.webpack // empty' package.json); then - if [ -n "$WEBPACK_VERSION" ]; then - echo "Using existing webpack version: $WEBPACK_VERSION" - else - WEBPACK_VERSION=$(determine_webpack_version "$CERC_NEXT_VERSION") - echo "Determined webpack version based on Next.js: $WEBPACK_VERSION" - # Add webpack to devDependencies - jq ".devDependencies.webpack = \"$WEBPACK_VERSION\"" package.json > package.json.tmp && mv package.json.tmp package.json - fi -else - WEBPACK_VERSION=$(determine_webpack_version "$CERC_NEXT_VERSION") - echo "Determined webpack version based on Next.js: $WEBPACK_VERSION" - # Add webpack to devDependencies - jq ".devDependencies.webpack = \"$WEBPACK_VERSION\"" package.json > package.json.tmp && mv package.json.tmp package.json -fi - # Install dependencies $CERC_BUILD_TOOL install || exit 1