Package Exports
- vite-plugin-commonjs
- vite-plugin-commonjs/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (vite-plugin-commonjs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
vite-plugin-commonjs
A pure JavaScript implementation for CommonJs
English | 简体中文
🔨 The plugin only work in the vite serve
phase
🚚 In the vite build
phase, CommonJs syntax will be supported by builtin @rollup/plugin-commonjs
Usage
import commonjs from 'vite-plugin-commonjs'
export default {
plugins: [
commonjs(/* options */),
]
}
API
export interface Options {
filter?: (id: string) => false | void
}
TODO
- Nested scope(function-scope)
- Dynamic require id
- require statement
// Top-level scope
const foo = require('foo').default
↓
import foo from 'foo';
const foo = require('foo')
↓
import * as foo from 'foo';
const foo = require('foo').bar
↓
import * as __CJS_import__0__ from 'foo'; const { bar: foo } = __CJS_import__0__;
// Non top-level scope
const foo = [{ bar: require('foo').bar }]
↓
import * as __CJS_import__0__ from 'foo'; const foo = [{ bar: __CJS_import__0__.bar }]
- exports statement