> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/web/get-started/faq/transpiling-javascript.md).

# Transpiling Javascript

World's #1 PDF SDK Library for Web, Mobile, Server, Desktop

When using modern [ES6+](http://es6-features.org/#Constants) syntax and features (which some of our code snippets do), it is important to transpile your code and include polyfills to ensure your code works in older browsers, such as IE11.

The recommended way to do this is to set up a build system that converts your ES6+ code to ES5, using a library such as Babel or Parcel.

## Babel

First we need to install Babel as a dev dependency into our project.

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
npm i --save-dev @babel/core @babel/cli @babel/preset-env
```

{% endcode %}
{% endtab %}
{% endtabs %}

The next step is configuring Babel to use the `env` preset, which will ensure your code is browser compatible. To do this, we create a `.babelrc` file at the root of our project, and then add the following code:

{% tabs %}
{% tab title="JSON" %}
{% code lineNumbers="true" %}

```json
{
  "presets": ["@babel/preset-env"]
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

Now we can create a `build` command that will transpile our code. In your `package.json` file (create one if it doesn't exist), add the following script:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
...,
"scripts": {
  "build": "npx babel src -d build"
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

This script will take any code in `src`, and output the transpiled code into the `build` folder.

Now when you're ready to transpile your code, simply run `npm run build`, and you'll get production ready code placed into the `build` folder!

There are other ways to use Babel as well. Here are some resources to get you started with more complex build systems:

* [Babel CLI Reference](https://babeljs.io/docs/en/babel-cli/)
* [Babel + Webpack tutorial](http://ccoenraets.github.io/es6-tutorial-data/babel-webpack/)

## Parcel

[Parcel](https://parceljs.org) is a module bundler, similar to [Webpack](https://webpack.js.org/), except it comes completly preconfigured out of the box. It is extremely easy to use, and you can be up and running in a few seconds with no configuration.

The first step is installing Parcel as a dependency:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
npm install -g parcel-bundler
```

{% endcode %}
{% endtab %}
{% endtabs %}

And then all you have to do is create a build script! In your `package.json` file (create one if you don't have one already), add the following script:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
...,
"scripts": {
  "build": "parcel build src/index.js"
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

In this case `src/index.js` is our entry point (feel free to change this to suit your needs).

Now when you're ready to transpile your code, simply run `npm run build`, and you'll get production ready code placed into the `build` folder!

Parcel also has many other easy to use features, such as a built in dev server and code splitting. [Here is the documentation](https://parceljs.org/getting_started.html) to get you started.

## Other resources

* [Promise polyfill](https://www.npmjs.com/package/promise-polyfill/)
* [Webpack](https://webpack.js.org/)
* [React boilerplate](https://github.com/facebook/create-react-app/)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/web/get-started/faq/transpiling-javascript.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
