
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
gulp-expose
Advanced tools
Expose module.exports to a global object, like window
in the browser envrionment.
npm install --save-dev gulp-expose
number.js:
module.exports = 1;
var expose = require('gulp-expose');
gulp.src('number.js')
.pipe(expose(function (file) { return { host: 'window', expose: 'One' } }))
.pipe(gulp.dest('dist'));
// window.MyFavNumber.One == 1
OR
var expose = require('gulp-expose');
gulp.src('number.js')
.pipe(expose(function (file) { return { host: 'window.MyFavNumber', expose: '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(function (file) { return { host: 'window', expose: 'PKG' } }))
.pipe(rename('config.js'))
.pipe(gulp.dest('test/dist'))
// window.PKG = { name: 'gulp-expose' }
getexposeinfo
receives a vinyl file
object, and should return the expose info object:
host
, with the exposed api.var gulp = require('gulp');
var expose = require('gulp-expose');
gulp.src('number.js')
.pipe(expose(function (file) { return { host: 'window', expose: 'One' } }))
.pipe(gulp.dest('dist'));
(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
FAQs
Expose a node module in browser, no dependencies handled
The npm package gulp-expose receives a total of 329 weekly downloads. As such, gulp-expose popularity was classified as not popular.
We found that gulp-expose demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.