{"id":19560688,"url":"https://github.com/zoubin/watchify-factor-bundle-gulp","last_synced_at":"2025-02-26T08:41:49.771Z","repository":{"id":34059339,"uuid":"37844857","full_name":"zoubin/watchify-factor-bundle-gulp","owner":"zoubin","description":"Example to use watchify + factor-bundle + gulp","archived":false,"fork":false,"pushed_at":"2015-06-25T06:02:47.000Z","size":160,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-08T22:43:38.886Z","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-06-22T08:30:06.000Z","updated_at":"2017-02-24T21:19:22.000Z","dependencies_parsed_at":"2022-07-15T20:00:43.339Z","dependency_job_id":null,"html_url":"https://github.com/zoubin/watchify-factor-bundle-gulp","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%2Fwatchify-factor-bundle-gulp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Fwatchify-factor-bundle-gulp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Fwatchify-factor-bundle-gulp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Fwatchify-factor-bundle-gulp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zoubin","download_url":"https://codeload.github.com/zoubin/watchify-factor-bundle-gulp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240822615,"owners_count":19863302,"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:28.313Z","updated_at":"2025-02-26T08:41:49.742Z","avatar_url":"https://github.com/zoubin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# watchify-factor-bundle-gulp\nExample to use watchify + factor-bundle + gulp\n\n## Usage\n\nHere is a solution based on the [pull-request](https://github.com/substack/factor-bundle/pull/73)\n\n```bash\ngit clone https://github.com/zoubin/watchify-factor-bundle-gulp.git\ncd watchify-factor-bundle-gulp\nnpm i\ncd factor-bundle-callback\nnpm i\n\ngulp\n```\n\nAnd this is a solution based on a hack:\n\n```bash\ngit clone https://github.com/zoubin/watchify-factor-bundle-gulp.git\ncd watchify-factor-bundle-gulp\nnpm i\n\ngulp --gulpfile hack.js\n```\n\n## gulpfile.js\n\n```javascript\nvar gulp = require('gulp');\nvar gutil = require('gulp-util');\nvar watchify = require('watchify');\nvar browserify = require('browserify');\nvar source = require('vinyl-source-stream');\nvar es = require('event-stream');\nvar path = require('path');\n\nvar entries = [ src('blue/index.js'), src('red/index.js') ];\nvar opts = {\n    entries: entries,\n};\nvar b = watchify(browserify(opts));\n\nb.plugin('./factor-bundle-callback', {\n    entries: [ src('blue/index.js'), src('red/index.js') ],\n    outputs: function () {\n        return [ source('blue.js'), source('red.js') ];\n    },\n});\n\ngulp.task('default', bundle); // so you can run `gulp js` to build the file\nb.on('update', bundle); // on any dep update, runs the bundler\nb.on('log', gutil.log); // output build logs to terminal\n\nfunction bundle() {\n    return new Promise(function (resolve) {\n        var common = b.bundle().pipe(source('common.js'));\n        b.once('factor.pipelines', function (files, pipelines, outputs) {\n            es.merge(outputs.concat(common))\n                // log errors if they happen\n                .on('error', gutil.log.bind(gutil, 'Browserify Error'))\n                .pipe(gulp.dest('./build/js'))\n                .on('finish', function () {\n                    resolve();\n                });\n        });\n    });\n}\n\nfunction src() {\n    return path.resolve.bind(path, __dirname, 'src/page').apply(null, arguments);\n}\n\n```\n\n## hack.js\n\n```javascript\nvar wrap = require('gulp-watchify-factor-bundle');\nvar gulp = require('gulp');\nvar gutil = require('gulp-util');\nvar path = require('path');\nvar buffer = require('vinyl-buffer');\nvar uglify = require('gulp-uglify');\nvar browserify = require('browserify');\n\nvar entries = [ src('blue/index.js'), src('red/index.js') ];\nvar b = browserify({\n    entries: entries,\n});\n\nvar bundle = wrap(b,\n    // options for factor bundle.\n    {\n        entries: entries,\n        outputs: [ 'blue.js', 'red.js' ],\n        common: 'common.js',\n    },\n    // more transforms. Should always return a stream.\n    function (bundleStream) {\n        return bundleStream\n            .on('error', gutil.log.bind(gutil, 'Browserify Error'))\n\n            // `optional`. use `buffer()` to make `stream not support` gulp plugins work\n            .pipe(buffer())\n\n            // use more gulp plugins here\n            .pipe(uglify())\n\n            .pipe(gulp.dest('./build/js'))\n    }\n);\n\nb.on('log', gutil.log);\n// normal bundle task\ngulp.task('default', bundle);\n// watchify bundle task\ngulp.task('watch', wrap.watch(bundle));\n\nfunction src() {\n    return path.resolve.bind(path, __dirname, 'src/page').apply(null, arguments);\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoubin%2Fwatchify-factor-bundle-gulp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzoubin%2Fwatchify-factor-bundle-gulp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoubin%2Fwatchify-factor-bundle-gulp/lists"}