简体   繁体   English

在哪里使用标志通知GWT避免混淆Javascript?

[英]Where to use the flag to inform GWT to avoid obfuscating Javascript?

I need to compile a GWT application without obfuscating Javascript, but I never worked with GWT before. 我需要在不混淆Javascript的情况下编译GWT应用程序,但是我以前从未使用过GWT。

After a bit of research, I found out about the -style flag ( http://www.gwtproject.org/doc/latest/DevGuideCompilingAndDebugging.html#DevGuideCompilerOptions ) to inform GWT to avoid obfuscating Javascript. 经过一些研究,我发现了有关-style标志( http://www.gwtproject.org/doc/latest/DevGuideCompilingAndDebugging.html#DevGuideCompilerOptions )的信息,以通知GWT避免混淆Javascript。

We also have a pom.xml file in our project. 我们的项目中也有一个pom.xml文件。 Let us assume it looks like that: 让我们假设它看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>
  <artifactId>test</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt</artifactId>
        <version>2.7.0</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-user</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-dev</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-codeserver</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-servlet</artifactId>
      <scope>runtime</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <version>2.7.0</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <module>com.example.test.Test</module>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Is this the place where I am supposed to put the -style flag? 这是我应该放置-style标志的地方吗? If so, where exactly in the XML tree should I put it? 如果是这样,我应该将它放在XML树的确切位置?

You should put the flag in the gwt compile plugin configuration 您应该将标志放在gwt编译插件配置中

 <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <version>2.7.0</version>
        <executions>
          <execution>
              <configuration>
                  <style>${gwtcompiler.style}</style>
              </configuration>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <module>com.example.test.Test</module>
        </configuration>
      </plugin>
    </plugins>
  </build>

And you define the variable earlier in your pom, just uncomment the line you want to use. 然后在pom中更早地定义变量,只需取消注释要使用的行即可。

<properties>
    <gwtcompiler.style>PRETTY</gwtcompiler.style>
    <!-- <gwtcompiler.style>OBFUSCATED</gwtcompiler.style> -->
</properties>

or use profiles to set it from the command line. 或使用配置文件从命令行进行设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM