2017-06-08 06:19:11 +00:00
|
|
|
# Rollup
|
|
|
|
|
2022-03-07 07:36:36 +00:00
|
|
|
This library has a proper ESM build that is enabled by default:
|
|
|
|
|
|
|
|
```js
|
|
|
|
import { read, utils } from 'xlsx';
|
|
|
|
```
|
|
|
|
|
|
|
|
This sample demonstrates a bundle for browser as well as for node.
|
2017-09-24 23:40:09 +00:00
|
|
|
|
|
|
|
This demo uses the `import` form to expose the whole library, enabling client
|
|
|
|
code to access the library with `import XLSX from 'xlsx'`. The JS code from
|
|
|
|
the root demo was moved to a separate `app.js` script.
|
2017-06-08 06:19:11 +00:00
|
|
|
|
|
|
|
## Required Plugins
|
|
|
|
|
2022-03-07 07:36:36 +00:00
|
|
|
The `rollup-plugin-node-resolve` plugin is used:
|
2017-06-08 06:19:11 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
import resolve from 'rollup-plugin-node-resolve';
|
|
|
|
export default {
|
|
|
|
/* ... */
|
|
|
|
plugins: [
|
|
|
|
resolve({
|
|
|
|
module: false, // <-- this library is not an ES6 module
|
|
|
|
browser: true, // <-- suppress node-specific features
|
2022-03-07 07:36:36 +00:00
|
|
|
})
|
2017-06-08 06:19:11 +00:00
|
|
|
],
|
|
|
|
/* ... */
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
2017-09-24 23:40:09 +00:00
|
|
|
For the browser deployments, the output format is `'iife'`. For node, the
|
|
|
|
output format is `'cjs'`.
|
|
|
|
|
|
|
|
### Worker Scripts
|
|
|
|
|
|
|
|
Rollup can also bundle worker scripts! Instead of using `importScripts`, the
|
|
|
|
worker script should import the module:
|
|
|
|
|
|
|
|
```diff
|
|
|
|
-importScripts('dist/xlsx.full.min.js');
|
2022-03-07 07:36:36 +00:00
|
|
|
+import * as XLSX from 'xlsx'; // or do named imports
|
2017-09-24 23:40:09 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
[![Analytics](https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/js-xlsx?pixel)](https://github.com/SheetJS/js-xlsx)
|