Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions site/jekyll/getting-started/aspnet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
id: aspnet
layout: docs
title: Getting Started on ASP.NET
---

This guide covers enabling server-side rendering and Babel compilation. If you want a step-by-step guide on configuring a brand new site, see [the ReactJS.NET tutorial for ASP.NET](/getting-started/tutorial_aspnet4.html).

ReactJS.NET requires Visual Studio 2015 and MVC 4 or 5.

Install the `React.Web.Mvc4` package through NuGet. You will also need to install a JS engine to use (either V8 or ChakraCore are recommended). See the [JSEngineSwitcher docs](https://github.com/Taritsyn/JavaScriptEngineSwitcher/wiki/Registration-of-JS-engines) for more information.

To use V8, add the following packages:

```
JavaScriptEngineSwitcher.V8
JavaScriptEngineSwitcher.V8.Native.win-x64
```

`ReactConfig.cs` will be automatically generated for you. Update it to register a JS engine and your JSX files:

```csharp
using JavaScriptEngineSwitcher.Core;
using JavaScriptEngineSwitcher.V8;

[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(React.Sample.Mvc4.ReactConfig), "Configure")]

namespace React.Sample.Mvc4
{
public static class ReactConfig
{
public static void Configure()
{
ReactSiteConfiguration.Configuration
.AddScript("~/Content/Sample.jsx");

JsEngineSwitcher.Current.DefaultEngineName = V8JsEngine.EngineName;
JsEngineSwitcher.Current.EngineFactories.AddV8();
}
}
}
```

Reference JSX files directly in script tags:

```html
<script src="~/Content/Sample.jsx"></script>
```

You're done! You can now call `Html.React` from within Razor files:

```
@Html.React("Sample", new { initialComments = Model.Comments, page = Model.Page })
```

You can also use [webpack](/guides/webpack.html) or [System.Web.Optimization](/guides/weboptimizer.html) to bundle your scripts together.

Check out the [sample project](https://github.com/reactjs/React.NET/tree/master/src/React.Sample.Mvc4) for a working demo.
26 changes: 23 additions & 3 deletions site/jekyll/getting-started/aspnetcore.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ layout: docs
title: Getting Started on ASP.NET Core
---

Getting started with ReactJS.NET on ASP.NET Core requires a few more steps compared to previous versions of ASP.NET and MVC. If you want a step-by-step guide on configuring a brand new site, see [the ReactJS.NET tutorial for ASP.NET Core](/getting-started/tutorial.html).
This guide covers enabling server-side rendering and Babel compilation. Getting started with ReactJS.NET on ASP.NET Core requires a few more steps compared to previous versions of ASP.NET and MVC. If you want a step-by-step guide on configuring a brand new site, see [the ReactJS.NET tutorial for ASP.NET Core](/getting-started/tutorial.html).

ReactJS.NET requires Visual Studio 2015 and ASP.NET Core RTM (final release). It is recommended to use .NET Framework, but ReactJS.NET also works with .NET Core.

Install the `React.AspNet` package through NuGet. After the package is installed, ReactJS.NET needs to be initialised in your `Startup.cs` file (unfortunately this can not be done automatically like in previous versions of ASP.NET with WebActivator). At the top of the file, add:
Install the `React.AspNet` package through NuGet. You will also need to install a JS engine to use (either V8 or ChakraCore are recommended). See the [JSEngineSwitcher docs](https://github.com/Taritsyn/JavaScriptEngineSwitcher/wiki/Registration-of-JS-engines) for more information. After these packages are installed, ReactJS.NET needs to be initialised in your `Startup.cs` file (unfortunately this can not be done automatically like in previous versions of ASP.NET with WebActivator).

At the top of Startup.cs, add:

```
using Microsoft.AspNetCore.Http;
using JavaScriptEngineSwitcher.Core;
using JavaScriptEngineSwitcher.ChakraCore;
using React.AspNet;
```

Expand All @@ -27,6 +31,10 @@ Add:
```csharp
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddReact();

// Make sure a JS engine is registered, or you will get an error!
services.AddJsEngineSwitcher(options => options.DefaultEngineName = ChakraCoreJsEngine.EngineName)
.AddChakraCore();
```


Expand Down Expand Up @@ -66,6 +74,18 @@ Finally, add this to `Views\_ViewImports.cshtml` (or create it if it doesn't exi
@using React.AspNet
```

Once ReactJS.NET has been configured, you will be able to use [on-the-fly JSX to JavaScript compilation](/getting-started/usage.html) and [server-side rendering](/guides/server-side-rendering.html).
Reference JSX files directly in script tags:

```html
<script src="~/Content/Sample.jsx"></script>
```

You're done! You can now call `Html.React` from within Razor files:

```
@Html.React("Sample", new { initialComments = Model.Comments, page = Model.Page })
```

If you need support for non-Windows platforms, please see the [ChakraCore guide](/guides/chakracore.html).

Check out the [sample project](https://github.com/reactjs/React.NET/tree/master/src/React.Sample.CoreMvc) for a working demo.
6 changes: 3 additions & 3 deletions site/jekyll/getting-started/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,15 @@ If you see this, congratulations! You've just built your first React component.
The first thing you'll notice is the XML-ish syntax in your JavaScript. We have a simple precompiler that translates the syntactic sugar to this plain JavaScript:

```javascript
var CommentBox = React.createClass({displayName: 'CommentBox',
render: function() {
class CommentBox extends React.Component {
render() {
return (
React.createElement('div', {className: "commentBox"},
"Hello, world! I am a CommentBox."
)
);
}
});
};

ReactDOM.render(
React.createElement(CommentBox, null),
Expand Down
6 changes: 3 additions & 3 deletions site/jekyll/getting-started/tutorial_aspnet4.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ If you see this, congratulations! You've just built your first React component.
The first thing you'll notice is the XML-ish syntax in your JavaScript. We have a simple precompiler that translates the syntactic sugar to this plain JavaScript:

```javascript
var CommentBox = React.createClass({displayName: 'CommentBox',
render: function() {
class CommentBox extends React.Component {
render() {
return (
React.createElement('div', {className: "commentBox"},
"Hello, world! I am a CommentBox."
)
);
}
});
};

ReactDOM.render(
React.createElement(CommentBox, null),
Expand Down
6 changes: 3 additions & 3 deletions site/jekyll/getting-started/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ Once installed, create your React components as usual.

```javascript
// /Scripts/HelloWorld.jsx
var HelloWorld = React.createClass({
render: function () {
class HelloWorld extends React.Component {
render() {
return (
<div>Hello {this.props.name}</div>
);
}
});
}
```

On-the-Fly JSX to JavaScript Compilation
Expand Down
43 changes: 0 additions & 43 deletions site/jekyll/guides/azure.md

This file was deleted.

4 changes: 2 additions & 2 deletions site/jekyll/guides/es6.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ var OldAndBusted = React.createClass({
});

// The new way
var NewHotness = React.createClass({
class NewHotness extends React.Component {
render() {
// ...
},
doStuff() {
// ...
}
});
};
```

* **[Classes](http://wiki.ecmascript.org/doku.php?id=strawman:maximally_minimal_classes)** &mdash; Similar to the class systems included in JavaScript frameworks such as Prototype and MooTools, but will (eventually) be native to JavaScript
Expand Down
27 changes: 2 additions & 25 deletions site/jekyll/guides/mono.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,8 @@ layout: docs
title: Linux (Mono)
---

ReactJS.NET includes full support for Mono via Google's [V8 JavaScript engine](https://code.google.com/p/v8/), the same engine used by Google Chrome and Node.js. To use ReactJS.NET with Mono, you need to compile V8 and VroomJs (a .NET wrapper around V8). This can be accomplished by running the following shell commands on your Linux or Mac OS X machine:
While Mono is supported, we strongly recommend using .NET Core instead.

```sh
# Get a supported version of V8
cd /usr/local/src/
git clone https://github.com/v8/v8.git v8-3.17
cd v8-3.17
git checkout tags/3.17.16.2

# Build V8
make dependencies
make native werror=no library=shared soname_version=3.17.16.2 -j4
cp out/native/lib.target/libv8.so.3.17.16.2 /usr/local/lib/

# Get ReactJS.NET's version of libvroomjs
cd /usr/local/src/
git clone https://github.com/reactjs/react.net.git
cd react.net
git submodule update --init
cd lib/VroomJs/libvroomjs/

# Build libvroomjs
g++ jscontext.cpp jsengine.cpp managedref.cpp bridge.cpp jsscript.cpp -o libVroomJsNative.so -shared -L /usr/local/src/v8-3.17/out/native/lib.target/ -I /usr/local/src/v8-3.17/include/ -fPIC -Wl,--no-as-needed -l:/usr/local/lib/libv8.so.3.17.16.2
cp libVroomJsNative.so /usr/local/lib/
ldconfig
```
ReactJS.NET includes full support for Mono via Google's [V8 JavaScript engine](https://code.google.com/p/v8/), the same engine used by Google Chrome and Node.js. To use ReactJS.NET with Mono, follow the documentation on the [JavaScriptEngineSwitcher repo](https://github.com/Taritsyn/JavaScriptEngineSwitcher/wiki/JS-Engine-Switcher:-Vroom) to build Vroom, and then register the JS Engine as the default in `Startup.cs`. For example on how to do this, see the [ChakraCore guide](/guides/chakracore.html).

If VroomJs fails to load, you will see an exception when your application is started. If this happens, run Mono with the `MONO_LOG_LEVEL=debug` environment variable to get more useful debugging information. Often, this occurs when Mono is unable to locate V8 (ie. it's not in /usr/lib/ or /usr/local/lib/)
2 changes: 2 additions & 0 deletions site/jekyll/guides/webpack.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ layout: docs
title: Webpack
---

This guide is for Webpack 1. To see the latest example for how to use webpack, check out the [sample project](https://github.com/reactjs/React.NET/tree/master/src/React.Sample.Webpack).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should upgrade this guide one day.


[Webpack](http://webpack.github.io/docs/what-is-webpack.html) is a popular module bundling system built on top of Node.js. It can handle not only combination and minification of JavaScript and CSS files, but also other assets such as image files (spriting) through the use of plugins. Webpack can be used as an alternative to Cassette or ASP.NET Combination and Minification. This guide assumes you have already [installed Webpack](http://webpack.github.io/docs/installation.html).

In order to use Webpack with ReactJS.NET's server-side rendering, it is suggested that you create a separate bundle ("[entry point](http://webpack.github.io/docs/multiple-entry-points.html)") containing *only* the code required to perform server-side rendering. Any components you would like to render server-side must be exposed globally so that ReactJS.NET can access them. This can be done through the [Webpack expose loader](https://github.com/webpack/expose-loader):
Expand Down
4 changes: 2 additions & 2 deletions site/jekyll/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ id: home

```javascript
// /Scripts/HelloWorld.jsx
var HelloWorld = React.createClass({
class HelloWorld extends React.Component {
render: function() {
return <div>Hello world!</div>;
}
});
}
```
```html
<!-- Reference it from HTML -->
Expand Down
2 changes: 1 addition & 1 deletion src/Cassette.React/BabelBundleProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (c) 2014-Present, Facebook, Inc.
* All rights reserved.
*
Expand Down
1 change: 1 addition & 0 deletions src/Cassette.React/Cassette.React.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

<ItemGroup>
<PackageReference Include="Cassette" Version="2.4.2" />
<PackageReference Include="JavaScriptEngineSwitcher.Msie" Version="3.0.0-beta5" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net40' ">
Expand Down
9 changes: 6 additions & 3 deletions src/Cassette.React/CassetteMSBuildStartup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (c) 2014-Present, Facebook, Inc.
* All rights reserved.
*
Expand All @@ -7,8 +7,8 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

using System;
using System.Diagnostics;
using JavaScriptEngineSwitcher.Core;
using JavaScriptEngineSwitcher.Msie;
using React;

namespace Cassette.React
Expand All @@ -31,6 +31,9 @@ public void Start()
return;
}

JsEngineSwitcher.Current.DefaultEngineName = MsieJsEngine.EngineName;
JsEngineSwitcher.Current.EngineFactories.AddMsie();

// All "per-request" registrations should be singletons in MSBuild, since there's no
// such thing as a "request"
Initializer.Initialize(requestLifetimeRegistration: registration => registration.AsSingleton());
Expand Down
51 changes: 0 additions & 51 deletions src/React.Core/Exceptions/ClearScriptV8InitialisationException.cs

This file was deleted.

Loading