【问题标题】:Integrate node.js project in lein build在 lein build 中集成 node.js 项目
【发布时间】:2018-02-05 12:12:27
【问题描述】:

我有一个单独的 javascript 前端项目,它带有自己的 package.json。我想以不需要额外设置(例如安装节点和 npm)的方式将此项目集成到我的 leiningen 构建中。通常 Maven 或 gradle 等构建工具会提供插件,下载某个 node 版本 + npm,安装所有依赖项,然后运行脚本构建 javascript 项目。 leiningen有这样的插件吗?

【问题讨论】:

    标签: node.js leiningen


    【解决方案1】:

    由于没人愿意回答,我最终使用 mvn 将 node.js 和 leiningen 项目粘合在一起。我的 leiningen 项目使用 immutant war 构建,我的 node.js 项目使用 npm run build 构建。它使用maven-frontend-plugin 安装节点和npm 并执行节点构建。它使用exec-maven-plugin 在单独的VM 中执行leiningen。这里是pom.xml,不包括项目信息。

    <repositories>
      <repository>
         <id>clojars</id>
         <name>Clojars</name>
         <url>http://clojars.org/repo</url>
       </repository>
     </repositories>
    
     <dependencies>
      <!-- Taken from http://www.elangocheran.com/blog/2015/12/compiling-a-leiningen-project-from-maven/ -->
      <dependency>
       <groupId>org.clojure</groupId>
       <artifactId>clojure</artifactId>
       <version>1.8.0</version>
      </dependency>
      <dependency>
       <groupId>leiningen</groupId>
       <artifactId>leiningen</artifactId>
       <version>2.8.1</version>
      </dependency>
     </dependencies>
    
     <pluginRepositories>
      <pluginRepository>
       <id>clojars</id>
       <name>Clojars</name>
       <url>http://clojars.org/repo</url>
      </pluginRepository>
     </pluginRepositories>
    
     <build>
      <plugins>
    
       <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <version>1.6</version>
        <executions>
         <execution>
          <id>install node and npm</id>
          <goals>
           <goal>install-node-and-npm</goal>
          </goals>
          <phase>generate-resources</phase>
          <configuration>
           <nodeVersion>v8.2.1</nodeVersion>
           <npmVersion>5.3.0</npmVersion>
          </configuration>
         </execution>
         <execution>
          <id>npm install</id>
          <goals>
           <goal>npm</goal>
          </goals>
          <phase>generate-resources</phase>
          <configuration>
           <arguments>install</arguments>
          </configuration>
         </execution>
         <execution>
          <id>npm build</id>
          <goals>
           <goal>npm</goal>
          </goals>
          <phase>generate-resources</phase>
          <configuration>
           <arguments>run build</arguments>
          </configuration>
         </execution>
        </executions>
       </plugin>
    
       <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.4.0</version>
        <executions>
         <execution>
          <id>lein war</id>
          <phase>package</phase>
          <goals>
           <goal>exec</goal>
          </goals>
          <configuration>
           <executable>java</executable>
           <arguments>
            <argument>-classpath</argument>
            <classpath />
            <argument>clojure.main</argument>
            <argument>-m</argument>
            <argument>leiningen.core.main</argument>
            <argument>immutant</argument>
            <argument>war</argument>
           </arguments>
          </configuration>
         </execution>
        </executions>
       </plugin>
    
    
      </plugins>
     </build>
    

    【讨论】:

      猜你喜欢
      • 2022-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多