Starer code for a react/webpack project.
Last active
August 25, 2016 06:24
-
-
Save de314/1f4d081bc5ad0a4df9eea68150910c72 to your computer and use it in GitHub Desktop.
React/Webpack Base
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm init -y | |
npm i -S react react-dom react-router lodash moment jquery | |
npm i -D babel-core babel-loader babel-preset-es2015 babel-preset-react react-hot-loader webpack webpack-dev-server | |
npm i -g webpack webpack-dev-server | |
# should probably add to package.json | |
# "scripts": { | |
# "start": "webpack-dev-server --host 0.0.0.0 --port 3000" // or desired port | |
# } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webpack = require('webpack'); | |
var path = require('path'); | |
module.exports = { | |
devtool: 'inline-source-map', | |
entry: [ | |
'webpack-dev-server/client?http://127.0.0.1:3000/', // or desired port | |
'webpack/hot/only-dev-server', | |
'./src' | |
], | |
output: { | |
path: path.join(__dirname, 'public'), | |
filename: 'client.min.js' | |
}, | |
resolve: { | |
modulesDirectories: ['node_modules', 'src'], | |
extensions: ['', '.js'] | |
}, | |
module: { | |
loaders: [ | |
{ | |
test: /\.jsx?$/, | |
exclude: /node_modules/, | |
loaders: ['react-hot', 'babel?presets[]=react,presets[]=es2015'] | |
} | |
] | |
}, | |
plugins: [ | |
new webpack.HotModuleReplacementPlugin(), | |
new webpack.NoErrorsPlugin() | |
] | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Base React/Webpack App</title> | |
</head> | |
<body> | |
<div id="container"> | |
<div id="app"></div> | |
</div> | |
<script src="client.min.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ./src/index.js | |
import React from 'react'; | |
import { render } from 'react-dom'; | |
import App from 'components/app'; | |
render(<App />, document.getElementById('app')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ./src/components/app.js | |
import React from 'react'; | |
import Header from './header'; | |
export default class App extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
// todo | |
} | |
} | |
render() { | |
return ( | |
<div> | |
<Header /> | |
<h1>Base React/Webpack App</h1> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment