{"id":20731104,"url":"https://github.com/stevenmhunt/gulp-detect","last_synced_at":"2025-08-08T18:34:04.244Z","repository":{"id":57257325,"uuid":"67472638","full_name":"stevenmhunt/gulp-detect","owner":"stevenmhunt","description":"Wraps your module-agnostic library code to support CommonJS, RequireJS and standard browser environments.","archived":false,"fork":false,"pushed_at":"2016-09-07T11:24:37.000Z","size":4,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-17T21:21:26.254Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stevenmhunt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-06T04:15:04.000Z","updated_at":"2017-11-24T15:34:44.000Z","dependencies_parsed_at":"2022-09-08T07:34:20.799Z","dependency_job_id":null,"html_url":"https://github.com/stevenmhunt/gulp-detect","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenmhunt%2Fgulp-detect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenmhunt%2Fgulp-detect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenmhunt%2Fgulp-detect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenmhunt%2Fgulp-detect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stevenmhunt","download_url":"https://codeload.github.com/stevenmhunt/gulp-detect/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243012751,"owners_count":20221616,"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-17T05:13:42.158Z","updated_at":"2025-03-11T10:21:19.909Z","avatar_url":"https://github.com/stevenmhunt.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gulp-detect\nWraps your module-agnostic library code to support CommonJS, RequireJS and standard browser environments.\n\n# Installation\n\n    \u003e npm install gulp-detect\n    \n# Usage\n\n    var detect = require('gulp-detect');\n    \n    gulp.task('build', function() {\n        return gulp.src(['./mainFile.js'])\n            .pipe(detect('globalVar'))\n            .pipe(gulp.dest('./dist'));\n    });\n\n#### detect (globalVariable)\n- globalVariable - The name of the global variable to use within your project to add objects to or to set as the default export. The default value is `globalObject`.\n\n# How it works\n\nThe gulp-detect module will take your file streams, and wrap them in an Immediately Invoking Function (IIF) \nto prevent unnecessary entries into `window` if in the browser. Then, it will add environment detection code\nwhich will automatically determine the environment and register then given global variable to either a RequireJS module,\na CommonJS module, or the global `window` object in the browser. Here is a sample of what the transformed file looks like:\n\n    \n    (function () {\n        var _detectedModuleType;\n        if (typeof define === 'function' \u0026\u0026 define.amd) {\n            _detectedModuleType = 'RequireJS';\n        }\n        else if (typeof module === 'object' \u0026\u0026 module.exports) {\n            _detectedModuleType = 'CommonJS';\n        }\n        else if (typeof window !== 'undefined') {\n            _detectedModuleType = 'Browser';\n        }\n        else {\n            throw 'Error: No browser or module system detected!';\n        }\n        var YOUR_GLOBAL_NANE_HERE = {};\n    \n    // your code gets put here.\n    \n        switch (_detectedModuleType) {\n            case 'RequireJS':\n                define(['YOUR_GLOBAL_NANE_HERE'], YOUR_GLOBAL_NANE_HERE);\n                break;\n            case 'CommonJS':\n                module.exports = YOUR_GLOBAL_NANE_HERE;\n                break;\n            case 'Browser':\n                window.YOUR_GLOBAL_NANE_HERE = YOUR_GLOBAL_NANE_HERE;\n                break;\n       }\n    })();\n    \nNote that anything that you wish to expose across module systems must be registered with the global name provided to the `detect()` function call.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenmhunt%2Fgulp-detect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevenmhunt%2Fgulp-detect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenmhunt%2Fgulp-detect/lists"}