woshi555bin / esm-cjs-converter

esm-cjs-converter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

English

esm-cjs-converter

  • Convert ES modules to CommonJS
  • Convert CommonJS to ES modules

usage

Convert ES modules to CommonJS

Before

import { a } from './a.js';
import b from './b.js';

export var c = 1;
export default 2
export default class Person { }
export default function(){}

After

const {a} = require('./a.js');
const b = require('./b.js');
var c = 1;
exports.c = c;
module.exports = 2;

Convert CommonJS to ES modules

Before

const {a} = require('./a.js');
const b = require('./b.js');
var c = 1;
exports.c = c;
module.exports = 2;

After

import { a } from "./a.js";
import b from "./b.js";
var c = 1;
export { c };
export default 2;

中文

esm-cjs-converter

  • 将 ES 模块转换为 CommonJS
  • 将 CommonJS 转换为 ES 模块

使用方法

把 ES modules 转成 CommonJS

转换前

import { a } from './a.js';
import b from './b.js';

export var c = 1;
export default 2

转换后

const {a} = require('./a.js');
const b = require('./b.js');
var c = 1;
exports.c = c;
module.exports = 2;

把 CommonJS 转成 ES modules

转换前

const {a} = require('./a.js');
const b = require('./b.js');
var c = 1;
exports.c = c;
module.exports = 2;

转换后

import { a } from "./a.js";
import b from "./b.js";
var c = 1;
export { c };
export default 2;

About

esm-cjs-converter

License:MIT License


Languages

Language:JavaScript 100.0%