Skip to content

Instantly share code, notes, and snippets.

@stdavis
Last active May 18, 2018 22:59
Show Gist options
  • Select an option

  • Save stdavis/01edf8634575a74c7674be4b47736e0e to your computer and use it in GitHub Desktop.

Select an option

Save stdavis/01edf8634575a74c7674be4b47736e0e to your computer and use it in GitHub Desktop.
Implement Babel in a AGRC JS Project
  • npm i grunt-babel babel-preset-latest babel-plugin-transform-remove-strict-mode —-save-dev
  • move src/app to _src/app and other base files like index.html.
  • update .gitignore to ignore the entire src directory (yeah!)
  • add babel grunt task config to go from _src/app to src/app
babel: {
    options: {
        sourceMap: true,
        presets: ['latest'],
        plugins: ['transform-remove-strict-mode']
    },
    src: {
        files: [{
            expand: true,
            cwd: '_src/app/',
            src: ['**/*.js'],
            dest: 'src/app/'
        }]
    }
}
  • add copy task to take care of all of the non-.js files
copy: {
    dist: {
        files: [{expand: true, cwd: 'src/', src: ['*.html'], dest: 'dist/'}]
    },
    src: {
        expand: true,
        cwd: '_src',
        src: ['**/*.html', '**/*.css', '**/*.png', '**/*.jpg', 'secrets.json', 'app/package.json'],
        dest: 'src'
    }
}
  • may need to reconfigure stylus to point from _src/app to src/app
  • repoint linter, watch, bump to _src directory
  • add newer:babel & newer:copy:src tasks to watch
  • add new clean sub task to clean src/app
clean: {
    build: ['dist'],
    deploy: ['deploy'],
    src: ['src/app']
},
  • add babel/clean/copy tasks to build and default tasks
grunt.registerTask('default', [
    'eslint',
    'clean:src',
    'babel',
    'stylus:src',
    'copy:src',
    'connect',
    'jasmine:main:build',
    'watch'
]);
grunt.registerTask('build-prod', [
    'clean:src',
    'babel',
    'stylus:src',
    'copy:src',
    'newer:imagemin:main',
    'dojo:prod',
    'uglify:prod',
    'copy:dist',
    'processhtml:main'
]);
  • update eslintrc to be at the correct ecma version (no need if using eslint-config-agrc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment