Skip to content
This repository was archived by the owner on Jun 1, 2020. It is now read-only.

Commit bff848d

Browse files
authored
Merge pull request #23 from Rulox/develop
Release
2 parents 52e6c58 + ea0e4ce commit bff848d

File tree

4 files changed

+69
-20
lines changed

4 files changed

+69
-20
lines changed

Gulpfile.js

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
var gulp = require('gulp');
22
var eslint = require('gulp-eslint');
3+
var uglify = require('gulp-uglify');
4+
var concat = require('gulp-concat');
5+
var cleanCSS = require('gulp-clean-css');
36
var gulpStyleLint = require('gulp-stylelint');
47
var browserSync = require('browser-sync').create();
58
var sass = require('gulp-sass');
@@ -14,12 +17,12 @@ var sourcemaps = require('gulp-sourcemaps');
1417

1518
// Static Server + watching scss/html files
1619
gulp.task('serve', ['sass', 'js'], function() {
17-
browserSync.init({
18-
server: './public'
19-
});
20-
gulp.watch('app/**/*.scss', ['sass']);
21-
gulp.watch('app/**/*.js', ['js']);
22-
gulp.watch('public/*.html').on('change', browserSync.reload);
20+
browserSync.init({
21+
server: './public'
22+
});
23+
gulp.watch('app/**/*.scss', ['sass']);
24+
gulp.watch('app/**/*.js', ['js']);
25+
gulp.watch('public/*.html').on('change', browserSync.reload);
2326
});
2427

2528
// Run lint for sass
@@ -39,27 +42,43 @@ gulp.task('jslint', function() {
3942
.pipe(eslint.format());
4043
});
4144

45+
// Min js files
46+
gulp.task('uglify', ['js'], function() {
47+
return gulp.src('./public/js/build.js')
48+
.pipe(uglify())
49+
.pipe(concat('build.js'))
50+
.pipe(gulp.dest('./public/js'))
51+
});
52+
53+
// Min css files
54+
gulp.task('minify-css', ['sass'], function() {
55+
return gulp.src('./public/css/main.css')
56+
.pipe(cleanCSS())
57+
.pipe(concat('main.css'))
58+
.pipe(gulp.dest('./public/css'))
59+
});
60+
4261
// Compile sass into CSS & auto-inject into browsers
4362
gulp.task('sass', ['stylelint'], function() {
44-
return gulp.src('./app/main.scss')
45-
.pipe(sass().on('error', sass.logError))
46-
.pipe(autoprefixer({
47-
browsers: ['last 2 versions'],
48-
cascade: false
49-
}))
50-
.pipe(sourcemaps.init({ loadMaps: true }))
51-
.pipe(sourcemaps.write('./'))
52-
.pipe(gulp.dest('./public/css'))
53-
.pipe(browserSync.stream())
54-
.pipe(notify({message: 'CSS created!', onLast: true}));
63+
return gulp.src('./app/main.scss')
64+
.pipe(sass().on('error', sass.logError))
65+
.pipe(autoprefixer({
66+
browsers: ['last 2 versions'],
67+
cascade: false
68+
}))
69+
.pipe(sourcemaps.init({ loadMaps: true }))
70+
.pipe(sourcemaps.write('./'))
71+
.pipe(gulp.dest('./public/css'))
72+
.pipe(browserSync.stream())
73+
.pipe(notify({message: 'CSS created!', onLast: true}));
5574
});
5675

5776
// Transpile ES6 js (React app) into JS & auto-inject into browsers
5877
gulp.task('js', ['jslint'], function() {
5978
var bundler = browserify('./app/app.js').transform("babelify", {presets: ["es2015", "react"]});
6079
return bundler.bundle()
6180
.on('error', function(err) { console.error(err); this.emit('end'); })
62-
.pipe(source('app.js'))
81+
.pipe(source('build.js'))
6382
.pipe(buffer())
6483
.pipe(sourcemaps.init({ loadMaps: true }))
6584
.pipe(sourcemaps.write('./'))
@@ -68,5 +87,20 @@ gulp.task('js', ['jslint'], function() {
6887
.pipe(notify({message: 'JS bundle created!', onLast: true}));
6988
});
7089

90+
// PRODUCTION
91+
gulp.task('set-prod-node-env', function() {
92+
return process.env.NODE_ENV = 'production';
93+
});
94+
95+
gulp.task('production', ['uglify', 'minify-css', 'set-prod-node-env']);
96+
97+
// Start server without build
98+
gulp.task('start', ['production'], function() {
99+
browserSync.init({
100+
server: './public'
101+
});
102+
});
103+
71104
// Tasks
72105
gulp.task('default', ['serve']);
106+

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ web server in your machine that automatically updates the code and the styles wh
1919

2020
* ES6 to JS Transpile
2121
* SASS to CSS
22+
* React Router
2223
* Auto watcher for JS and SCSS files
2324
* Atomic design project structure
2425
* Launch server that updates itself every time we change a file with browsersync
@@ -27,7 +28,6 @@ web server in your machine that automatically updates the code and the styles wh
2728

2829
## TODO List
2930
* Tests
30-
* Production build (minification, etc)
3131

3232
## Requirements
3333
* nodejs v5.*
@@ -113,6 +113,16 @@ npm run build-dev
113113
```
114114
1. Build CSS and JS from sources but does not start browsersync server.
115115

116+
```bash
117+
npm run build-prod
118+
```
119+
1. Build CSS and JS minified and ready for production but does not start browsersync server.
120+
121+
```bash
122+
npm run start-server
123+
```
124+
1. Run the server serving the `/public` folder using browsersync.
125+
116126
```bash
117127
npm run js-lint
118128
```

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"description": "Basic Structure for React app following Atomic Design",
55
"scripts": {
66
"start": "gulp",
7+
"start-server": "gulp start",
78
"build-dev": "gulp js && gulp sass",
9+
"build-prod": "gulp production",
810
"js-lint": "gulp jslint",
911
"sass-lint": "gulp stylelint"
1012
},
@@ -42,11 +44,14 @@
4244
"eslint-plugin-jsx-a11y": "^2.2.2",
4345
"eslint-plugin-react": "^6.3.0",
4446
"gulp-autoprefixer": "^3.1.1",
47+
"gulp-clean-css": "^2.0.12",
48+
"gulp-concat": "^2.6.0",
4549
"gulp-eslint": "^3.0.1",
4650
"gulp-notify": "^2.2.0",
4751
"gulp-sass": "^2.3.2",
4852
"gulp-sourcemaps": "^1.6.0",
4953
"gulp-stylelint": "^3.2.0",
54+
"gulp-uglify": "^2.0.0",
5055
"vinyl-buffer": "^1.0.0",
5156
"vinyl-source-stream": "^1.1.0"
5257
}

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
</head>
88
<body>
99
<div id="app"></div>
10-
<script type="text/javascript" src="js/app.js"></script>
10+
<script type="text/javascript" src="js/build.js"></script>
1111
</body>
1212
</html>

0 commit comments

Comments
 (0)