Skip to content

Instantly share code, notes, and snippets.

@skynode
Last active April 14, 2017 01:18
Show Gist options
  • Save skynode/e2ac68fc3420aef7bca676f43bc3b007 to your computer and use it in GitHub Desktop.
Save skynode/e2ac68fc3420aef7bca676f43bc3b007 to your computer and use it in GitHub Desktop.
Configuring Webpack 2.3.x in dev mode
import webpack from 'webpack';
import path from 'path';
import nodeExternals from 'webpack-node-externals';
export default {
devtool: "cheap-module-eval-source-map",
entry: [
//code order here is critical
"eventsource-polyfill", //for hot reloading in IE
"webpack-hot-middleware/client?reload=true", //reloads page if HMR fails
"./src/index.jsx"
],
target: "web",
output: {
path: path.resolve(__dirname, "/dist"),
publicPath: "/",
filename: "bundle.js"
},
devServer: {
contentBase: "./src"
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.LoaderOptionsPlugin({
debug: true
})
],
module: {
rules: [
{
test: /\.(js|jsx)?$/,
include: path.join(__dirname, "src"),
use: "babel-loader"
},
{
test: /\.css$/,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader'
}
]
},
{
test: /\.eot(\?v=\d+\.\d+)?$/,
use: "file-loader"
},
{
test: /\.otf(\?[a-z0-9]+)?$/,
use: "file-loader?name=fonts/[name].[ext]"
},
{
test: /\.(woff|woff2)$/,
use: "url-loader?prefix=font/&limit=5000"
},
{
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
use: "url-loader?limit=10000&mimetype=application/octet-stream"
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
use: "url-loader?limit=10000&mimetype=image/svg+xml"
}
]
}
};
@skynode
Copy link
Author

skynode commented Mar 14, 2017

For react apps, also add .babelrc with the following:

{
    "presets": ["es2015", "react"] ,
    "env": {
           "development": {
                    "presets": ["react-hmre"]
            }
     }
}

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