Skip to content

Commit 901249b

Browse files
committed
Implement a separation between JS needed for Bedrock and JS needed for the prototype output
1 parent d7f8cc8 commit 901249b

File tree

7 files changed

+38
-15
lines changed

7 files changed

+38
-15
lines changed

content/js/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
import '../../core/js/index';
1+
// Client JS
2+
// 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
3+
4+
import data from './modules/data.js';

content/js/modules/data.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default [
2+
{ name: 'John Doe' }
3+
]

content/templates/_layouts/master.pug

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ html(dir="ltr" lang="en" class=htmlClass ? htmlClass : '')
4545

4646

4747
= "\n"
48-
script(src='/js/bundle.js')
48+
script(src='/js/bundle-prototype.js')
49+
script(src='/js/bundle-client.js')
4950

5051
block footerScripts
5152
// Nothing yet

core/paths.js

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ module.exports = {
5454
},
5555
core: {
5656
path: corePath,
57+
js: {
58+
entryFile: path.join(corePath, 'js/index.js'),
59+
allFiles: path.join(corePath, 'js/**/*.js')
60+
},
5761
scss: {
5862
all: path.join(corePath, 'scss/**/*.scss'),
5963
prototype: path.join(corePath, 'scss/prototype.scss')

core/tasks/bundle.js

+19-10
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,23 @@ const babelify = require('babelify');
55

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

8-
module.exports = function () {
9-
return gulp.src(paths.content.js.entryFile)
10-
.pipe(bro({
11-
debug: true,
12-
transform: [
13-
babelify.configure({ presets: ['@babel/preset-env'] }),
14-
]
15-
}))
16-
.pipe(rename('bundle.js'))
17-
.pipe(gulp.dest(paths.compiled.js))
8+
let babelConfig = {
9+
transform: [
10+
babelify.configure({ presets: ['@babel/preset-env'] }),
11+
]
12+
}
13+
14+
module.exports = {
15+
clientBundle() {
16+
return gulp.src(paths.content.js.entryFile)
17+
.pipe(bro(babelConfig))
18+
.pipe(rename('bundle-client.js'))
19+
.pipe(gulp.dest(paths.compiled.js))
20+
},
21+
prototypeBundle() {
22+
return gulp.src(paths.core.js.entryFile)
23+
.pipe(bro(babelConfig))
24+
.pipe(rename('bundle-prototype.js'))
25+
.pipe(gulp.dest(paths.compiled.js))
26+
}
1827
};

core/tasks/watch.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ module.exports = function () {
1212
gulp.watch(paths.content.assets.resources, gulp.series('copy:resources'));
1313
gulp.watch(paths.content.iconFont.sourceFiles, gulp.series('icon-font'));
1414
gulp.watch(paths.content.icons.sourceFiles, browserSync.reload());
15-
gulp.watch(paths.content.js.allFiles, gulp.series('bundle'));
15+
gulp.watch(paths.content.js.allFiles, gulp.series('bundle:clientBundle'));
16+
gulp.watch(paths.core.js.allFiles, gulp.series('bundle:prototypeBundle'));
17+
1618
};

gulpfile.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ gulp.task('copy:favicon', copy.favicon);
2222
gulp.task('copy:resources', copy.resources);
2323
gulp.task('copy:scripts', copy.scripts);
2424
gulp.task('copy:compiledToDist', copy.compiledToDist);
25-
gulp.task('bundle', bundle);
25+
gulp.task('bundle:clientBundle', bundle.clientBundle);
26+
gulp.task('bundle:prototypeBundle', bundle.prototypeBundle);
2627
gulp.task('icon-font', iconFont);
2728

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

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

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

0 commit comments

Comments
 (0)