Reputation: 5530
I am trying to use Grunt-browserify and reactify to parse and bundle React components written in jsx. I want to use the extension flag so that I don't have have to specify the file extension name of my modules, but I have been unable to get this to work. Here is some test code:
A Gruntfile:
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
browserify: {
dev: {
src: 'src/app.jsx',
dest: 'dest/app.js',
options: {
debug: true,
transform: ['reactify'],
extensions: ['.jsx']
}
}
}
});
grunt.loadNpmTasks('grunt-browserify');
grunt.registerTask('default', ['browserify:dev']);
};
The main app file app.jsx
:
'use strict';
var React = require('react');
var Test = require('./components/Test'); // Here is the problem...
React.render(
<Test />,
document.getElementById('test')
);
And then Test.jsx
:
'use strict';
var React = require('react');
var Test = React.createClass({
render: function() {
return(
<div>
<p>Some markup</p>
</div>
);
}
});
module.exports = Test;
When I try to compile this by running grunt
, I get an error:
Error: Cannot find module './components/Test' from '/Users/****/Sites/grunt-test/src'
The Grunt-browserify documentation says that it has supported the extensions flag since v1.2.6 and I have seen examples of this all over the web, but I can't seem to get it to work here. If I run browserify from the command line -- like so browserify -t reactify --extension=.jsx -o dest/app.js
-- it works.
Any ideas?
Upvotes: 1
Views: 1083
Reputation: 101
Have you tried moving the properties inside browserifyOptions as follow?
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
browserify: {
dev: {
src: 'src/app.jsx',
dest: 'dest/app.js',
options: {
browserifyOptions: {
debug: true,
transform: ['reactify'],
extensions: ['.jsx']
}
}
}
}
});
Upvotes: 10