Skip to content

Commit d6a55bc

Browse files
committed
replace browserify in favor of webpack
1 parent ae48c9e commit d6a55bc

File tree

5 files changed

+63
-65
lines changed

5 files changed

+63
-65
lines changed

app/src/preprocessors.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,20 @@ module.exports = function(GulpAngularGenerator) {
3535
/**
3636
* Compute gulp inject task dependencies depending on js and css preprocessors
3737
*/
38-
GulpAngularGenerator.prototype.computeInjectTaskDeps = function computeInjectTaskDeps() {
39-
this.injectTaskDeps = [];
40-
if (this.props.cssPreprocessor.key !== 'none') {
41-
this.injectTaskDeps.push('\'styles\'');
38+
GulpAngularGenerator.prototype.computeWatchTaskDeps = function computeInjectTaskDeps() {
39+
this.watchTaskDeps = [];
40+
41+
if (this.props.jsPreprocessor.srcExtension === 'es6') {
42+
this.watchTaskDeps.push('\'scripts:watch\'');
4243
}
4344

44-
if (this.props.jsPreprocessor.key === 'traceur') {
45-
this.injectTaskDeps.push('\'browserify\'');
46-
} else {
47-
this.injectTaskDeps.push('\'scripts\'');
45+
if (this.props.htmlPreprocessor.key !== 'none') {
46+
this.watchTaskDeps.push('\'markups\'');
4847
}
48+
49+
this.watchTaskDeps.push('\'inject\'');
50+
51+
console.log('this.watchTaskDeps', this.watchTaskDeps);
4952
};
5053

5154
/**

app/templates/_package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,12 @@
4545
"gulp-coffee": "~2.3.1",
4646
"gulp-coffeelint": "~0.4.0",
4747
<% } if (props.jsPreprocessor.srcExtension === 'es6') { %>
48-
"browserify": "~8.1.1",
49-
"vinyl-buffer": "~1.0.0",
50-
"vinyl-source-stream": "~1.0.0",
48+
"gulp-webpack": "~1.2.0",
49+
"jshint-loader": "~0.8.3",
5150
<% } if (props.jsPreprocessor.key === 'babel') { %>
52-
"babelify": "~5.0.3",
51+
"babel-loader": "~4.0.0",
5352
<% } if (props.jsPreprocessor.key === 'traceur') { %>
54-
"gulp-traceur": "~0.17.0",
53+
"traceur-loader": "~0.6.3",
5554
<% } if (props.jsPreprocessor.key === 'typescript') { %>
5655
"gulp-typescript": "~2.4.0",
5756
"gulp-tslint": "~1.4.1",

app/templates/gulp/_inject.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ var $ = require('gulp-load-plugins')();
77
var wiredep = require('wiredep').stream;
88

99
module.exports = function(options) {
10-
<% if (_.isEmpty(injectTaskDeps)) { %>
1110
gulp.task('inject', function () {
12-
<% } else { %>
13-
gulp.task('inject', [<%= injectTaskDeps.join(', ') %>], function () {
14-
<% } %>
15-
1611
var injectStyles = gulp.src([
1712
<% if (props.cssPreprocessor.key !== 'none') { %>
1813
options.tmp + '/serve/{app,components}/**/*.css',

app/templates/gulp/_scripts.js

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,19 @@ var gulp = require('gulp');
44
var browserSync = require('browser-sync');
55
<% if (props.jsPreprocessor.key === 'typescript') { %>
66
var mkdirp = require('mkdirp');
7-
<% } if (props.jsPreprocessor.srcExtension === 'es6') { %>
8-
var browserify = require('browserify');
9-
var source = require('vinyl-source-stream');
10-
var buffer = require('vinyl-buffer');
11-
<% } if (props.jsPreprocessor.key === 'babel') { %>
12-
var babelify = require('babelify');
137
<% } %>
148

159
var $ = require('gulp-load-plugins')();
1610

1711
module.exports = function(options) {
18-
<% if (props.jsPreprocessor.key === 'typescript') { %>
12+
<% if (props.jsPreprocessor.srcExtension !== 'es6') { %>
13+
<% if (props.jsPreprocessor.key === 'typescript') { %>
1914
gulp.task('scripts', ['tsd:install'], function () {
2015
mkdirp.sync(options.tmp);
2116

22-
<% } else { %>
17+
<% } else { %>
2318
gulp.task('scripts', function () {
24-
<% } %>
25-
<% if (props.jsPreprocessor.key !== 'babel') { %>
19+
<%  } %>
2620
return gulp.src(options.src + '/{app,components}/**/*.<%= props.jsPreprocessor.extension %>')
2721
<% if (props.jsPreprocessor.extension === 'js') { %>
2822
.pipe($.jshint())
@@ -53,33 +47,46 @@ module.exports = function(options) {
5347
<% } %>
5448
.pipe(browserSync.reload({ stream: true }))
5549
.pipe($.size());
50+
});
5651
<% } else { %>
57-
return browserify({ debug: true })
58-
.add('./' + options.src + '/app/index.js')
59-
.transform(babelify)
60-
.bundle().on('error', options.errorHandler('Browserify'))
61-
.pipe(source('index.js'))
62-
.pipe(buffer())
63-
.pipe($.sourcemaps.init({ loadMaps: true }))
64-
.pipe($.sourcemaps.write())
65-
.pipe(gulp.dest(options.tmp + '/serve/app'))
66-
.pipe(browserSync.reload({ stream: true }))
67-
.pipe($.size());
68-
<% } %>
52+
function webpack(watch, callback) {
53+
return gulp.src(options.src + '/app/index.js')
54+
.pipe($.webpack({
55+
watch: watch,
56+
module: {
57+
preLoaders: [{ test: /\.js$/, exclude: /node_modules/, loader: 'jshint-loader'}],
58+
<% if (props.jsPreprocessor.key === 'babel') { %>
59+
loaders: [{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'}]
60+
<% } if (props.jsPreprocessor.key === 'traceur') { %>
61+
loaders: [{ test: /\.js$/, exclude: /node_modules/, loader: 'traceur-loader'}]
62+
<% } %>
63+
},
64+
output: { filename: 'index.js' }
65+
}, null, function(err, stats) {
66+
if(err) {
67+
options.errorHandler('Webpack')(err);
68+
}
69+
$.util.log(stats.toString({
70+
colors: $.util.colors.supportsColor,
71+
chunks: false,
72+
hash: false,
73+
version: false
74+
}));
75+
browserSync.reload();
76+
if(watch) {
77+
watch = false;
78+
callback();
79+
}
80+
}))
81+
.pipe(gulp.dest(options.tmp + '/serve/app'));
82+
}
83+
84+
gulp.task('scripts', function () {
85+
return webpack(false);
6986
});
7087

71-
<% if (props.jsPreprocessor.key === 'traceur') { %>
72-
gulp.task('browserify', ['scripts'], function () {
73-
return browserify({ debug: true })
74-
.add('./' + options.tmp + '/<%= props.jsPreprocessor.key %>/app/index.js')
75-
.bundle().on('error', options.errorHandler('Browserify'))
76-
.pipe(source('index.js'))
77-
.pipe(buffer())
78-
.pipe($.sourcemaps.init({ loadMaps: true }))
79-
.pipe($.sourcemaps.write())
80-
.pipe(gulp.dest(options.tmp + '/serve/app'))
81-
.pipe(browserSync.reload({ stream: true }))
82-
.pipe($.size());
88+
gulp.task('scripts:watch', function (callback) {
89+
return webpack(true, callback);
8390
});
84-
<% } %>
91+
<% } %>
8592
};

app/templates/gulp/_watch.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ function isOnlyChange(event) {
1010
}
1111

1212
module.exports = function(options) {
13-
<% if (props.htmlPreprocessor.key === 'none') { %>
14-
gulp.task('watch', ['inject'], function () {
15-
<% } else { %>
16-
gulp.task('watch', ['markups', 'inject'], function () {
17-
<% } %>
13+
gulp.task('watch', [<%= watchTaskDeps.join(', ') %>], function () {
1814

1915
gulp.watch([options.src + '/*.html', 'bower.json'], ['inject']);
2016

@@ -37,24 +33,22 @@ module.exports = function(options) {
3733
}
3834
});
3935

40-
<% if (props.jsPreprocessor.extension === 'js') { %>
36+
<% if (props.jsPreprocessor.srcExtension !== 'es6') { %>
37+
<% if (props.jsPreprocessor.extension === 'js') { %>
4138
gulp.watch(options.src + '/{app,components}/**/*.js', function(event) {
42-
<% } else { %>
39+
<% } else { %>
4340
gulp.watch([
4441
options.src + '/{app,components}/**/*.js',
4542
options.src + '/{app,components}/**/*.<%= props.jsPreprocessor.extension %>'
4643
], function(event) {
47-
<% } %>
44+
<% } %>
4845
if(isOnlyChange(event)) {
49-
<% if (props.jsPreprocessor.key !== 'traceur') { %>
5046
gulp.start('scripts');
51-
<% } else { %>
52-
gulp.start('browserify');
53-
<% } %>
5447
} else {
5548
gulp.start('inject');
5649
}
5750
});
51+
<% } %>
5852

5953
<% if (props.htmlPreprocessor.key !== 'none') { %>
6054
gulp.watch(options.src + '/{app,components}/**/*.<%= props.htmlPreprocessor.extension %>', ['markups']);

0 commit comments

Comments
 (0)