Skip to content

Commit

Permalink
Implement a separation between JS needed for Bedrock and JS needed fo…
Browse files Browse the repository at this point in the history
…r the prototype output
  • Loading branch information
Wolfr committed Jun 8, 2021
1 parent d7f8cc8 commit 901249b
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 15 deletions.
5 changes: 4 additions & 1 deletion content/js/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
import '../../core/js/index';
// Client JS
// This file just to test output, you can put your own scripts here. Scripts loaded here will be transpiled using Babel to bundle-client.js

import data from './modules/data.js';
3 changes: 3 additions & 0 deletions content/js/modules/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default [
{ name: 'John Doe' }
]
3 changes: 2 additions & 1 deletion content/templates/_layouts/master.pug
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ html(dir="ltr" lang="en" class=htmlClass ? htmlClass : '')


= "\n"
script(src='/js/bundle.js')
script(src='/js/bundle-prototype.js')
script(src='/js/bundle-client.js')

block footerScripts
// Nothing yet
4 changes: 4 additions & 0 deletions core/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ module.exports = {
},
core: {
path: corePath,
js: {
entryFile: path.join(corePath, 'js/index.js'),
allFiles: path.join(corePath, 'js/**/*.js')
},
scss: {
all: path.join(corePath, 'scss/**/*.scss'),
prototype: path.join(corePath, 'scss/prototype.scss')
Expand Down
29 changes: 19 additions & 10 deletions core/tasks/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@ const babelify = require('babelify');

const paths = require('../paths');

module.exports = function () {
return gulp.src(paths.content.js.entryFile)
.pipe(bro({
debug: true,
transform: [
babelify.configure({ presets: ['@babel/preset-env'] }),
]
}))
.pipe(rename('bundle.js'))
.pipe(gulp.dest(paths.compiled.js))
let babelConfig = {
transform: [
babelify.configure({ presets: ['@babel/preset-env'] }),
]
}

module.exports = {
clientBundle() {
return gulp.src(paths.content.js.entryFile)
.pipe(bro(babelConfig))
.pipe(rename('bundle-client.js'))
.pipe(gulp.dest(paths.compiled.js))
},
prototypeBundle() {
return gulp.src(paths.core.js.entryFile)
.pipe(bro(babelConfig))
.pipe(rename('bundle-prototype.js'))
.pipe(gulp.dest(paths.compiled.js))
}
};
4 changes: 3 additions & 1 deletion core/tasks/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ module.exports = function () {
gulp.watch(paths.content.assets.resources, gulp.series('copy:resources'));
gulp.watch(paths.content.iconFont.sourceFiles, gulp.series('icon-font'));
gulp.watch(paths.content.icons.sourceFiles, browserSync.reload());
gulp.watch(paths.content.js.allFiles, gulp.series('bundle'));
gulp.watch(paths.content.js.allFiles, gulp.series('bundle:clientBundle'));
gulp.watch(paths.core.js.allFiles, gulp.series('bundle:prototypeBundle'));

};
5 changes: 3 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ gulp.task('copy:favicon', copy.favicon);
gulp.task('copy:resources', copy.resources);
gulp.task('copy:scripts', copy.scripts);
gulp.task('copy:compiledToDist', copy.compiledToDist);
gulp.task('bundle', bundle);
gulp.task('bundle:clientBundle', bundle.clientBundle);
gulp.task('bundle:prototypeBundle', bundle.prototypeBundle);
gulp.task('icon-font', iconFont);

gulp.task('templates:compile:content', templates.compile.content);
Expand All @@ -36,7 +37,7 @@ gulp.task('templates:compile', config.styleguide ?

gulp.task('watch', watch);
gulp.task('copy', gulp.parallel('copy:images', 'copy:fonts', 'copy:resources', 'copy:scripts', 'copy:favicon'));
gulp.task('compile-all', gulp.parallel('templates:clean','icon-font', 'bundle', 'sass', 'copy'));
gulp.task('compile-all', gulp.parallel('templates:clean','icon-font', 'bundle:clientBundle', 'bundle:prototypeBundle', 'sass', 'copy'));

gulp.task('build', gulp.series('compile-all', 'templates:compile', 'copy:compiledToDist'), function (done) {
console.log('------------\n');
Expand Down

0 comments on commit 901249b

Please sign in to comment.