Last active
March 7, 2016 01:35
-
-
Save batwicket/d75d15e824a066c5deb5 to your computer and use it in GitHub Desktop.
fun with webpack
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 path = require('path'); | |
var express = require('express'); | |
var webpack = require('webpack'); | |
var config = require('./webpack.config.dev'); | |
var app = express(); | |
var compiler = webpack(config); | |
app.use(require('webpack-dev-middleware')(compiler, { | |
noInfo: true, | |
publicPath: config.output.publicPath | |
})); | |
app.use(require('webpack-hot-middleware')(compiler)); | |
app.get('*', function(req, res) { | |
res.sendFile(path.join(__dirname, 'index.html')); | |
}); | |
app.listen(3000, 'localhost', function(err) { | |
if (err) { | |
console.log(err); | |
return; | |
} | |
console.log('Listening at http://localhost:3000'); | |
}); |
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
!doctype html> | |
<html> | |
<head> | |
<title>React Transform Boilerplate</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<link rel="stylesheet" href="material.css"> | |
</head> | |
<body> | |
<div id="root"></div> | |
<script src="material.js"></script> | |
<script type="text/javascript"> | |
SERVER_URL = "https://localdev.net:8443"; | |
</script> | |
<script src="/static/bundle.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
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import { DefaultRoute, Link, Route, Router, RouteHandler, IndexRoute } from 'react-router'; | |
import { MainLayout } from './layouts/MainLayout'; | |
import { LoginPage } from './pages/LoginPage'; | |
import auth from './auth/auth.js'; | |
import history from './history.js'; | |
function requireAuth(nextState, replaceState) { | |
if (!auth.loggedIn()) | |
replaceState({ nextPathname: nextState.location.pathname }, '/login') | |
} | |
ReactDOM.render(( | |
<Router> | |
<Route path="/" component={MainLayout}> | |
<IndexRoute component={LoginPage} onEnter={requireAuth}/> | |
<Route path="login" component={LoginPage}/> | |
</Route> | |
</Router> | |
), document.getElementById('root')); |
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
react-transform-boilerplate jf$ npm start --verbose | |
npm info it worked if it ends with ok | |
npm verb cli [ '/usr/local/Cellar/node/5.5.0/bin/node', | |
npm verb cli '/usr/local/bin/npm', | |
npm verb cli 'start', | |
npm verb cli '--verbose' ] | |
npm info using npm@3.5.3 | |
npm info using node@v5.5.0 | |
npm verb run-script [ 'prestart', 'start', 'poststart' ] | |
npm info lifecycle react-transform-boilerplate@1.0.0~prestart: react-transform-boilerplate@1.0.0 | |
npm info lifecycle react-transform-boilerplate@1.0.0~start: react-transform-boilerplate@1.0.0 | |
> react-transform-boilerplate@1.0.0 start /projects/golang/src/react-transform-boilerplate | |
> node devServer.js | |
Listening at http://localhost:3000 | |
webpack built 50348cfb568f0c67788a in 4558ms |
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
{ | |
private: true, | |
name: react-transform-boilerplate, | |
version: 1.0.0, | |
description: A new Webpack boilerplate with hot reloading React components, and error handling on module and component level., | |
scripts: { | |
clean: rimraf dist, | |
build:webpack: cross-env NODE_ENV=production webpack --config webpack.config.prod.js, | |
build: npm run clean && npm run build:webpack, | |
start: node devServer.js, | |
lint: eslint src | |
}, | |
repository: { | |
type: git, | |
url: https://github.com/gaearon/react-transform-boilerplate.git | |
}, | |
keywords: [ | |
react, | |
reactjs, | |
boilerplate, | |
hot, | |
reload, | |
hmr, | |
live, | |
edit, | |
webpack, | |
babel, | |
react-transform | |
], | |
author: Dan Abramov <dan.abramov@me.com> (http://github.com/gaearon), | |
license: CC0-1.0, | |
bugs: { | |
url: https://github.com/gaearon/react-transform-boilerplate/issues | |
}, | |
homepage: https://github.com/gaearon/react-transform-boilerplate, | |
devDependencies: { | |
babel-core: ^6.3.15, | |
babel-eslint: ^5.0.0-beta4, | |
babel-loader: ^6.2.0, | |
babel-preset-es2015: ^6.3.13, | |
babel-preset-react: ^6.3.13, | |
babel-preset-react-hmre: ^1.0.0, | |
cross-env: ^1.0.6, | |
eslint: ^1.10.3, | |
css-loader: ^0.23.1, | |
style-loader: ^0.13.0, | |
react-mdl: ^1.4.4, | |
history: ^2.0.1, | |
eslint-plugin-babel: ^3.0.0, | |
eslint-plugin-react: ^3.11.3, | |
eventsource-polyfill: ^0.9.6, | |
express: ^4.13.3, | |
rimraf: ^2.4.3, | |
isomorphic-style-loader: ^0.0.12, | |
webpack: ^1.12.9, | |
webpack-dev-middleware: ^1.4.0, | |
webpack-hot-middleware: ^2.6.0 | |
}, | |
dependencies: { | |
react: ^0.14.3, | |
react-dom: ^0.14.3 | |
} | |
} |
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 path = require('path'); | |
var webpack = require('webpack'); | |
module.exports = { | |
devtool: 'cheap-module-eval-source-map', | |
entry: [ | |
'eventsource-polyfill', // necessary for hot reloading with IE | |
'webpack-hot-middleware/client', | |
'./src/index' | |
], | |
output: { | |
path: path.join(__dirname, 'dist'), | |
filename: 'bundle.js', | |
publicPath: '/static/' | |
}, | |
plugins: [ | |
new webpack.HotModuleReplacementPlugin(), | |
new webpack.NoErrorsPlugin() | |
], | |
resolve: { | |
alias: { | |
'styles': path.join(__dirname, 'styles'), | |
}, | |
extensions: ['', '.js', '.jsx', '.css'] | |
}, | |
module: { | |
loaders: [{ | |
test: /\.js?/, | |
exclude: /node_modules/, | |
loaders: ['babel'], | |
include: path.join(__dirname, 'src') | |
}, { | |
test: /\.css$/, | |
exclude: /node_modules/, | |
loaders: [ 'style!css' ], | |
include: __dirname | |
}] | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment