Getting reactions and scrolling to work with ES6

I have a browser task that is configured like this:

module.exports = function(grunt) {

  grunt.config.set('browserify', {
    dev: {
      src: 'assets/js/main.jsx',
      dest: '.tmp/public/js/main.js',
      options: {
        debug: true,
        extensions: ['.jsx'],
        transform: ['reactify']
      }
    }
  });

  grunt.loadNpmTasks('grunt-browserify');
};

I tried setting it up in such a way as to use es6:

module.exports = function(grunt) {

  grunt.config.set('browserify', {
    dev: {
      src: 'assets/js/main.jsx',
      dest: '.tmp/public/js/main.js',
      options: {
        debug: true,
        extensions: ['.jsx'],
        transform: ['reactify', {'es6': true}]
      }
    }
  });

  grunt.loadNpmTasks('grunt-browserify');
};

This causes an error:

Error: path must be a string

I can’t understand from the docs how to do this, given that I don’t want to configure the conversion in my package.json. Any help would be appreciated.

+4
source share
2 answers

I missed the brackets after the conversion option. It works:

module.exports = function(grunt) {

  grunt.config.set('browserify', {
    dev: {
      src: 'assets/js/main.jsx',
      dest: '.tmp/public/js/main.js',
      options: {
        debug: true,
        extensions: ['.jsx'],
        transform: [
          [ 'reactify', {'es6': true} ]
        ]
      }
    }
  });

  grunt.loadNpmTasks('grunt-browserify');
};
+4
source

Alternatively, you can also just compile ES6 modules (without Grunt / Gulp) with watchify.

In package.json add the following:

{
  "scripts": {
    "build": "watchify -o build/bundle.js -v -d assets/js/main.jsx"
  },
  "devDependencies": {
    "browserify": "^10.2.4",
    "envify": "^3.4.0",
    "reactify": "^1.1.1",
    "watchify": "^3.2.2"
  },
  "browserify": {
    "transform": [
      ["reactify", {"es6": true}],
      "envify"
    ]
  }
}

/ npm run-script build.

+1

All Articles