Skip to content

Instantly share code, notes, and snippets.

@chrisdel101
Last active March 13, 2017 00:34
Show Gist options
  • Save chrisdel101/737d1dc9d7524d3581900560c438e73f to your computer and use it in GitHub Desktop.
Save chrisdel101/737d1dc9d7524d3581900560c438e73f to your computer and use it in GitHub Desktop.
Problem loading react
//src/index.js
import React from 'react'
import ReactDOM from 'react-dom'
ReactDOM.render(
<h2>Hello React with JSX</h2>,
document.getElementById('root');
);
-------------------------------
//views/index.ejs
<!DOCTYPE html>
<head>
<%- include partials/header.ejs %>
</head>
<html>
<body>
<div id='root'></div>
</body>
<%- include partials/footer.ejs %>
</html>
-------------------------------
//views/partials/footer.ejs -error 404
<script src="/bundle.js" charset="utf-8"></script>
-------------------------------
//server.js
import fs from 'fs';
import config from './config';
import express from 'express';
import apiRouter from './api'
const server = express();
server.set('view engine', 'ejs');
server.get('/', (req,res) => {
res.render('index.ejs', {
title: "Home",
content: "This is the content section"
});
});
server.use('/api', apiRouter)
server.listen(config.port, ()=> {
console.log("Exress listening on port ", config.port)
})
-------------------------------
webpack
module.exports = {
entry: '.src/index.js',
output: {
path: __dirname + '/public',
filename: 'bundle.js'
},
module: {
loaders:[
{
test: /\.js$/,
loader:'babel-loader'
}
]
}
};
-------------------------------
package json
{
"name": "my_mern_app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon --exec babel-node server.js --ignore public/",
"dev": "webpack -wd"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"ejs": "^2.5.6",
"express": "^4.15.2",
"mongodb": "^2.2.24",
"react": "^15.4.2",
"react-dom": "^15.4.2"
},
"devDependencies": {
"babel-cli": "^6.23.0",
"babel-core": "^6.23.1",
"babel-eslint": "^7.1.1",
"babel-loader": "^6.4.0",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.23.0",
"babel-preset-stage-2": "^6.22.0",
"eslint": "^3.17.1",
"eslint-plugin-react": "^6.10.0",
"nodemon": "^1.11.0",
"webpack": "^2.2.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment