3.0.1 • Published 4 years ago

dist-wrap v3.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

dist-wrap

简单的将CommonJS代码转成前端直接能src的代码,支持amd, global加载。

安装

npm install dist-wrap --save-dev

特性

  • 最少的包裹--只有一层。
  • 头部注释不动。
  • 没有module.exports判定,支持CommonJS为啥还用转呢?是吧。

API

wrap(source)

wrap(source, globalName)

必须 在源文件中包含一行 module.exports = someModule

比如源source:

/* hello */
var hello = 'hello';
module.exports = hello; //这个必须有

执行

var wrap = require('dist-wrap');
var result = wrap(source);

结果result:

/* hello */
(function(){
//dist-wrap top

  var hello = 'hello';
  //module.exports = hello;

//dist-wrap bottom
  if(typeof define === 'function' && define.amd) {
    define(function(){
      return hello;
    });
  }else{
    this.hello = hello; //this是全局,.hello可以自定义,见下文
  }
})();

自定义全局命名

如果想要绑定到全局的名字不一样,你可以用第二个参数:

wrap(source, 'HELLO');
3.0.1

4 years ago

3.0.0

4 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.0.2

7 years ago