Skip to content

Instantly share code, notes, and snippets.

@jaseflow
Created June 6, 2016 22:48
Show Gist options
  • Select an option

  • Save jaseflow/20bb6246381084d65b65a558ff74cdfb to your computer and use it in GitHub Desktop.

Select an option

Save jaseflow/20bb6246381084d65b65a558ff74cdfb to your computer and use it in GitHub Desktop.
var path = require("path"),
webpack = require("webpack"),
merge = require("merge"),
config = require("./config/config"),
ExtractTextPlugin = require("extract-text-webpack-plugin");
var webpackConfig = {
output: {
path: path.join(__dirname, "dist"),
filename: "bundle.js",
publicPath: "/static/"
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.NoErrorsPlugin()
]
};
var sassLoaders = [
"css-loader",
"sass-loader?includePaths[]=" + path.resolve(__dirname, "./src/styles")
];
if (config.name === "Production") {
webpackConfig = merge(webpackConfig,{
devtool: "source-map",
entry : [
"./src/client/index.js"
],
module: {
loaders: [
{
test: /\.js$/,
loader: "babel",
exclude: /node_modules/,
include: __dirname
},
{ test: /\.(png|jpg|gif|jpeg)$/, loader: "url-loader?limit=8192"},
{ test: /\.scss$/, loader: ExtractTextPlugin.extract("style-loader", sassLoaders.join("!")) }
]
},
plugins : [
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("prod")
}
}),
new webpack.optimize.UglifyJsPlugin({minimize: true}),
new ExtractTextPlugin("styles.css")
]
});
} else {
webpackConfig = merge(webpackConfig, {
devtool: "#inline-source-map",
module: {
loaders: [{
test: /\.js$/,
loader: "babel",
exclude: /node_modules/,
include: __dirname,
query: {
optional: ["runtime"],
stage: 2,
env: {
development: {
plugins: [
"react-transform"
],
extra: {
"react-transform": {
transforms: [{
transform: "react-transform-hmr",
imports: ["react"],
locals: ["module"]
},
{
transform: "react-transform-catch-errors",
imports: ["react","redbox-react" ]
}
]
}
}
}
}
}
},
{
test: /\.(png|jpg|gif|jpeg)$/,
loader: "url-loader?limit=8192"},
{
test: /\.scss$/,
loaders: ["style", "css", "sass"] }
]},
entry : [
"webpack-hot-middleware/client",
"./src/client/index.js"
],
plugins : [
new webpack.HotModuleReplacementPlugin()
]
});
}
module.exports = webpackConfig;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment