为生产构建时的 vaadin 23 报告调试模式

vaadin 23 reporting debug mode when built for production

我通过以下方式在生产模式下构建了我的 vaadin 23 应用程序:

mvn clean package -Pproduction -DskipTests -U

我的 pom.xml 包含必要的配置文件:

<!-- vaadin profiles -->
    <!-- https://vaadin.com/docs/latest/flow/production/production-build -->
    <profiles>
        <profile>
            <id>production</id>
            <properties>
                <vaadin.productionMode>true</vaadin.productionMode>
            </properties>

            <!-- configuration depending on environment -->
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.vaadin</groupId>
                        <artifactId>vaadin-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>build-frontend</goal>
                                </goals>
                                <phase>compile</phase>
                            </execution>
                        </executions>

                        <configuration>
                            <productionMode>true</productionMode>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            <!-- .. more configuration .. -->
            <dependencies>
                <dependency>
                    <groupId>com.vaadin</groupId>
                    <artifactId>vaadin</artifactId>
                    <exclusions>
                        <exclusion>
                            <groupId>com.vaadin</groupId>
                            <artifactId>vaadin-dev-server</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
            </dependencies>

        </profile>
    </profiles>

我正在使用 java 17.

为 tomcat 9 构建一个 war 文件

war包含WEB-INF/classes/META-INF/VAADIN/config/flow-build-info。json

{
  "productionMode": true,
  "useDeprecatedV14Bootstrapping": false,
  "eagerServerLoad": false,
  "chunks": {
    "fallback": {
      "jsModules": [
        "@vaadin/select/src/vaadin-select.js",
        "./selectConnector.js",
        "@polymer/paper-ripple/paper-ripple.js",
        "./custom-media-query.js",
        "./com/github/appreciated/card/clickable-card.js",
        "./com/github/appreciated/card/stateful-card.js",
        "./grid-layout/grid-layout.js",
        "./font-awesome-iron-iconset/far.js",
        "./font-awesome-iron-iconset/fab.js",
        "./element-media-query.js",
        "@vaadin/charts/src/vaadin-chart.js",
        "@vaadin/grid-pro/src/vaadin-grid-pro.js",
        "@vaadin/grid-pro/src/vaadin-grid-pro-edit-column.js",
        "./gridProConnector.js",
        "@vaadin/board/vaadin-board-row.js",
        "@vaadin/avatar-group/src/vaadin-avatar-group.js",
        "@vaadin/crud/src/vaadin-crud.js",
        "@vaadin/crud/src/vaadin-crud-edit-column.js",
        "@vaadin/message-input/src/vaadin-message-input.js",
        "@vaadin/login/src/vaadin-login-form.js",
        "./messageListConnector.js",
        "@vaadin/message-list/src/vaadin-message-list.js",
        "@vaadin/virtual-list/vaadin-virtual-list.js",
        "./virtualListConnector.js",
        "@polymer/iron-list/iron-list.js",
        "./ironListConnector.js",
        "./ironListStyles.js",
        "@vaadin/upload/src/vaadin-upload-file.js",
        "@vaadin/login/src/vaadin-login-overlay.js",
        "@vaadin/board/vaadin-board.js",
        "./vaadin-big-decimal-field.js",
        "@vaadin/app-layout/src/vaadin-drawer-toggle.js",
        "@vaadin/confirm-dialog/src/vaadin-confirm-dialog.js",
        "@vaadin/app-layout/src/vaadin-app-layout.js"
      ],
      "cssImports": [
        {
          "value": "./styles/grid-layout.css"
        }
      ]
    }
  },
  "enableDevServer": false
}

WEB-INF/classes/META-INF/VAADIN/config/stats.json 包含:

{
 "assetsByChunkName": {
  "bundle": "VAADIN/build/vaadin-bundle-7f98e7fa04576858b6f8.cache.js"
 }
}

我能看到的唯一问题是它包含了我没有使用的模块,但我认为这对当前问题没有任何影响。

当我部署 war 时,tomcat 报告:

(AtmosphereFramework.java:1087) - Atmosphere Framework 2.7.3.slf4jvaadin4 started.
(AtmosphereFramework.java:2626) - Installed AtmosphereInterceptor  Track Message Size Interceptor using | with priority BEFORE_DEFAULT 
(DefaultDeploymentConfiguration.java:155) - Following issues were discovered with deployment configuration:
WARNING: Vaadin is running in DEBUG MODE with debug features enabled, but with a prebuild frontend bundle (production ready).
When deploying application for production, disable debug features by enabling production mode!
See more from https://vaadin.com/docs/latest/flow/production/overview
[main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/usr/local/tomcat/webapps/ROOT.war] has finished in [14,764] ms
org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
[main] org.apache.catalina.startup.Catalina.start Server startup in [14985] milliseconds

否则系统按预期工作。

我已按照此故障排除指南进行操作,一切似乎都是正确的: https://vaadin.com/docs/latest/flow/production/troubleshooting

感谢@Frettman 的好主意,我最终解决了这个问题。

核心问题实际上是我们通过注释配置的 vaadin servlet。


@WebServlet(urlPatterns =
{ "/*" }, name = "OnePub", asyncSupported = true, loadOnStartup = 1, initParams =
{
        @WebInitParam(name = "org.atmosphere.cpr.AtmosphereInterceptor", value = "dev.onepub.servlets.AtmosphereFilter"),
        @WebInitParam(name = "closeIdleSessions", value = "true"),

        /// changed this when we release.
        @WebInitParam(name = "productionMode", value = "false")

})

问题行是

@WebInitParam(name = "productionMode", value = "false")

将值更改为 'true' 解决了问题。

@WebInitParam(name = "productionMode", value = "true")

我还进行了另一项更改,可能有助于修复。

我的 pom 文件生产配置文件部分包含一个依赖项:

<dependency>
                    <groupId>com.vaadin</groupId>
                    <artifactId>vaadin</artifactId>
                    <exclusions>
                        <exclusion>
                            <groupId>com.vaadin</groupId>
                            <artifactId>vaadin-dev-server</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>

我不确定这是如何进入 pom 但我将配置文件部分更改为:

<profiles>
        <profile>
            <!-- Production mode is activated using -Pproduction -->
            <id>production</id>
            <properties>
                <vaadin.productionMode>true</vaadin.productionMode>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>com.vaadin</groupId>
                    <artifactId>flow-server-production-mode</artifactId>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.vaadin</groupId>
                        <artifactId>vaadin-maven-plugin</artifactId>
                        <version>${vaadin.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>build-frontend</goal>
                                </goals>
                                <phase>compile</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>