From bf664365ef80b31b418abdb54214c4b6173a73d2 Mon Sep 17 00:00:00 2001 From: Ben Brehaut Date: Tue, 5 Sep 2017 22:54:03 +0100 Subject: [PATCH] Added babel to gulp --- README.md | 2 ++ gulpfile.js | 4 ++++ package.json | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 2b49d98..c5e63be 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,8 @@ All Sass files are located within ``/assets/scss``, with the ``style.scss`` outp ###### Default task All JavaScript files are located with ``/assets/js``, the ``scripts.js`` file is the main Javascript file for the theme, with external third party libraries within the ``vendor`` folder. All files within this will be concatenated into the ``dist/main.js`` file and ``dist/main.min.js`` +The scripts task will also run the main JavaScript file through Babel, which means you can use all the new ES2015, ES2016 etc. features without fear of them not working in some older browsers! + * ``/assets/js/scripts.js`` is the main JavaScript file. This is where you should write all of your JavaScript. * ``/assets/js/dist/main.js`` is the uncompressed and concatenated JavaScript file from all of the files within the ``/assets/js/vendor/*.js`` folder and ``/assets/js/scripts.js`` file. * ``/assets/js/dist/main.min.js`` is our compressed version of the ``/assets/js/dist/main.js`` file. diff --git a/gulpfile.js b/gulpfile.js index 0a7e01e..e250909 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -14,6 +14,7 @@ var imagemin = require('gulp-imagemin'); var prefix = require('gulp-autoprefixer'); var svgstore = require('gulp-svgstore'); var sourcemaps = require('gulp-sourcemaps'); +var babel = require('gulp-babel'); /** * @function variables @@ -50,6 +51,9 @@ var autoprefixerOptions = { */ gulp.task('scripts', function () { return gulp.src([jsFiles, mainJSFile]) + .pipe(babel({ + presets: ['env'] + })) .pipe(plumber()) .pipe(concat(outputJSFile)) // output main JavaScript file without uglify .pipe(gulp.dest(outputJSFileLocation)) diff --git a/package.json b/package.json index feed512..4e7ad5d 100644 --- a/package.json +++ b/package.json @@ -24,9 +24,13 @@ "author": "Ben Brehaut", "license": "MIT", "devDependencies": { + "babel-core": "^6.26.0", + "babel-loader": "^7.1.2", + "babel-preset-env": "^1.6.0", "browser-sync": "^2.18.12", "gulp": "^3.8.8", "gulp-autoprefixer": "4.0.0", + "gulp-babel": "^7.0.0", "gulp-clean-css": "^3.6.0", "gulp-concat": "^2.6.1", "gulp-imagemin": "^3.3.0",