---
title: Bundling Sheets with RequireJS
sidebar_label: RequireJS
pagination_prev: demos/index
pagination_next: demos/grid/index
sidebar_position: 11
---
import current from '/version.js';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import CodeBlock from '@theme/CodeBlock';
[RequireJS](https://requirejs.org/) is a JavaScript file and module loader. It
includes an in-browser loader as well as a static optimizer.
[SheetJS](https://sheetjs.com) is a JavaScript library for reading and writing
data from spreadsheets.
This demo uses RequireJS and SheetJS to export data. We'll explore how to load
SheetJS in a site using RequireJS and how to use the `r.js` optimizer to create
a bundled site.
The [Live demo](pathname:///requirejs/requirejs.html) loads RequireJS from the
CDN, uses it to load the standalone script from the SheetJS CDN, and uses the
`XLSX` variable to create a button click handler that creates a workbook.
:::note
This demo was last tested on 2023 October 18 against RequireJS `2.3.6`
:::
## Integration Details
The [SheetJS Standalone scripts](/docs/getting-started/installation/standalone)
comply with AMD `define` semantics. They support RequireJS and the `r.js`
optimizer out of the box.
### Config
The RequireJS config should set the `xlsx` alias in the `paths` property.
#### SheetJS CDN
The SheetJS CDN URL can be directly referenced in a path alias:
{`\
require.config({
baseUrl: ".",
name: "app",
paths: {
// highlight-next-line
xlsx: "https://cdn.sheetjs.com/xlsx-${current}/package/dist/xlsx.full.min"
}
});`}
#### Vendoring
After downloading the SheetJS standalone script, a relative path can be used in
the path alias. For example, if the standalone script was downloaded in the same
directory as the HTML page, the path should be `./xlsx.full.min`:
```js
require.config({
baseUrl: ".",
name: "app",
paths: {
// highlight-next-line
xlsx: "./xlsx.full.min"
}
});
```
### Usage
Once the alias is set, `"xlsx"` can be required from app scripts:
```js
// highlight-next-line
require(["xlsx"], function(XLSX) {
/* use XLSX here */
console.log(XLSX.version);
});
```
Within the callback, the `XLSX` variable exposes the functions listed in the
["API Reference"](/docs/api/) section of the documentation.
## Complete Example
This demo will explore the standalone RequireJS script and the `r.js` optimizer.
### Standalone RequireJS
0) Download the SheetJS Standalone script and move to the project directory: