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.1.0
  • Source
  • npm
  • Socket score

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

vite-plugin-esmodule

npm package
NPM version NPM Downloads

Build ES module to CommonJs module for Node.js

English | 简体中文

Why

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

🚧 Warning

The plugin only work in the vite build phase

The Plugin built NPM Packages use Vite by default, of course you can specify use Webpack by options.webpack

If some NPM Packges have problems after being built with vite, please choose to build with options.webpack

Usage

Take execa, node-fetch and file-type as examples

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

export default {
  plugins: [
    esmodule([
      'execa',
      'node-fetch',
      // file-type have exports condition in package.json
      { 'file-type': 'file-type/index.js' },
    ]),
  ],
}
  • execa.js
import {execa} from 'execa';

const {stdout} = await execa('echo', ['unicorns']);
console.log(stdout);
//=> 'unicorns'

See the test cases

API

esmodule(modules[,options])

modules: ES module name list

modules: (string | { [module: string]: string })[]

options:

options?: WebpackOptions | ViteOptions

export interface WebpackOptions {
  webpack?: true | ((config: Configuration) => Configuration | void | Promise<Configuration | void>);
  vite: never;
}

export interface ViteOptions {
  vite?: true | ((config: UserConfig) => UserConfig | void | Promise<UserConfig | void>);
  webpack: never;
}

How to work

This plugin just wraps vite-plugin-optimizer

Keywords

FAQs

Package last updated on 23 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