#################
# Build the app #
#################
FROM node:22-alpine AS build
WORKDIR /app
RUN npm install -g @angular/cli
COPY package.json package-lock.json ./
RUN npm install --fetch-timeout=600000
COPY . .
RUN ng build --configuration production --output-path=/dist
################
# Run in NGINX #
################
FROM nginx:alpine
COPY --from=build /dist/browser /usr/share/nginx/html
COPY --from=build /app/nginx.conf /etc/nginx/nginx.conf
# When the container starts, replace the env.js with values from environment variables
CMD ["/bin/sh", "-c", "envsubst < /usr/share/nginx/html/assets/environment/env.template.js > /usr/share/nginx/html/assets/environment/env.js && exec nginx -g 'daemon off;'"]
虽然应用程序在我的本地机器上运行良好,但 ng serve , L.markerClusterGroup 在部署到生产服务器后却无法运行。(我忘了具体错误是什么样子的。)无论如何,我找到了以下解决方法:
import * as leaflet from 'leaflet';
import 'leaflet';
import 'leaflet.markercluster';
// workaround for angular 18, otherwise leaflet.markercluster doesn't work
declare let L: typeof leaflet;