import path from 'path'; import { dest, series } from 'gulp'; import babelify from 'babelify'; import browserify from 'browserify'; import source from 'vinyl-source-stream'; import buffer from 'vinyl-buffer'; import concat from 'gulp-concat'; const PROJECT_DIR = path.join('src', 'newsreader'); const SRC_DIR = path.join(PROJECT_DIR, 'js'); const STATIC_SUFFIX = 'dist/js/'; const CORE_DIR = path.join(PROJECT_DIR, 'news', 'core', 'static', 'core'); const taskMappings = [ { name: 'homepage', destDir: `${CORE_DIR}/${STATIC_SUFFIX}` }, { name: 'categories', destDir: `${CORE_DIR}/${STATIC_SUFFIX}` }, ]; const babelTask = done => { const tasks = taskMappings.map(taskMapping => { const { name, destDir } = taskMapping; const bundle = browserify({ entries: `${SRC_DIR}/pages/${name}/index.js`, debug: true, }); const transpiledBundle = bundle.transform(babelify); return () => transpiledBundle .bundle() .pipe(source('index.js')) .pipe(buffer()) .pipe(concat(`${name}.js`)) .pipe(dest(destDir)); }); return series(...tasks)(done); }; export default babelTask;