Comments (6)
webpack config creates 2 versions of this: app.js and app.server.js
The server rendered one is included in server/config/routes.js
on the server side. This takes the HTML of app/base.html
, which includes the client-rendered app.js in a script tag.
from reactgo.
Oh ok, looks like the export
function is necessary for Webpack to pick it up properly-- I'm guessing it is translated to one of these strange lines like this exports['default'] = UniversalRenderer;
which is somehow used in app.server? I was just used to every export
of a file be complemented by an import
in another file to actually use it.
from reactgo.
@gsccheng Yep!
Webpack bundles the entire App, and because I'm exporting it as a function, we supply it arguments to be used here
// Import the webpack emitted bundle
var App = require('../../public/assets/app.server');
// ...
// Passing in data to bootstrap our alt Stores and url for react-router
var html = App(JSON.stringify(res.locals.data || {}), req.url);
Hope that helps.
from reactgo.
Thanks guys for your quick responses and concern! It truly feels good to know that there are people there to help, especially when you may be a bit shy broadcasting out into the world, and tackling something complicated (at least for me).
@choonkending What I meant was more about the export of universalRenderer(alt, routes, html);
in app/app.js
, (not the export of ../../public/assets/app.server
). Nothing seemed to explicitly import
that app/app.js
file. Yet, this is okay because Webpack still bundled it and universalRenderer(alt, routes, html);
is still used.
It looks like it is because in webpack.config.js
we have this section
name: "server-side rendering",
context: path.join(__dirname, "app"),
entry: {
app: "./app",
header: "./elements/Header.react"
},
target: "node",
output: {
// The output directory as absolute path
path: assetsPath,
// The filename of the entry chunk as relative path inside the output.path directory
filename: "[name].server.js",
that essentially imports it, specifically through app: "./app",
. There's also the equivalent section in this config file to produce the app.js
output for the client side. Is this correct?
from reactgo.
@gsccheng Spot on! :)
from reactgo.
@gsccheng I'm closing this issue. If you have any questions, feel free to open another one or join our Gitter room!
from reactgo.
Related Issues (20)
- webpack config file preload all different environment configs.
- Failed to serialize user into session when using MYSQL with Node and Passport. URGENT
- Easy deployment question HOT 4
- Postgres DB on port other than 5432 HOT 2
- New release / update changelog and publish to npm
- Remove usage of css @apply HOT 2
- Consider bundle size limits for vendor packages
- Close / Update old / rotten PRs
- Update all npm packages HOT 2
- Please re-install nodemon HOT 1
- Use hooks HOT 2
- Consider using easy-peasy on top of Redux HOT 1
- Do not bundle server application (Using Node.JS v. 9 with modules support) HOT 1
- [QUESTION] Where I can find the CI service? HOT 2
- Signup error when using CORS HOT 2
- Introducing immer
- Introducting TypeScript
- postcss-cssnext deprecated HOT 1
- Use react-router v5
- leadme 한글 공식문서 링크
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reactgo.