Skip to content

Instantly share code, notes, and snippets.

@subblue
Created June 5, 2016 08:27
Show Gist options
  • Save subblue/a0c06c9b3168a55ec5d75a7dd27467f0 to your computer and use it in GitHub Desktop.
Save subblue/a0c06c9b3168a55ec5d75a7dd27467f0 to your computer and use it in GitHub Desktop.
General Webpack dev config
'use strict';
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const npmPackage = require('./package.json');
const host = '0.0.0.0';
const port = 3000;
const config = {
entry: [
'babel-polyfill',
'./src/app'
],
output: {
path: './dist',
publicPath: `http://${host}:${port}/`,
filename: 'app.js'
},
resolve: {
root: './src',
alias: {},
extensions: ['', '.js', '.jsx'],
modulesDirectories: npmPackage._moduleDirectories || []
},
module: {
loaders: [
{
test: /\.jsx?$/,
loader: 'react-hot!babel?sourceMap&plugins[]=transform-runtime&presets[]=es2015,presets[]=stage-0,presets[]=react',
exclude: /node_modules/
},
{
test: /\.css$/,
loader: 'style!css?sourceMap!postcss',
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'url?limit=8192&name=images/[name].[ext]',
exclude: /node_modules/
},
{
test: /\.(eot|ttf|woff|woff2)$/,
loader: 'url?limit=8192&name=fonts/[name].[ext]',
exclude: /node_modules/
}
]
},
postcss: function (webpack) {
return [
require('postcss-import')({addDependencyTo: webpack, map: true}),
require('postcss-url')(),
require('postcss-cssnext')({map: true}),
// require('postcss-browser-reporter')(),
require('postcss-reporter')()
];
},
plugins: [
// ref: https://github.com/webpack/webpack/issues/615
new webpack.DefinePlugin({
'process.env': {NODE_ENV: JSON.stringify('development')}
}),
new webpack.DefinePlugin({
VERSION: JSON.stringify(npmPackage.version)
}),
new HtmlWebpackPlugin({
template: 'src/index.html',
title: 'Page title',
inject: 'body'
})
],
devServer: {
contentBase: './src',
cached: false,
colors: true,
port: port,
host: host,
noInfo: false,
quiet: false,
historyApiFallback: true,
stats: {
hash: false,
colors: true,
cached: false,
version: false,
exclude: [
// /node_modules\/(react|dev-server|core-js|react-router|babel-core|reflux|history)\//,
// /webpack|babel-runtime/
]
}
}
};
module.exports = config;
@subblue
Copy link
Author

subblue commented Jun 5, 2016

The package.json file to use with this is here: https://gist.github.com/subblue/850b1a7ee81229c5f904c8a045810af7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment