diff --git a/gulpfile.js b/gulpfile.js index bf9dd46d..1534c561 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -18,6 +18,11 @@ var concat = require('gulp-concat'); var _ = require('lodash'); var eslint = require('gulp-eslint'); var jest = require('jest-cli'); +var argv = require('yargs').argv; +var server = require('./server.js').app; +var minifyCss = require('gulp-minify-css'); +var uglify = require('gulp-uglify'); + var config = { bootstrapDir: './node_modules/bootstrap-sass', @@ -41,11 +46,14 @@ var config = { } }; -gulp.task('build', function() { +gulp.task('build', ['js:build', 'sass:build', 'copy'], function() { +}); + +gulp.task('js:build', function() { bundle(false); }); - -gulp.task('serve', ['browser-sync', 'lint:watch', 'sass', 'sass:watch', 'copy'], function() { + +gulp.task('serve', ['browser-sync', 'run-server', 'lint:watch', 'sass:build', 'sass:watch', 'copy'], function() { bundle(true); }); @@ -59,27 +67,30 @@ gulp.task('jest:watch', function(done) { gulp.watch([ config.jestOptions.rootDir + "/**/*.js" ], [ 'jest' ]); }); +gulp.task('run-server', function() { + server.listen(4000); +}); + gulp.task('browser-sync', function() { browserSync({ - server: { - baseDir: '.' - }, - port: process.env.PORT || 3000 + files: ['build/css/*.css', 'build/js/*.js'], + proxy: 'http://localhost:4000', + port: 3000 }); }); -gulp.task('sass', function () { +gulp.task('sass:build', function () { gulp.src('./sass/**/main.scss') - .pipe(sourcemaps.init()) + .pipe(gulpif(!argv.production, sourcemaps.init())) .pipe(sass({ includePaths: [ config.bootstrapDir + '/assets/stylesheets' ] - }) - .on('error', sass.logError)) - .pipe(sourcemaps.write('./maps')) + }).on('error', sass.logError)) + .pipe(gulpif(!argv.production, sourcemaps.write('./maps'))) + .pipe(gulpif(argv.production, minifyCss())) .pipe(gulp.dest('./build/css')) - .pipe(browserSync.stream());; + .pipe(browserSync.stream()); }); gulp.task('sass:watch', function () { @@ -87,13 +98,13 @@ gulp.task('sass:watch', function () { }); gulp.task('copy', function () { - var files = [ + var staticAssets = [ './fonts/**/*', './img/**/*' ]; - gulp.src(files, {base: './'}) - .pipe(gulp.dest('build')); + gulp.src(staticAssets, {base: './'}) + .pipe(gulp.dest('./build')); gulp.src(config.bootstrapDir + '/assets/fonts/**/*') .pipe(gulp.dest('./build/fonts')); @@ -117,6 +128,7 @@ gulp.task('lint:watch', function () { function bundle(watch) { var bro; + if (watch) { bro = watchify(browserify('./js/app.js', // Assigning debug to have sourcemaps @@ -141,13 +153,14 @@ function bundle(watch) { .on('error', notify.onError('Error: <%= error.message %>')) .pipe(source('app.js')) .pipe(buffer()) - .pipe(sourcemaps.init({ + .pipe(gulpif(!argv.production, sourcemaps.init({ loadMaps: true - })) // loads map from browserify file - .pipe(sourcemaps.write()) // writes .map file - .pipe(gulp.dest('./build')) + }))) // loads map from browserify file + .pipe(gulpif(!argv.production, sourcemaps.write())) // writes .map file + .pipe(gulpif(argv.production, uglify({mangle: false}))) + .pipe(gulp.dest('./build/js')) .pipe(browserSync.stream()); } return rebundle(bro); -} \ No newline at end of file +} diff --git a/index.html b/index.html index e30f8d54..852f9027 100644 --- a/index.html +++ b/index.html @@ -6,10 +6,10 @@ ascribe - +
- + diff --git a/js/app.js b/js/app.js index d1215fa3..af92c379 100644 --- a/js/app.js +++ b/js/app.js @@ -26,7 +26,7 @@ fetch.defaults({ } }); -Router.run(routes, Router.HashLocation, (AscribeApp) => { +Router.run(routes, Router.HistoryLocation, (AscribeApp) => { React.render( , document.getElementById('main') diff --git a/js/components/ascribe_media/media_player.js b/js/components/ascribe_media/media_player.js index 55188568..b0002de0 100644 --- a/js/components/ascribe_media/media_player.js +++ b/js/components/ascribe_media/media_player.js @@ -46,8 +46,8 @@ let Image = React.createClass({ this.inject('http://code.jquery.com/jquery-2.1.4.min.js') .then(() => Promise.all([ - this.inject('node_modules/shmui/shmui.css'), - this.inject('node_modules/shmui/jquery.shmui.js') + this.inject('/static/thirdparty/shmui/shmui.css'), + this.inject('/static/thirdparty/shmui/jquery.shmui.js') ]).then(() => { window.jQuery('.shmui-ascribe').shmui(); })); }, diff --git a/js/components/header.js b/js/components/header.js index d46dd4b2..3df56afb 100644 --- a/js/components/header.js +++ b/js/components/header.js @@ -38,7 +38,7 @@ let Header = React.createClass({ return (