question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Babel and grunt-watch

See original GitHub issue

Hello!

I’ve got a project that uses connect -> watch -> babel in the dev environment. When I first run grunt server, it transpiles the es6->js successfully.

The watch works in that it sees changes to the es6 file and runs the babel tasks. The js file changes somehow, because grunt sees a change and refreshes the page with livereload, but the changes to the es6 file are not reflected in the js file.

My inexperienced assumption is that the js file is being rewritten, but without the new changes to the es6 file. Any thoughts?

A truncated copy of my gruntfile:

grunt.registerTask('server', [
    'sass',
    'babel',
    'connect:server',
    'watch'
]);

grunt.initConfig({
    babel: {
        options: {
            sourceMap: true
        },
        all: {
            files: [{
                expand: true,
                cwd: 'dev/js/site',
                src: ['**/*.es6'],
                dest: 'dev/js/site',
                ext: '.js'
            }]
        }
    },
    watch: {
        livereload: {
            options: { livereload: true },
            files: ['dev/css/*.css', 'dev/js/site/*.js', 'dev/**/*.html']
        },
        sass: {
            files: 'dev/scss/*.scss',
            tasks: ['sass']
        },
        babel: {
            files: 'dev/js/site/*.es6',
            tasks: ['babel']
        }
    },
    connect: {
        server: {
            options: {
                port: 8888,
                hostname: '*',
                livereload: true,
                open: true,
                base: 'dev'
            }
        }
    }
}

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
joshbrotoncommented, Feb 19, 2015

Yep. You’re right. I had to specify the specific babel task in the watch. Odd, but works for me. Thanks!

babel: {
    files: 'dev/js/site/*.es6',
    tasks: ['babel:dev']
}
0reactions
koshuangcommented, Jun 26, 2015

Thanks @mmahalwy, it works!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Implementing Babel via Grunt - Utah GIS
Add the new babel and copy tasks to the watch task config. Using grunt-newer will make things more efficient.
Read more >
Using Babel + grunt to work with ES6 - how to transform ...
I am already using babel, see the line grunt.registerTask('default', ['babel', 'jshint', 'concat', 'uglify']) in the gruntfile. Do ...
Read more >
How use Babel with Grunt - The freeCodeCamp Forum
Hi, I have this warning: warning: Task "babel" not found. ... OK + sass Registering "grunt-contrib-watch" local Npm module tasks.
Read more >
ECMAScript 6 Development Today with Babel and Grunt
It's a transpiler that can turn new syntax of ES6 to an ES5 construct that ... You can start the task by typing...
Read more >
grunt-babel - npm
Use next generation JavaScript, today. Latest version: 8.0.0, last published: 4 years ago. Start using grunt-babel in your project by ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found