docs.sheetjs.com/docz/docs/02-getting-started/01-installation/06-amd.md

94 lines
2.2 KiB
Markdown
Raw Normal View History

2022-06-11 17:21:26 +00:00
---
sidebar_position: 6
sidebar_custom_props:
2022-06-22 19:25:24 +00:00
summary: NetSuite, SAP UI5, RequireJS
2022-06-11 17:21:26 +00:00
---
import current from '/version.js';
2022-06-27 02:05:36 +00:00
# AMD (define)
2022-06-11 17:21:26 +00:00
Each standalone release script is available at <https://cdn.sheetjs.com/>.
`xlsx.full.min.js` supports AMD with name `xlsx` out of the box.
<div><a href={`https://cdn.sheetjs.com/xlsx-${current}/package/dist/xlsx.full.min.js`}>https://cdn.sheetjs.com/xlsx-{current}/package/dist/xlsx.full.min.js</a> is the URL for {current}</div><br/>
2022-06-22 19:25:24 +00:00
:::note
When referencing by file name, AMD loaders typically omit the file extension.
The actual file name is `xlsx.full.min.js`, but the examples will refer to the
script as `xlsx.full.min`.
:::
2022-06-11 17:21:26 +00:00
## NetSuite
After downloading the script, it can be referenced directly in `define` calls
in SuiteScripts:
```js
define(['N/file', './xlsx.full.min'], function(file, XLSX) {
// ... use XLSX here
})
```
2022-08-13 22:01:26 +00:00
As explained in the [NetSuite demo](../../demos/netsuite), module
2022-06-11 17:21:26 +00:00
aliases are created in config files referenced via `@NAmdConfig` comments.
2022-06-22 19:25:24 +00:00
## SAP UI5
After downloading the script, it can be uploaded to the UI5 project and loaded
in the `sap.ui.define` call:
```js
sap.ui.define([
/* ... other libraries ... */
"path/to/xlsx.full.min"
], function(/* ... variables for the other libraries ... */, XLSX) {
// use XLSX here
})
```
:::warning
The [SAP Website has a note about including third-party JS libraries.](https://blogs.sap.com/2017/04/30/how-to-include-third-party-libraries-modules-in-sapui5/SAPUI5)
It recommends copying and pasting JavaScript code.
**Copy and pasting code does not work** for SheetJS scripts as they contain
Unicode characters that may be mangled. The standalone script should be
downloaded and manually uploaded to the project.
:::
2022-06-11 17:21:26 +00:00
## RequireJS
After downloading the script, it can be referenced directly in `require` calls:
```js
require(['./xlsx.full.min'], function(XLSX) {
// ... use XLSX here
});
```
2022-06-27 02:05:36 +00:00
#### Aliases
2022-06-11 17:21:26 +00:00
The `requirejs.config` function can define aliases through the `paths` key:
```js
requirejs.config({
paths: {
xlsx: [ './xlsx.full.min' ]
}
});
```
2022-06-27 02:05:36 +00:00
Once that is set, app code can freely require `xlsx`:
```js
require(['xlsx'], function(XLSX) {
// ... use XLSX here
});
```