isomorphic-javascript

Caching with Webpack, [hash] value inside index source code, using React.js

点点圈 提交于 2020-01-12 03:55:11
问题 I'm building an isomorphic application. It is completely built with react -- namely, the html base is also in react. I have my root html as an app component. It looks something like this: ... var AppTemplate = React.createClass({ displayName: 'AppTemplate', render: function() { return ( <html> <head lang="en"> <title>hello</title> <link rel="stylesheet" href='/css/style.css' /> </head> <body> <RouteHandler {...this.props}/> <script type='text/javascript' src='/js/bundle.js' /> </body> </html>

Server-side react with webpack 2 System.import

非 Y 不嫁゛ 提交于 2020-01-02 02:46:09
问题 I have an isomorphic app that's using webpack 2 to compile assets. I added chunking now with System.import which works on the webpack side but not on the server-side with function not found. Any idea how I can solve this? 回答1: There are a few options available for getting System.import working with isomorphic/server-side rendering: Feature-detect System and polyfill Node allows you to call require() in a number of places and shimming System.import as follows should work: if (typeof System ===

Async Routes Causes Server-Side Checksum Invalid Error

我怕爱的太早我们不能终老 提交于 2019-12-24 15:44:55
问题 I'm using Webpack, react, react-router, react-redux, redux, and simple-redux-router. I got this error while using react-router with async routes and server-side rendering: bundle.js:1 Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits

dynamic-segments using basename on the server side - React-Router

房东的猫 提交于 2019-12-24 07:53:27
问题 I have the following code written into my server.js for isomorphic rendering. import { match, useRouterHistory } from 'react-router'; import createHistory from 'react-router/lib/createMemoryHistory'; import createHistory from 'react-router/lib/createMemoryHistory'; import { useBasename } from 'history'; import getRoutes from './routes'; const client = new ApiClient(req); const memoryHistory = useRouterHistory(createHistory)({ basename: '/in' }); const store = createStore(memoryHistory, client

How to get latitude and longitude for a place in an isomorphic application on server

青春壹個敷衍的年華 提交于 2019-12-24 07:16:21
问题 I have isomorphic app which loads on server and client as well. My concern is about loading results for the application on server I need to call google maps api service to get lattitude and longitude for the place for ex 'www.mysite.com/search/New-York--NY--United-States' then I need to find its latitude and longitude from google maps api with below code in php(my api is in php) $address= $this->input->get('address'); $geo = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json

JSON object vs window variable for passing server-side rendered initial state using reactjs

感情迁移 提交于 2019-12-22 14:18:05
问题 In an isomorphic application with Reactjs, you need to pass the identical initial state that was rendered on the server down to the client (which will then 'rehydrate' the app with event bindings and such). I've seen two approaches to passing this initial state down-- Setting a global variable to the window: <script> window.initialState = {{JSON.stringify(initialState)}} ; </script> Or passing it as a JSON object: <script id="initial-state" type="application/json"> {{JSON.stringify

JSON object vs window variable for passing server-side rendered initial state using reactjs

假装没事ソ 提交于 2019-12-22 14:16:07
问题 In an isomorphic application with Reactjs, you need to pass the identical initial state that was rendered on the server down to the client (which will then 'rehydrate' the app with event bindings and such). I've seen two approaches to passing this initial state down-- Setting a global variable to the window: <script> window.initialState = {{JSON.stringify(initialState)}} ; </script> Or passing it as a JSON object: <script id="initial-state" type="application/json"> {{JSON.stringify

Different main entry point in package.json for node and browser

徘徊边缘 提交于 2019-12-22 04:33:27
问题 In isomorphic react app I have myModule which should behave differently on node and browser environments. I would like configure this split point in package.json for myModule : package.json { "private": true, "name": "myModule", "main": "./myModule.server.js", "browser": "./myModule.client.js" } file structure ├── myModule │ ├── myModule.client.js │ ├── myModule.server.js │ └── package.json │ ├── browser.js └── server.js So when I use myModule in node I should get only myModule.server.js :

Building server part of (React) isomorphic webapp with webpack including style-loader for CSS

試著忘記壹切 提交于 2019-12-19 10:39:22
问题 I am attempting to make a React application that I am developing isomorphic. One of the known problems with doing this is that webpack loaders allow import/require of non-javascript assets such as CSS files. e.g. // ExampleComponent.jsx import Select from 'react-select'; import 'react-select/dist/react-select.css'; If building an application with Express then node will get to this import and fail because it can not process a CSS file, it is expecting javascript only (and thanks to babel

Jest Test Babel Error: Plugin/Preset files are not allowed to export objects

孤人 提交于 2019-12-18 14:55:54
问题 I'm using a very up-to-date (December 2017) stack of dependencies. As I try-out isomorphic react tests with Jest, the test suit keeps failing with the following error: * Test suite failed to run [BABEL] /__tests__/router.test.js: Plugin/Preset files are not allowed to export objects, only functions. Here are my dependencies: "dependencies": { "axios": "^0.17.1", "babel-polyfill": "^6.26.0", "cors": "^2.8.4", "express": "^4.16.2", "react": "^16.1.1", "react-dom": "^16.1.1", "react-router-dom":