Permalink
Browse files

initial commit

a working index page
  • Loading branch information...
BradDenver committed Dec 31, 2014
0 parents commit 303b95a8dffb4e75fe376301d6462ea51e221dbb
Showing with 136 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +19 −0 bower.json
  3. +7 −0 dev/entry.jsx
  4. +1 −0 dev/index.html
  5. +20 −0 elements/Layout.jsx
  6. +20 −0 package.json
  7. +28 −0 server.js
  8. +38 −0 webpack.config.js
@@ -0,0 +1,3 @@
/node_modules/
/bower_components/
@@ -0,0 +1,19 @@
{
"name": "react-static-site",
"version": "0.0.0",
"authors": [
"Brad Denver <brad.denver@gmail.com>"
],
"license": "MIT",
"private": true,
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"pure": "~0.5.0"
}
}
@@ -0,0 +1,7 @@
var React = require('react'),
Layout = require('../elements/Layout.jsx');
React.render(<Layout title="React Static Site" >Hello World</Layout>, document);
@@ -0,0 +1 @@
<html data-reactid=".d3jmodpqm8" data-react-checksum="1282699795"><head data-reactid=".d3jmodpqm8.0"><title data-reactid=".d3jmodpqm8.0.0">React Static Site</title></head><body data-reactid=".d3jmodpqm8.1"><span data-reactid=".d3jmodpqm8.1.0">Hello World</span><script src="http://localhost:3000/scripts/bundle.js" data-reactid=".d3jmodpqm8.1.1"></script></body></html>
@@ -0,0 +1,20 @@
var React = require('react');
var Layout = React.createClass({
render: function() {
var script = (process.env.NODE_ENV!=='production') ? <script src="http://localhost:3000/scripts/bundle.js"></script> : '';
return (
<html>
<head>
<title>{this.props.title}</title>
</head>
<body>
{this.props.children}
{script}
</body>
</html>
);
}
});
module.exports = Layout;
@@ -0,0 +1,20 @@
{
"name": "react-static-site",
"version": "1.0.0",
"description": "an experiment in generating a static site from react",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"dependencies": {
"node-jsx": "^0.12.4",
"react": "^0.12.2"
},
"devDependencies": {
"jsx-loader": "^0.12.2",
"react-hot-loader": "^1.0.4",
"webpack": "^1.4.15",
"webpack-dev-server": "^1.7.0"
}
}
@@ -0,0 +1,28 @@
require('node-jsx').install();
var fs = require('fs'),
React = require('react'),
webpack = require('webpack'),
WebpackDevServer = require('webpack-dev-server'),
config = require('./webpack.config'),
Layout = require('./elements/Layout.jsx');
// create the index.html to be used by webpack
fs.writeFileSync('dev/index.html', React.renderToString(React.createElement(Layout, {
title: 'React Static Site',
children: 'Hello World'
})));
var server = new WebpackDevServer(webpack(config), {
contentBase: './dev',
publicPath: config.output.publicPath,
hot: true
});
server.listen(3000, 'localhost', function (err, result) {
if (err) {
console.log(err);
}
console.log('Listening at localhost:3000');
});
@@ -0,0 +1,38 @@
var webpack = require('webpack');
module.exports = {
// Entry point for static analyzer:
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/dev-server',
'./dev/entry.jsx'
],
output: {
// Where to put build results when doing production builds:
// (Server doesn't write to the disk, but this is required.)
path: __dirname,
// JS filename you're going to use in HTML
filename: 'bundle.js',
// Path you're going to use in HTML
publicPath: 'http://localhost:3000/scripts/'
},
plugins: [
new webpack.HotModuleReplacementPlugin()
],
resolve: {
// Allow to omit extensions when requiring these files
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [
// Pass *.jsx files through jsx-loader transform
{ test: /\.jsx$/, loaders: ['react-hot', 'jsx'] },
]
}
};

0 comments on commit 303b95a

Please sign in to comment.