Skip to content

Instantly share code, notes, and snippets.

@AndersNS
Created April 10, 2015 07:26
Show Gist options
  • Save AndersNS/ea371735f639aee8072d to your computer and use it in GitHub Desktop.
Save AndersNS/ea371735f639aee8072d to your computer and use it in GitHub Desktop.
My webpack setup for a reactjs project
"scripts": {
"build-client": "webpack --verbose --colors --display-error-details --config webpack.client.js",
"watch-client": "webpack --verbose --colors --display-error-details --config webpack.client-watch.js && webpack-dev-server --config webpack.client-watch.js"
}
var webpack = require("webpack");
var config = require("./webpack.client.js");
config.cache = true;
config.debug = true;
config.devtool = "eval-source-map";
config.entry.unshift(
"webpack-dev-server/client?http://localhost:8080",
"webpack/hot/only-dev-server"
);
config.output.publicPath = "http://localhost:8080/js/";
config.output.hotUpdateMainFilename = "update/[hash]/update.json";
config.output.hotUpdateChunkFilename = "update/[hash]/[id].update.js";
config.plugins = [
new webpack.DefinePlugin({__CLIENT__: true, __SERVER__: false}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
];
config.module = {
loaders: [
{include: /\.json$/, loaders: ["json-loader"]},
{include: /\.js$/, loaders: ["react-hot", "babel-loader?stage=1&optional=runtime"], include: /app/}
]
};
config.devServer = {
publicPath: "http://localhost:8080/js/",
contentBase: "./build",
hot: true,
inline: true,
quiet: true,
lazy: false,
noInfo: true,
headers: {"Access-Control-Allow-Origin": "*"},
stats: {colors: true}
};
module.exports = config;
var webpack = require("webpack");
var path = require("path");
module.exports = {
target: "web",
cache: false,
context: __dirname,
devtool: false,
entry: ["./app/client.js"],
output: {
path: path.join(__dirname, "build/js"),
filename: "bundle.js",
chunkFilename: "[name].[id].js",
publicPath: "js/"
},
plugins: [
new webpack.DefinePlugin({__CLIENT__: true, __SERVER__: false}),
new webpack.DefinePlugin({"process.env": {NODE_ENV: '"production"'}}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin()
],
module: {
loaders: [
{include: /\.json$/, loaders: ["json-loader"]},
{include: /\.js$/, loaders: ["babel-loader?stage=1&optional=runtime"], exclude: /node_modules/}
]
},
resolve: {
modulesDirectories: [
"src",
"node_modules",
"web_modules"
],
extensions: ["", ".json", ".jsx", ".js"]
},
node: {
__dirname: true,
fs: 'empty'
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment