{"id":19560640,"url":"https://github.com/zoubin/gulp-expose","last_synced_at":"2025-09-05T10:32:56.290Z","repository":{"id":30431279,"uuid":"33984267","full_name":"zoubin/gulp-expose","owner":"zoubin","description":"Expose a node module in browser, no dependencies handled","archived":false,"fork":false,"pushed_at":"2018-08-29T05:44:41.000Z","size":9,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-25T07:52:35.355Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zoubin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-15T09:11:07.000Z","updated_at":"2018-08-29T05:44:42.000Z","dependencies_parsed_at":"2022-08-03T15:14:00.192Z","dependency_job_id":null,"html_url":"https://github.com/zoubin/gulp-expose","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Fgulp-expose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Fgulp-expose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Fgulp-expose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Fgulp-expose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zoubin","download_url":"https://codeload.github.com/zoubin/gulp-expose/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231903628,"owners_count":18443552,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T05:08:21.641Z","updated_at":"2024-12-31T23:37:03.035Z","avatar_url":"https://github.com/zoubin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gulp-expose\nExpose module.exports to a global object, like `window` in the browser envrionment.\n\n## install\n```\nnpm install --save-dev gulp-expose\n```\n## usage\n\nnumber.js:\n\n```\nmodule.exports = 1;\n```\n\n```javascript\nvar expose = require('gulp-expose');\ngulp.src('number.js')\n    .pipe(expose('window', 'One'))\n    .pipe(gulp.dest('dist'));\n// window.One == 1\n```\n\nOR\n\n```javascript\nvar expose = require('gulp-expose');\ngulp.src('number.js')\n    .pipe(expose('window.MyFavNumber', 'One'))\n    .pipe(gulp.dest('dist'));\n\n// window.MyFavNumber.One == 1\n// as long as the namespace `window.MyFavNumber` is available.\n```\n\nAnd json can be exposed, too:\n\nconfig.json:\n\n```js\n{\n    \"name\": \"gulp-expose\"\n}\n```\n\n```js\nvar expose = require('gulp-expose');\nvar gulp = require('gulp-rename');\n\ngulp.src('test/src/config.json')\n    .pipe(expose('window', 'PKG'))\n    .pipe(rename('config.js'))\n    .pipe(gulp.dest('test/dist'))\n\n// window.PKG = { name: 'gulp-expose' }\n```\n\n### expose(host, expose)\n\n* host. String. The object that will have the exposed api. It can be any valid expression that can be evaluated as an object.\n* expose. String. The property name that will be added to `host`, with the exposed api.\n\nIf `host` is a function, it receives a [vinyl](https://github.com/wearefractal/vinyl) `file` object, and should return the expose info object `{ host: host, expose: expose }`.\n\n## example\n\n### build\n\n```javascript\nvar gulp = require('gulp');\nvar expose = require('gulp-expose');\ngulp.src('number.js')\n    .pipe(expose('window', 'One'))\n    .pipe(gulp.dest('dist'));\n```\n\n### dist/number.js\n\n```javascript\n(function (host, expose) {\n   var module = { exports: {} };\n   var exports = module.exports;\n   /****** code begin *********/\nmodule.exports = 1;\n\n   /****** code end *********/\n   ;(\nfunction copy(src, target, obj) {\n    obj[target] = obj[target] || {};\n    if (src \u0026\u0026 typeof src === 'object') {\n        for (var k in src) {\n            if (src.hasOwnProperty(k)) {\n                obj[target][k] = src[k];\n            }\n        }\n    } else {\n        obj[target] = src;\n    }\n}\n   ).call(null, module.exports, expose, host);\n}).call(window, window, \"One\");\n```\n\nNow in browser:\n\n```\nwindow.One === 1; // true\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoubin%2Fgulp-expose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzoubin%2Fgulp-expose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoubin%2Fgulp-expose/lists"}