1.5.0 • Published 2 years ago
vite-plugin-esmodule v1.5.0
vite-plugin-esmodule
Build ES module to CommonJs module for Node.js/Electron
Why 🤔
When using ES modules(e.g.node-fetch) in Node.js/Electron projects, we may need to compile them into CommonJs modules to ensure they work correctly.
在 Node.js/Electron 项目中使用 ES 模块时(e.g. node-fetch),我们可能需要将其编译成 CommonJs 模块,以确保它们能够正常工作
Install
npm i -D vite-plugin-esmodule webpackUsage
vite.config.js
import esmodule from 'vite-plugin-esmodule'
export default {
  plugins: [
    // Take `execa`, `node-fetch` and `file-type` as examples
    esmodule([
      'execa',
      'node-fetch',
      // 🌱 this means that you have explicit specified the entry file
      { 'file-type': 'file-type/index.js' },
    ]),
  ],
}execa.js
import {execa} from 'execa';
const {stdout} = await execa('echo', ['unicorns']);
console.log(stdout);
//=> 'unicorns'API (Define)
esmodule(modules[, webpack])
import type { Configuration } from 'webpack'
type ModuleRecord = string | { [module: string]: string }
function esmodule(
  modules: ModuleRecord[] | ((esmPkgs: string[]) => ModuleRecord[]),
  webpack?: ((config: Configuration) => Configuration | void | Promise<Configuration | void>),
): import('vite').PluginHow to work
This plugin just wraps vite-plugin-optimizer
1.5.0
2 years ago
1.4.4
3 years ago
1.4.3
3 years ago
1.4.2
3 years ago
1.4.1
3 years ago
1.3.2
3 years ago
1.4.0
3 years ago
1.3.1
3 years ago
1.3.0
3 years ago
1.2.0
4 years ago
1.1.1
4 years ago
1.1.0
4 years ago
1.0.1
4 years ago
1.2.5
4 years ago
1.2.4
4 years ago
1.2.3
4 years ago
1.2.2
4 years ago
1.2.1
4 years ago
1.1.2
4 years ago
1.0.0
4 years ago