vite-plugin-esmodule
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "vite-plugin-esmodule", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Build ES module to CommonJs module for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -18,2 +18,6 @@ [![npm package](https://nodei.co/npm/vite-plugin-esmodule.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/vite-plugin-esmodule) | ||
Take execa and node fetch as examples | ||
- vite.config.js | ||
```js | ||
@@ -31,1 +35,35 @@ import esmodule from 'vite-plugin-esmodule' | ||
``` | ||
- execa.js | ||
```js | ||
import {execa} from 'execa'; | ||
const {stdout} = await execa('echo', ['unicorns']); | ||
console.log(stdout); | ||
//=> 'unicorns' | ||
``` | ||
- node-fetch.js | ||
```js | ||
import fetch from 'node-fetch'; | ||
const response = await fetch('https://github.com/'); | ||
const body = await response.text(); | ||
console.log(body); | ||
``` | ||
See the test [cases](https://github.com/caoxiemeihao/vite-plugins/tree/main/playground/vite-plugin-esmodule) | ||
## API | ||
#### esmodule(modules: string[]) | ||
modules: ES module name list | ||
## How to work | ||
The plugin will use the `build` API of Vite to build ES module into the `node_modules/.vite-plugin-esmodule` directory | ||
Then point to the built path by modifying `resolve.alias` |
4688
68