New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vite-plugin-esmodule

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-esmodule

Build ES module to CommonJs module for Node.js

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5K
decreased by-17.21%
Maintainers
1
Weekly downloads
 
Created
Source

npm package

Build ES module to CommonJs module for Node.js

English | 简体中文

NPM version NPM Downloads

Why

When ES module such as execa, node-fetch used in the Node.js project, we should compile them into CommonJs modules to ensure that they can work

📢 The plugin only work in the vite build phase

Usage

Take execa and node fetch as examples

  • vite.config.js
import esmodule from 'vite-plugin-esmodule'

export default {
  plugins: [
    esmodule([
      'execa',
      'node-fetch',
    ]),
  ],
}
  • execa.js
import {execa} from 'execa';

const {stdout} = await execa('echo', ['unicorns']);
console.log(stdout);
//=> 'unicorns'
  • node-fetch.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

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

Keywords

FAQs

Package last updated on 07 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc