Socket
Book a DemoInstallSign in
Socket

dist-wrap

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dist-wrap

Used for front-end dist, module, amd, global wrap source.

latest
Source
npmnpm
Version
3.0.1
Version published
Maintainers
1
Created
Source

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');

Keywords

front-end

FAQs

Package last updated on 26 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.