This repository has been archived by the owner on Jan 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use express instead of webpack-dev-server for more flexability
- Loading branch information
1 parent
6b1b892
commit 6a19f6a
Showing
8 changed files
with
65 additions
and
57 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
var WebpackDevServer = require('webpack-dev-server'); | ||
var express = require('express'); | ||
var webpackDevMiddleware = require('webpack-dev-middleware'); | ||
var webpack = require('webpack'); | ||
var config = require('./webpack.config.js'); | ||
var webpackConfig = require('./webpack.config.js'); | ||
var app = express(); | ||
|
||
var compiler = webpack(config); | ||
var server = new WebpackDevServer(compiler, { | ||
contentBase: 'www', | ||
var compiler = webpack(webpackConfig); | ||
|
||
app.use(express.static(__dirname + '/www')); | ||
|
||
app.use(webpackDevMiddleware(compiler, { | ||
hot: true, | ||
filename: 'bundle.js', | ||
publicPath: '/', | ||
stats: { | ||
colors: true, | ||
}, | ||
}); | ||
server.listen(8080, 'localhost', () => { | ||
console.log('Server started, webpack is compiling...'); | ||
historyApiFallback: true, | ||
})); | ||
|
||
var server = app.listen(3000, function() { | ||
var host = server.address().address; | ||
var port = server.address().port; | ||
console.log('Example app listening at http://%s:%s', host, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
|
||
/** | ||
* A counter button: tap the button to increase the count. | ||
*/ | ||
class Counter extends React.Component { | ||
constructor() { | ||
super(); | ||
this.state = { | ||
count: 0, | ||
}; | ||
} | ||
|
||
render() { | ||
return ( | ||
<button | ||
onClick={() => { | ||
this.setState({ count: this.state.count + 1 }); | ||
}} | ||
> | ||
Count: {this.state.count} | ||
</button> | ||
); | ||
} | ||
} | ||
export default Counter; |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
/** | ||
* Hello | ||
*/ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import HelloWorld from './HelloWorld'; | ||
import Counter from './Counter'; | ||
|
||
ReactDOM.render( | ||
React.createElement(HelloWorld), | ||
React.createElement(Counter), | ||
document.getElementById('mount') | ||
); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,32 @@ | ||
var path = require('path'); | ||
var webpack = require('webpack'); | ||
var projectRoot = __dirname; | ||
|
||
var config = { | ||
context: path.join(projectRoot, 'src'), | ||
context: path.join(__dirname, 'src'), | ||
entry: [ | ||
'./index.js', | ||
'webpack/hot/dev-server', | ||
'webpack-dev-server/client?http://localhost:8080/', | ||
'./main.js', | ||
], | ||
output: { | ||
path: path.join(projectRoot, 'html'), | ||
path: path.join(__dirname, 'www'), | ||
filename: 'bundle.js', | ||
publicPath: '/', | ||
}, | ||
module: { | ||
loaders: [ | ||
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'}, | ||
{ | ||
test: /\.js$/, | ||
exclude: /node_modules/, | ||
loaders: ['babel'], | ||
}, | ||
], | ||
}, | ||
resolveLoader: { | ||
root: [ | ||
path.join(projectRoot, 'node_modules'), | ||
path.join(__dirname, 'node_modules'), | ||
], | ||
}, | ||
resolve: { | ||
root: [ | ||
path.join(projectRoot, 'node_modules'), | ||
path.join(__dirname, 'node_modules'), | ||
], | ||
}, | ||
plugins: [ | ||
new webpack.HotModuleReplacementPlugin(), | ||
], | ||
}; | ||
module.exports = config; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,6 @@ | ||
<html> | ||
<head> | ||
<style> | ||
.hello-world { | ||
border: 2px solid lightblue; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
Your component will be mounted here: | ||
<div id='mount'> | ||
</div> | ||
<script src='bundle.js' ></script> | ||
<div id="mount"></div> | ||
<script src="/bundle.js" ></script> | ||
</body> | ||
</html> |