UNPKG

1.76 kBMarkdownView Raw
1[npm]: https://img.shields.io/npm/v/@rollup/plugin-esm-shim
2[npm-url]: https://www.npmjs.com/package/@rollup/plugin-esm-shim
3[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-esm-shim
4[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-esm-shim
5
6[![npm][npm]][npm-url]
7[![size][size]][size-url]
8[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com)
9
10# @rollup/plugin-esm-shim
11
12🍣 A Rollup plugin to replace CJS global variables within esm output bundles.
13
14The list of global variables that are shimmed are:
15
16- `__filename`: This variable corresponds to the file path of the generated bundle file.
17- `__dirname`: This variable corresponds to the folder path of the created bundle file.
18- `require`: Corresponds to a function to import modules in a synchronous way.
19
20## Requirements
21
22This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v2.0+.
23
24## Install
25
26Using npm:
27
28```console
29npm install @rollup/plugin-esm-shim --save-dev
30```
31
32## Usage
33
34Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin:
35
36```typescript
37import esmShim from '@rollup/plugin-esm-shim';
38
39export default {
40 input: 'src/index.js',
41 output: {
42 dir: 'output',
43 format: 'cjs'
44 },
45 plugins: [esmShim()]
46};
47```
48
49Then call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#command-line-reference) or the [API](https://www.rollupjs.org/guide/en/#javascript-api).
50
51## Meta
52
53[CONTRIBUTING](/.github/CONTRIBUTING.md)
54
55[LICENSE (MIT)](/LICENSE)
56
57Portions of this code were used with permission from [unbuild](https://github.com/unjs/unbuild). [unbuild LICENSE](./unbuild.LICENSE)