New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gulp-expose

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-expose

Expose a node module in browser, no dependencies handled

0.0.7
latest
Source
npm
Version published
Weekly downloads
356
-6.32%
Maintainers
1
Weekly downloads
 
Created
Source

gulp-expose

Expose module.exports to a global object, like window in the browser envrionment.

install

npm install --save-dev gulp-expose

usage

number.js:

module.exports = 1;
var expose = require('gulp-expose');
gulp.src('number.js')
    .pipe(expose('window', 'One'))
    .pipe(gulp.dest('dist'));
// window.MyFavNumber.One == 1

OR

var expose = require('gulp-expose');
gulp.src('number.js')
    .pipe(expose('window.MyFavNumber', 'One'))
    .pipe(gulp.dest('dist'));

// window.MyFavNumber.One == 1
// as long as the namespace `window.MyFavNumber` is available.

And json can be exposed, too:

config.json:

{
    "name": "gulp-expose"
}

var expose = require('gulp-expose');
var gulp = require('gulp-rename');

gulp.src('test/src/config.json')
    .pipe(expose('window', 'PKG'))
    .pipe(rename('config.js'))
    .pipe(gulp.dest('test/dist'))

// window.PKG = { name: 'gulp-expose' }

expose(host, expose)

  • host. String. The object that will have the exposed api. It can be any valid expression that can be evaluated as an object.
  • expose. String. The property name that will be added to host, with the exposed api.

If host is a function, it receives a vinyl file object, and should return the expose info object { host: host, expose: expose }.

example

build

var gulp = require('gulp');
var expose = require('gulp-expose');
gulp.src('number.js')
    .pipe(expose('window', 'One'))
    .pipe(gulp.dest('dist'));

dist/number.js

(function (host, expose) {
   var module = { exports: {} };
   var exports = module.exports;
   /****** code begin *********/
module.exports = 1;

   /****** code end *********/
   ;(
function copy(src, target, obj) {
    obj[target] = obj[target] || {};
    if (src && typeof src === 'object') {
        for (var k in src) {
            if (src.hasOwnProperty(k)) {
                obj[target][k] = src[k];
            }
        }
    } else {
        obj[target] = src;
    }
}
   ).call(null, module.exports, expose, host);
}).call(window, window, "One");

Now in browser:

window.One === 1; // true

Keywords

gulp

FAQs

Package last updated on 16 Apr 2015

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