【问题标题】:Where is the require.js file generated from?require.js 文件是从哪里生成的?
【发布时间】:2019-04-03 22:22:33
【问题描述】:

我正在从这个例子中学习 Angular 2 https://github.com/pkaul/maven-typescript-example

所以在我运行第三步 (mvn jetty:run) 之后,一个可运行的 war 文件夹将被打包到 example-webapp/target 文件夹中。但是,有一个文件我不确定。 在文件夹 example-webapp/target/example-webapp-0.1.0-SNAPSHOT/modules 下,require.js 文件,旧时间戳为 2013-05-14 .

我想知道它的来源和用途。 我猜该文件与 example-webapp 内的 pom.xml 中定义的 requirejs-maven-plugin 插件有关。地位得到确认或更正。

<plugin>
    <groupId>com.github.mcheely</groupId>
    <artifactId>requirejs-maven-plugin</artifactId>
    <version>1.0.4</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>optimize</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <skip>true</skip><!-- NOT ENABLED AS A DEFAULT -->
        <configFile>${basedir}/src/build/js/optimize.js</configFile>
        <filterConfig>true</filterConfig>
    </configuration>
</plugin>

【问题讨论】:

    标签: javascript angular maven gruntjs


    【解决方案1】:

    文件require.js 正在从Maven dependency 中提取:

    <dependency>
      <groupId>org.jszip.redist</groupId>
      <artifactId>require</artifactId>
      <version>2.1.6</version>
      <type>jszip</type>
    </dependency>
    

    该项目使用 jszip-maven-plugin 来处理 JavaScript 库,就像它们是标准 Maven 依赖项(如 Spring 或其他)一样:

    当您想要创建 JSZip 模块或在 war 项目中使用这些 JSZip 模块时,可以使用 JSZip 的 Maven 插件。

    该插件的最大优势在于,无需手动复制和下载 require.js 文件并将其放在 webapp 的正确位置,这使得构建完全自动化且易于更新(您只需要更新依赖项)。它与传统 Java 库的 Maven 依赖概念密切相关。

    插件将从Maven Central 下载这些JavaScript 库为jszip, unpack them and put them where configured:

    <plugin>
        <groupId>org.jszip.maven</groupId>
        <artifactId>jszip-maven-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
            <mappings>
                <!-- copy all JSZIP dependencies to directory "modules" -->
                <mapping>
                    <select>*:*</select>
                    <path>modules</path>
                </mapping>
            </mappings>
        </configuration>
        <!-- -->
    </plugin>
    

    在这种情况下,它们会被复制到modules 目录,这就是您所看到的输出。 &lt;select&gt;*:*&lt;/select&gt; 表示考虑所有jszip 依赖关系,&lt;path&gt;modules&lt;/path&gt; 指定输出目录。

    所以实际上,它与 requirejs-maven-plugin 无关,它用于优化和压缩 JavaScript 文件。

    【讨论】:

      猜你喜欢
      • 2011-10-22
      • 2015-03-18
      • 1970-01-01
      • 1970-01-01
      • 2012-01-31
      • 2015-01-17
      • 2012-12-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多