@@ -241,6 +241,42 @@ module.exports = function (grunt) {
241241 } ,
242242 } ,
243243 } ,
244+ // transpile CommonJS output to broadly compatible ES5
245+ babel : {
246+ commonjs_es5 : {
247+ options : {
248+ sourceMap : false ,
249+ compact : true ,
250+ // Only keep comments that explicitly include @preserve
251+ generatorOpts : {
252+ comments : false ,
253+ shouldPrintComment : function ( val ) {
254+ return / @ p r e s e r v e / i. test ( val ) ;
255+ } ,
256+ } ,
257+ presets : [
258+ [
259+ '@babel/preset-env' ,
260+ {
261+ targets : { ie : '11' } , // broad compatibility
262+ bugfixes : true ,
263+ modules : 'commonjs' ,
264+ loose : true ,
265+ } ,
266+ ] ,
267+ ] ,
268+ } ,
269+ files : [
270+ {
271+ expand : true ,
272+ cwd : 'dist/commonjs' ,
273+ src : [ '**/*.js' ] ,
274+ dest : 'dist/commonjs' ,
275+ ext : '.js' ,
276+ } ,
277+ ] ,
278+ } ,
279+ } ,
244280 // create files to support the dist structure
245281 'file-creator' : {
246282 'package.json ES Module' : {
@@ -287,8 +323,9 @@ module.exports = function (grunt) {
287323 grunt . loadNpmTasks ( 'grunt-contrib-concat' ) ;
288324 grunt . loadNpmTasks ( 'grunt-file-creator' ) ;
289325 grunt . loadNpmTasks ( 'grunt-version' ) ;
326+ grunt . loadNpmTasks ( 'grunt-babel' ) ;
290327
291328 // Register task(s).
292- grunt . registerTask ( 'default' , [ 'clean' , 'cssmin' , 'concat' , 'file-creator' ] ) ;
293- grunt . registerTask ( 'uglifyMain' , [ 'clean' , 'cssmin' , 'concat' , 'file-creator' , 'uglify' ] ) ;
329+ grunt . registerTask ( 'default' , [ 'clean' , 'cssmin' , 'concat' , 'file-creator' , 'babel' ] ) ;
330+ grunt . registerTask ( 'uglifyMain' , [ 'clean' , 'cssmin' , 'concat' , 'file-creator' , 'babel' , ' uglify'] ) ;
294331} ;
0 commit comments