Last active
April 23, 2017 09:11
-
-
Save endam/2fff4676dc76da7dfbd551bbb3e30e72 to your computer and use it in GitHub Desktop.
React Hot Loader sample description
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
browserSync({ | |
port: 3006, | |
・・・ |
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
entry : [ | |
'webpack/hot/dev-server', | |
'webpack-hot-middleware/client', | |
'./index.js', | |
], |
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
function getEntries() { | |
let entries = {}; | |
// hot reload用設定 | |
const devClient = [ | |
'webpack/hot/dev-server', | |
'webpack-hot-middleware/client', | |
]; | |
// entrypoint毎にhot reload用設定を付加する | |
config.react.map((app_name) => { | |
entries[`react_${app_name}`] = [...devClient, `./js/react/${app_name}/app.js`]; | |
}); | |
return entries; | |
} |
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
module: { | |
loaders: [ | |
{ | |
loaders: ['react-hot-loader', 'babel-loader'], | |
test: /\.js?$/, | |
exclude: /node_modules/, | |
include: [src], | |
}, | |
] | |
}, |
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
entry : { | |
app1: ['./app1/index.js', 'webpack/hot/dev-server', 'webpack-hot-middleware/client'], | |
app2: ['./app2/index.js', 'webpack/hot/dev-server', 'webpack-hot-middleware/client'], | |
}, | |
output: { | |
path: dist, | |
publicPath: '/dist/', | |
filename: '[name].bundle.js' | |
}, |
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
plugins: [ | |
new webpack.LoaderOptionsPlugin({ | |
debug: true | |
}), | |
new webpack.optimize.OccurrenceOrderPlugin(), | |
new webpack.NoEmitOnErrorsPlugin(), | |
new webpack.HotModuleReplacementPlugin(), | |
] |
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 gulp from "gulp"; | |
import webpack from "webpack"; | |
import browserSync from 'browser-sync'; | |
import webpackDevMiddleware from "webpack-dev-middleware"; | |
import webpackHotMiddleware from "webpack-hot-middleware"; | |
import webpackConfig from "./webpack.config.js"; | |
import proxyMiddleware from 'http-proxy-middleware'; | |
gulp.task("watch", () => { | |
const bundler = webpack(webpackConfig); | |
const proxy = proxyMiddleware('/', {target: 'http://{ゲストOSのIPアドレス}'}); | |
browserSync({ | |
server: { | |
baseDir: "./", | |
port: 3000, | |
middleware: [ | |
webpackDevMiddleware(bundler, { | |
publicPath: webpackConfig.output.publicPath, | |
stats: { colors: true }, | |
watchOptions: { | |
poll: true, | |
ignored: /node_modules/ | |
} | |
}), | |
webpackHotMiddleware(bundler), | |
proxy, | |
] | |
}, | |
files: [ | |
'*.css', | |
'*.html' | |
], | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment