Skip to content

Commit fd2b59e

Browse files
Docs: Update webpack page with better babel config and server-render details
1 parent 4799b88 commit fd2b59e

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

site/jekyll/bundling/webpack.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,28 @@ This configuration uses two entry points (`Content/server.js` for the server sid
6060

6161
Our configuration also requires installation of the "babel" loader:
6262

63-
```
63+
```sh
6464
npm install --save-dev babel-loader
6565
```
6666

67-
You will also need a `.babelrc` in the root of your project:
67+
You will also need a `.babelrc` in the root of your project, with at least preset-react and preset-env enabled. Note that the plugins and presets need to be separately installed via `npm install --save-dev`.
6868

69-
```
69+
```json
7070
{
71-
"presets": ["react", "env"]
71+
"presets": ["@babel/preset-react", "@babel/preset-env"],
72+
"plugins": [
73+
"@babel/proposal-object-rest-spread",
74+
"@babel/plugin-syntax-dynamic-import",
75+
"@babel/proposal-class-properties"
76+
]
7277
}
7378
```
7479

7580
Once Webpack has been configured, run `webpack` to build the bundles. Once you have verified that the bundle is being created correctly, you can modify your ReactJS.NET configuration (normally `App_Start\ReactConfig.cs`) to load the newly-created bundle:
7681

7782
```csharp
7883
ReactSiteConfiguration.Configuration
79-
.AddScript("~/build/server.bundle.js");
84+
.AddScriptWithoutTransform("~/wwwroot/server.bundle.js");
8085
```
8186

8287
This will load all your components into the `Components` global, which can be used from `Html.React` to render any of the components:
@@ -87,6 +92,13 @@ This will load all your components into the `Components` global, which can be us
8792
})
8893
```
8994

95+
Reference the built bundle directly in a script tag at the end of the page:
96+
97+
```html
98+
<script src="~/client.bundle.js"></script>
99+
@Html.ReactInitJavaScript();
100+
```
101+
90102
A full example is available in [the ReactJS.NET repository](https://github.com/reactjs/React.NET/tree/master/src/React.Sample.Webpack.CoreMvc).
91103

92104
### Migrating from expose-loader

0 commit comments

Comments
 (0)