README
xng-cjs
把 JavaScript 模块从CommonJs 规范转化为 ES6 规范.
快速开始
全局安装:
npm install xng-cjs -g
本地调试:
cnpm i
node bin/xng-cjs [文件或者文件名]
每次更新后npm run build
全局命令使用:
xng-cjs [文件或者文件名]
如 xng-cjs src | xng-cjs src/fileName.js
暂时不支持的转换格式
const a = require('a').default;
const {a, b} = require('a');
const a, {b, c} = require('a');
const obj = {};
let a = {
a,
...obj
}
module.exports = a
转换效果
const a = require('./a'); -> import a from './a';
module.exports = {a:1}; -> exports defualt {a:1};
························································
// import PROFILE_SIZE from './sss';
let COMMIT_SIZE = {};
const COVER_SIZE = {
COMMIT_SIZE,
PROFILE_SIZE
};
module.exports = COVER_SIZE;
↓
// The current module is compiled by xng-cjs
// import PROFILE_SIZE from './sss';
let COMMIT_SIZE = {};
const COVER_SIZE = {
COMMIT_SIZE,
PROFILE_SIZE
};
export const PROFILE_SIZE = COVER_SIZE['PROFILE_SIZE'];
export default COVER_SIZE;
························································
const COVER_SIZE = {
COMMIT_SIZE,
PROFILE_SIZE
};
module.exports = COVER_SIZE;
↓
const COVER_SIZE = {
COMMIT_SIZE,
PROFILE_SIZE
};
export const COMMIT_SIZE = COVER_SIZE['COMMIT_SIZE'];
export const PROFILE_SIZE = COVER_SIZE['PROFILE_SIZE'];
export default COVER_SIZE;
························································
exports.c = 'c'; - > export const c = "c";
exports.f = function() {
return 'f';
};
↓
export const f = function () {
return "f";
};
let COMMIT_SIZE = '180x140';
let PROFILE_SIZE = '180x140';
const COVER_SIZE = {
COMMIT_SIZE,
PROFILE_SIZE,
};
module.exports = COVER_SIZE;
↓
let COMMIT_SIZE = "180x140";
let PROFILE_SIZE = "180x140";
const COVER_SIZE = {
COMMIT_SIZE,
PROFILE_SIZE
};
export default COVER_SIZE;