Skip to content

Instantly share code, notes, and snippets.

@annielmenezes
Last active April 8, 2016 01:16
Show Gist options
  • Save annielmenezes/948b6bc53fc497e97b74d527a206a6dc to your computer and use it in GitHub Desktop.
Save annielmenezes/948b6bc53fc497e97b74d527a206a6dc to your computer and use it in GitHub Desktop.
Webpack config boilerplate to React project
{
"scripts": {
"build": "webpack",
"start": "webpack-dev-server"
},
"devDependencies": {
"babel-core": "^6.5.2",
"babel-loader": "^6.2.3",
"babel-preset-es2015": "^6.5.0",
"babel-preset-react": "^6.5.0",
"babel-preset-react-hmre": "^1.1.0",
"babel-preset-survivejs-kanban": "^0.3.3",
"babel-register": "^6.5.2",
"css-loader": "^0.23.1",
"npm-install-webpack-plugin": "^2.0.2",
"style-loader": "^0.13.0",
"webpack": "^1.12.14",
"webpack-dev-server": "^1.14.1",
"webpack-merge": "^0.7.3"
},
"dependencies": {
"alt": "^0.18.2",
"alt-container": "^1.0.2",
"alt-utils": "^1.0.0",
"node-uuid": "^1.4.7",
"react": "^0.14.7",
"react-dom": "^0.14.7"
}
}
/* @flow */
import path from 'path';
import webpack from 'webpack';
import merge from 'webpack-merge';
import NpmInstallPlugin from 'npm-install-webpack-plugin';
const TARGET = process.env.npm_lifecycle_event;
const PATHS = {
app: path.join(__dirname, 'app'),
build: path.join(__dirname, 'build')
};
process.env.BABEL_ENV = TARGET;
const common = {
entry: {
app: PATHS.app
},
resolve: {
extensions: ['', '.js', '.jsx']
},
output: {
path: PATHS.build,
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /\.css$/,
loaders: ['style', 'css'],
include: PATHS.app
},
{
test: /\.jsx?$/,
loaders: ['babel?cacheDirectory'],
include: PATHS.app
}
]
}
};
if (TARGET === 'start' || !TARGET) {
module.exports = merge(common, {
devtool: 'eval-source-map',
devServer: {
contentBase: PATHS.build,
historyApiFallback: true,
hot: true,
inline: true,
progress: true,
stats: 'errors-only',
host: process.env.HOST,
port: process.env.PORT
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new NpmInstallPlugin({
save: true
})
]
});
}
if (TARGET === 'build') {
module.exports = merge(common, {});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment