Add support for CommonJS modules
I agree that this would be really nice to have. Need to think about how it will work with minification/combination though. Do Cassette or ASP.NET Bundling/Minification have first-class support for modules? Need to try out different loaders and see how they play with each other.
cc @PrabirShrestha
Really interested in this one. Had any more thoughts on how it might work?
I haven't thought about it much yet. I don't think any JS combiners/minifiers for ASP.NET/C# support JavaScript modules at the moment.
One potential way of doing it is to let Webpack handle bundling and then just load the Webpack bundle in ReactJS.NET rather than individual JavaScript files like it does at the moment. This would mean Webpack would be handling the JSX compilation rather than ReactJS.NET.
Ideally it'd use ES6 module syntax rather than RequireJS/CommonJS/AMD syntax.
At the minute everything coming out from Facebook appears to be in CommonJs syntax (the Dispatcher for Flux that you released for instance) which has made me lean towards following suit for ease. Any reason why one over the other? With CommonJS you seem to be able to leverage node.js modules such as the event emitter etc. so more goodies for less effort.
All the mods you are doing all seem to be very .net tool heavy, any reason for avoiding re-using existing tools such as node.js, grunt, etc other than trying to not scare away die hard .net fans? I use .net every day but don't mind introducing a new tool if it does the job.
I have a similar use-case. My react toolchain is in place, resulting in a bundle.js file that I include through BundleConfig. If I try to add bundle.js in ReactConfig I get this error: "Error while loading "~/Scripts/browserify/dist/bundle.js": 'document' is undefined"
I guess all I want from ReactJS.Net is server-side rendering, because all my dependencies are in that bundle.
Added a Webpack example here: https://github.com/reactjs/React.NET/tree/master/src/React.Sample.Webpack. I'll also be writing a blog post about Webpack + ReactJS.NET soon. I'm going to close this task.
@PeteDuncanson:
At the minute everything coming out from Facebook appears to be in CommonJs syntax
Yeah internally we use CommonJS so generally you'll find all JavaScript libraries released by Facebook will use CommonJS syntax. Having said that, they're always usable without having to use CommonJS requires.
All the mods you are doing all seem to be very .net tool heavy, any reason for avoiding re-using existing tools such as node.js, grunt, etc
A few reasons:
- Initially ReactJS.NET only focused on the simplest use cases with as few "moving parts" as possible. My initial proof-of-concept (and indeed the very first release of ReactJS.NET) focused on using the MSIE JavaScript engine to run the JSX Transformer. This meant that almost all the code was managed .NET code and users did not need to install any additional components. Not everyone can install Node.js in their environment, so this can be beneficial.
- There's already an existing ecosystem around JavaScript minification/combination in .NET (eg. Cassette and Microsoft's ASP.NET Optimization framework). People that use .NET already have sites built using these technologies, so I wanted to be able to easily slot in there without having to change large parts of the site.
Having said that, I definitely see the benefits of using Gulp and Webpack, and they're definitely nicer in more complex scenarios. I created a simple example using Webpack and I'll see if there's ways I can improve support for Webpack and Browserify in ReactJS.NET.
@spicydonuts
I have a similar use-case. My react toolchain is in place, resulting in a bundle.js file that I include through BundleConfig. If I try to add bundle.js in ReactConfig I get this error: "Error while loading "~/Scripts/browserify/dist/bundle.js": 'document' is undefined"
I'd suggest creating a separate issue for that :). "document is undefined" means you're using document somewhere, which is not available server-side. I'd suggest creating a separate bundle with only your server-side dependencies and omitting anything that's only needed client-side.
In case someone will be looking for require.js integration example, it could be found here.
Apologies for being slightly off-topic but @Daniel15 did you ever get chance to write that blog post (ReactJS,NET & Webpack)?
I didn't write a blog post as such, but there's some documentation here: http://reactjs.net/guides/webpack.html
That's great, I'll check it out.
I had looked on the ReactJS.NET blog and your personal one but didn't think of checking out the docs, thanks.