-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: bundle event on watch stream
- Loading branch information
Showing
21 changed files
with
98 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
'use strict' | ||
|
||
const reduce = require('../../..') | ||
const gulp = require('gulp') | ||
const path = require('path') | ||
const del = require('del') | ||
|
||
gulp.task('clean', function () { | ||
return del(path.join(__dirname, 'build')) | ||
}) | ||
|
||
gulp.task('build', ['clean'], function () { | ||
let basedir = path.join(__dirname, 'src') | ||
let b = reduce.create({ | ||
basedir: basedir, | ||
paths: [path.join(basedir, 'web_modules')], | ||
}) | ||
|
||
// As multiple bundles are created, | ||
// it is important to deal with duplicates carefully. | ||
// There are known issues caused in such cases. | ||
// See https://github.com/substack/factor-bundle/issues/51 | ||
// This plugin will just disable the default dedupe transform. | ||
b.plugin('dedupify') | ||
b.on('dedupify.deduped', function (o) { | ||
console.warn('Duplicates of modules found!', o.file, o.dup) | ||
}) | ||
|
||
return gulp.src('page/**/index.js', { cwd: basedir }) | ||
.pipe(reduce.bundle(b, { | ||
// This object is passed to `common-bundle`. | ||
groups: 'page/**/index.js', | ||
common: 'common.js', | ||
})) | ||
.pipe(gulp.dest('build')) | ||
}) | ||
|
||
gulp.task('watch', ['clean'], function () { | ||
let clean = require('clean-remains')([]) | ||
let basedir = path.join(__dirname, 'src') | ||
let b = reduce.create({ | ||
basedir: basedir, | ||
paths: [path.join(basedir, 'web_modules')], | ||
cache: {}, | ||
packageCache: {}, | ||
}) | ||
b.plugin('dedupify') | ||
b.on('dedupify.deduped', function (o) { | ||
console.warn('Duplicates of modules found!', o.file, o.dup) | ||
}) | ||
return gulp.src('page/**/index.js', { cwd: basedir }) | ||
.pipe(reduce.watch(b, { | ||
groups: 'page/**/index.js', | ||
common: 'common.js', | ||
}, { entryGlob: 'page/**/index.js' })) | ||
.on('bundle', function (bundleStream) { | ||
bundleStream | ||
.pipe(gulp.dest('build')) | ||
// This plugin will remove files created in the building history but no longer in the newest build. | ||
.pipe(clean()) | ||
.on('data', file => console.log('bundle:', file.relative)) | ||
.on('end', () => console.log('-'.repeat(40))) | ||
}) | ||
}) | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
'use strict' | ||
|
||
const reduce = require('../..') | ||
const reduce = require('reduce-js') | ||
const del = require('del') | ||
|
||
const basedir = __dirname + '/src' | ||
const build = __dirname + '/build' | ||
del(build).then(function () { | ||
let b = reduce.create({ basedir: basedir }) | ||
|
||
b.on('error', err => console.log(err)) | ||
b.on('common.map', map => console.log(map)) | ||
|
||
reduce.src('*.js', { cwd: basedir }) | ||
.pipe(reduce.bundle(b, 'bundle.js')) | ||
.pipe(reduce.dest(build)) | ||
.on('data', file => console.log('bundle:', file.relative)) | ||
.on('end', () => console.log('DONE')) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters