Skip to content

Instantly share code, notes, and snippets.

@ALF-er
Created April 29, 2015 13:59
Show Gist options
  • Save ALF-er/8a6af60b59b49af23a1c to your computer and use it in GitHub Desktop.
Save ALF-er/8a6af60b59b49af23a1c to your computer and use it in GitHub Desktop.
my webpack.config.js
var webpack = require("webpack");
var yargs = require("yargs");
var path = require("path");
var nib = require("nib");
var argv = yargs
.boolean("p").alias("p", "optimize-minimize")
.boolean("h").alias("h", "hot")
.argv;
module.exports = {
entry: (function() {
var entry = [];
entry.push(path.join(__dirname, "src", "app", "entrypoints", "main.jsx"));
return {
main: entry
};
})(),
output: {
path: path.join(__dirname, "dist", "app"),
filename: "[name].js",
publicPath: "/app/"
},
module: {
loaders: [
{
test: /fetch.js$/,
loaders: ["exports?fetch=window.fetch.bind(window),Headers=window.Headers,Request=window.Request,Response=window.Response"]
},
{
test: /history.js$/,
loaders: ["exports?History=window.history"]
},
{
test: /\.js$/,
exclude: [/node_modules/],
loaders: ["babel"]
},
{
test: /\.jsx$/,
exclude: [/node_modules/],
loaders: (function() {
var loaders = [];
if (argv.h) {
loaders.push("react-hot");
}
loaders.push("babel");
return loaders;
})()
},
{
test: /\.styl$/,
loaders: [
"style",
"css",
"stylus"
]
},
{
test: /\.css$/,
loaders: [
"style",
"css"
]
},
{
test: /\.json$/,
loaders: [
"json"
]
},
{
test: /\.(png|jpg|gif)$/,
loaders: (function() {
var loaders = [];
loaders.push("url?limit=50000");
return loaders;
})()
},
{
test: /\.(ttf|eot|woff|svg)$/,
loaders: [
"file"
]
}
]
},
resolve: {
extensions: ["", ".js", ".jsx"],
root: path.join(__dirname, "src", "app"),
modulesDirectories: ["web_modules", "node_modules", "src"],
alias: {
"localforageSerializer": "../utils/serializer"
}
},
cache: !argv.p,
debug: !argv.p,
devtool: !argv.p ? "eval-cheap-module-source-map" : false,
// devtool: false,
stats: {
colors: true,
reasons: !argv.p
},
stylus: {
use: [nib()]
},
plugins: (function() {
var plugins = [];
plugins.push(
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(argv.p ? "production" : "development"),
"__DEV__": !argv.p
})
);
if (argv.p) {
plugins.push(new webpack.optimize.DedupePlugin());
plugins.push(new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}));
plugins.push(new webpack.optimize.OccurenceOrderPlugin());
plugins.push(new webpack.optimize.AggressiveMergingPlugin());
}
if (argv.h) {
// plugins.push(new webpack.HotModuleReplacementPlugin());
plugins.push(new webpack.NoErrorsPlugin());
}
return plugins;
})()
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment