webpack based on app next version

This commit is contained in:
VPhung24 2024-10-15 19:53:41 +00:00
parent 333a3eea02
commit fcf2584a3a

View File

@ -46,8 +46,22 @@ determine_webpack_version() {
esac
}
# 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 "Using webpack version: $CERC_WEBPACK_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