Skip to content

Commit 481ea18

Browse files
committed
Add browserify
1 parent 1525c6b commit 481ea18

File tree

5 files changed

+58
-23
lines changed

5 files changed

+58
-23
lines changed

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
This project is alpha version, forever.
44

5-
## Features
5+
## Installation
66

7-
Require [Babel](https://babeljs.io/), [PostCSS](https://github.com/postcss/postcss).
7+
Firtst up, you have to install latest [Node.js](https://nodejs.org/en/).
88

9-
### Plugins
9+
Next, please type the following commands.
1010

11-
+ [autoprefixer](https://github.com/postcss/autoprefixer)
12-
+ [postcss-calc](https://github.com/postcss/postcss-calc)
13-
+ [postcss-custom-properties](https://github.com/postcss/postcss-custom-properties)
14-
+ [postcss-import](https://github.com/postcss/postcss-import)
15-
+ [cssnano](https://github.com/ben-eb/cssnano)
16-
+ [stylelint](http://stylelint.io/)
11+
```
12+
$ npm install -g gulp
13+
$ cd path/to/maple
14+
$ npm install
15+
$ npm start
16+
```
1717

18-
## Installation
18+
### Taking Future Syntax
1919

20-
This project use a bunch of npm, so you need [Node.js](https://nodejs.org/) v4.0+.
20+
+ JavaScript: [Babel](https://babeljs.io/)
21+
+ CSS: [cssnext](http://cssnext.io/)(some specs only)

bundle.js

Whitespace-only changes.

dest/js/app.js

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
var gulp = require('gulp');
22
var browserSync = require('browser-sync');
33
var sourcemaps = require('gulp-sourcemaps');
4-
var babel = require('gulp-babel');
54
var eslint = require('gulp-eslint');
65
var postcss = require('gulp-postcss');
76
var del = require('del');
@@ -17,28 +16,58 @@ var processors = [
1716
})
1817
];
1918

19+
var source = require('vinyl-source-stream');
20+
var buffer = require('vinyl-buffer');
2021
var browserify = require('browserify');
2122
var babelify = require('babelify');
2223
var watchify = require('watchify');
2324
var uglify = require('gulp-uglify');
2425

26+
// Thanks
27+
// https://gist.github.com/danharper/3ca2273125f500429945
28+
function compile(watch) {
29+
var bundler = watchify(browserify('src/js/app.js', {debug: true}).transform(babelify));
30+
function rebundle() {
31+
bundler.bundle()
32+
.on('error', function (err) {
33+
console.error(err);
34+
this.emit('end');
35+
})
36+
.pipe(source('app.js'))
37+
.pipe(buffer())
38+
.pipe(sourcemaps.init()
39+
.pipe(uglify())
40+
.pipe(sourcemaps.write('./'))
41+
.pipe(gulp.dest('dest/js'));
42+
}
43+
if (watch) {
44+
bundler.on('update', function () {
45+
console.log('-> bundling...');
46+
rebundle();
47+
});
48+
}
49+
rebundle();
50+
}
51+
52+
function watch() {
53+
return compile(true);
54+
}
55+
gulp.task('build:js', function() { return compile(); });
56+
gulp.task('watch:js', function() { return watch(); });
57+
58+
2559
// Clean Dir
2660
gulp.task('clean', function () {
2761
del(['dest/js', 'dest/css']).then(function (paths) {
2862
console.log('Deleted files/folders:\n', paths.join('\n'));
2963
});
3064
});
3165

32-
// JavaScript Task
33-
gulp.task('js', function () {
66+
// ES Lint
67+
gulp.task('lint', function () {
3468
return gulp.src('src/js/app.js')
35-
.pipe(sourcemaps.init())
3669
.pipe(eslint())
37-
.pipe(eslint.format())
38-
.pipe(babel())
39-
.pipe(uglify())
40-
.pipe(sourcemaps.write('.'))
41-
.pipe(gulp.dest('dest/js'));
70+
.pipe(eslint.format());
4271
});
4372

4473
// CSS Task

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@
2525
"start": "gulp serve",
2626
"build": "gulp build"
2727
},
28+
"dependencies": {
29+
"babel": "^5.8.23"
30+
},
2831
"devDependencies": {
2932
"autoprefixer": "^6.0.2",
30-
"babel": "^5.8.23",
3133
"babelify": "^6.3.0",
3234
"browser-sync": "^2.8.2",
3335
"browserify": "^11.2.0",
3436
"cssnano": "^3.0.0",
3537
"del": "^2.0.2",
3638
"gulp": "^3.9.0",
37-
"gulp-babel": "^5.2.1",
3839
"gulp-eslint": "^1.0.0",
3940
"gulp-postcss": "^6.0.0",
4041
"gulp-sourcemaps": "^1.5.2",
@@ -45,6 +46,8 @@
4546
"postcss-import": "^7.0.0",
4647
"postcss-reporter": "^1.1.0",
4748
"stylelint": "^1.2.1",
49+
"vinyl-buffer": "^1.0.0",
50+
"vinyl-source-stream": "^1.1.0",
4851
"watchify": "^3.4.0"
4952
},
5053
"license": "MIT"

0 commit comments

Comments
 (0)