Skip to content

Commit cbfc65a

Browse files
committed
Add Babel to build process (close snowplow#665)
1 parent 8513a28 commit cbfc65a

3 files changed

Lines changed: 40 additions & 9 deletions

File tree

.babelrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"presets": [["@babel/preset-env", {
3+
"targets": {
4+
"chrome": 32,
5+
"ie": 9,
6+
"firefox": 27,
7+
"safari": 8
8+
}
9+
}]]
10+
}

Gruntfile.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,23 @@ module.exports = function(grunt) {
8989
files: {
9090
'tests/pages/helpers.js': ['tests/scripts/helpers.js'],
9191
'tests/pages/detectors.js': ['tests/scripts/detectors.js'],
92-
'tests/pages/snowplow.js': ['src/js/init.js']
92+
'tests/pages/bundle.js': ['src/js/init.js']
93+
}
94+
}
95+
},
96+
97+
babel: {
98+
options: {
99+
presets: ['@babel/preset-env']
100+
},
101+
dist: {
102+
files: {
103+
'dist/bundle-postbabel.js': 'dist/bundle.js'
104+
}
105+
},
106+
test: {
107+
files: {
108+
'tests/pages/snowplow.js': 'tests/pages/bundle.js'
93109
}
94110
}
95111
},
@@ -101,7 +117,7 @@ module.exports = function(grunt) {
101117
'banner': '<%= banner %>',
102118
'process': true
103119
},
104-
src: ['dist/bundle.js'],
120+
src: ['dist/bundle-postbabel.js'],
105121
dest: 'dist/snowplow.js'
106122
},
107123
tag: {
@@ -175,6 +191,7 @@ module.exports = function(grunt) {
175191
grunt.loadNpmTasks('grunt-browserify');
176192
grunt.loadNpmTasks('intern');
177193
grunt.loadNpmTasks('grunt-contrib-uglify');
194+
grunt.loadNpmTasks('grunt-babel');
178195

179196
grunt.registerTask('upload_setup', 'Read aws.json and configure upload tasks', function() {
180197
var aws = grunt.file.readJSON('aws.json');
@@ -242,11 +259,11 @@ module.exports = function(grunt) {
242259
});
243260
});
244261

245-
grunt.registerTask('default', 'Build Browserify, add banner, and minify', ['browserify:main', 'concat:deploy', 'uglify:deploy']);
246-
grunt.registerTask('publish', 'Upload to S3 and invalidate Cloudfront (full semantic version only)', ['upload_setup', 'browserify:main', 'concat:deploy', 'uglify:deploy', 's3:not_pinned', 'cloudfront:not_pinned']);
247-
grunt.registerTask('publish-pinned', 'Upload to S3 and invalidate Cloudfront (full semantic version and semantic major version)', ['upload_setup', 'browserify:main', 'concat:deploy', 'uglify:deploy', 's3', 'cloudfront']);
248-
grunt.registerTask('quick', 'Build snowplow.js, skipping building and minifying', ['browserify:main', 'concat:deploy']);
249-
grunt.registerTask('test', 'Intern tests', ['browserify:test', 'intern']);
250-
grunt.registerTask('travis', 'Intern tests for Travis CI', ['concat:test', 'browserify:test', 'intern']);
262+
grunt.registerTask('default', 'Build Browserify, add banner, and minify', ['browserify:main', 'babel:dist', 'concat:deploy', 'uglify:deploy']);
263+
grunt.registerTask('publish', 'Upload to S3 and invalidate Cloudfront (full semantic version only)', ['upload_setup', 'browserify:main', 'babel:dist', 'concat:deploy', 'uglify:deploy', 's3:not_pinned', 'cloudfront:not_pinned']);
264+
grunt.registerTask('publish-pinned', 'Upload to S3 and invalidate Cloudfront (full semantic version and semantic major version)', ['upload_setup', 'browserify:main', 'babel:dist', 'concat:deploy', 'uglify:deploy', 's3', 'cloudfront']);
265+
grunt.registerTask('quick', 'Build snowplow.js, skipping building and minifying', ['browserify:main', 'babel:dist', 'concat:deploy']);
266+
grunt.registerTask('test', 'Intern tests', ['browserify:test', 'babel:test', 'intern']);
267+
grunt.registerTask('travis', 'Intern tests for Travis CI', ['concat:test', 'browserify:test', 'babel:test', 'intern']);
251268
grunt.registerTask('tags', 'Minifiy the Snowplow invocation tag', ['uglify:tag', 'concat:tag']);
252269
};

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
"sha1": "git://github.com/pvorb/node-sha1.git#910081c83f3661507d9d89e66e3f38d8b59d5559"
1111
},
1212
"devDependencies": {
13+
"@babel/core": "^7.1.2",
14+
"@babel/preset-env": "^7.1.0",
1315
"JSON": "1.0.0",
16+
"babel-cli": "^6.26.0",
1417
"grunt": "0.4.5",
1518
"grunt-aws": "0.6.2",
16-
"grunt-browserify": "5.0.0",
19+
"grunt-babel": "^8.0.0",
20+
"grunt-browserify": "^5.0.0",
1721
"grunt-contrib-concat": "0.5.1",
1822
"lodash": "^4.17.11",
1923
"grunt-contrib-uglify": "^4.0.0",

0 commit comments

Comments
 (0)