Babel Maven Plugin

Transpile JavaScript files in Babel in pure Java.

License

License

Categories

Categories

Maven Build Tools
GroupId

GroupId

com.jarslab.maven
ArtifactId

ArtifactId

babel-maven-plugin
Last Version

Last Version

1.6
Release Date

Release Date

Type

Type

maven-plugin
Description

Description

Babel Maven Plugin
Transpile JavaScript files in Babel in pure Java.
Project URL

Project URL

https://github.com/jarslab/babel-maven-plugin
Source Code Management

Source Code Management

https://github.com/jarslab/babel-maven-plugin

Download babel-maven-plugin

How to add to project

<plugin>
    <groupId>com.jarslab.maven</groupId>
    <artifactId>babel-maven-plugin</artifactId>
    <version>1.6</version>
</plugin>

Dependencies

compile (1)

Group / Artifact Type Version
org.graalvm.js : js jar 19.3.1

provided (3)

Group / Artifact Type Version
org.apache.maven : maven-plugin-api jar 3.6.0
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.6.0
org.immutables : value jar 2.8.2

test (3)

Group / Artifact Type Version
junit : junit jar 4.12
org.assertj : assertj-core jar 3.10.0
org.mockito : mockito-core jar 2.21.0

Project Modules

There are no modules declared in this project.

Travis CI Maven Central

Babel Maven Plugin

Plugin lets you to execute Babel transcription for given JavaScript files. It requires no npm or node.js, it is plain Java project (based on embedded GraalVM from version 1.4) which works perfectly combined with WebJars.

Maven coords

<dependency>
  <groupId>com.jarslab.maven</groupId>
  <artifactId>babel-maven-plugin</artifactId>
  <version>1.6</version>
</dependency>

Settings, ie buttons and knobs

  • verbose - no surprises, the execution becomes a bit more talkative (default: false),
  • threads - number of threads to use when transpiling (default: 1, will be capped on the amount of processors available)
  • encoding - will apply chosen encoding during files operations (read/write) (default: Charset.defaultCharset()),
  • babelSrc - readable path to standalone(!) Babel sources. It can be provided from WebJars dependency, minified or development version,
  • sourceDir - base path for JavaScript files you are going to translate,
  • targetDir - result path, note that all sub-directories from sourceDir will be preserved,
  • jsFiles - list of JavaScript files (static) from sourceDir to translate,
  • jsIncludes - list of JavaScript files (with simple masks */?),
  • jsExcludes - list of exceptions for jsIncludes,
  • prefix - optional prefix applied for every translated file,
  • formatPresets - enable/disable presets formatting (default: true). Once disabled presets are required to be well formatted,
  • presets - presets for Babel execution (default: es2015),
  • plugins - plugins for Babel execution (default: "" (empty)) NOTE: any custom plugins are required to be available in provided babelSrc

Example

<plugin>
    <groupId>com.jarslab.maven</groupId>
    <artifactId>babel-maven-plugin</artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <id>js-transpile</id>
            <phase>process-resources</phase>
            <goals>
                <goal>babel</goal>
            </goals>
            <configuration>
                <verbose>true</verbose>
                <threads>4</threads>
                <babelSrc>${project.basedir}/target/classes/assets/jslib/babel.min.js</babelSrc>
                <sourceDir>${project.basedir}/target/classes/assets/</sourceDir>
                <targetDir>${project.basedir}/target/classes/assets/</targetDir>
                <jsSourceIncludes>
                    <jsSourceInclude>src/*.js</jsSourceInclude>
                </jsSourceIncludes>
                <prefix>trans-</prefix>
                <presets>react,es2015</presets>
            </configuration>
        </execution>
    </executions>
</plugin>

Changelog

  • 1.6: Fix Presets handling
  • 1.5: Add plugins option for Babel execution
  • 1.4: Switch from deprecated Nashorn engine to GraalVM

Versions

Version
1.6
1.5
1.4
1.3
1.2
1.1
1.0