문제 설명
Intellij IDEA 13 ‑ 최신 JS 파일을 사용한 아티팩트 빌드 프로세스(grunt 빌드를 통해) (Intellij IDEA 13 ‑ Artifact build process with latest JS files (Via grunt build))
Is it possible in Intellij (13) to execute grunt build
(shell command) as part of the artifact build process so that the artifact to be deploy contains the up to date JS/CSS/HTML files? I see 'Run Ant target'
that looks like it would execute a shell command but i'm not using ant (nor do I want to)?
참조 솔루션
방법 1:
I believe that IntelliJ is using Ant as an adapter to all other tools, because you can run pretty much anything with it.
Just add the following build.xml to your project.
<project name="grunt" default="build">
<target name="build">
<exec executable="grunt">
<arg value="build"/>
</exec>
</target>
</project>
방법 2:
I stumbled upon this question when I was interested in exactly the same. I am using IntelliJ Idea for more than a decade. Now, when I started to work with Angular, NodeJS/NPM and build by Grunt, I really wanted to be able to continue building and launching my development artifacts from the IDE seamlessly, without any manual steps to execute Grunt/browserify even if it is "just" another click on a button before you build. So...
One solution to trigger a Grunt task execution in IntelliJ Idea as a part of the artifact build process, would be to add exec‑maven‑plugin
and bind it to an execution phase e.g. prepare‑package
, most likely in some separate profile. Something like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec‑maven‑plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>grunt</id>
<phase>prepare‑package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>grunt${script.extension}</executable>
<workingDirectory>angular‑app</workingDirectory>
<arguments>
<argument>‑‑no‑color</argument>
<argument>${grunt.task}</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
Now in the "Maven Projects" tool window you can right‑click the appropriate lifecycle phase in the list and mark as "Execute before rebuild".
This should do the job and satisfy your requirement not to use Ant.
But in my case (though I don't use Ant as a build system for a long time now, nor I like Ant too much), I decided to take the approach proposed by @kukido in his answer. This way I didn't modify Maven to suit IDE which I consider to be conceptually incorrect as the build system (Maven in my case) should not be influenced by anything imposed by IDE. I really think that such a great tool as IntelliJ Idea can take one step further and provide possibility to run more arbitrary commands/goals on "Pre‑precess" of preparing an artifact in IDE. For now I will use the Ant as a thin adapter here and keep my POM clean.
(by Mannie、kukido、ynovytskyy)