Created
January 19, 2016 15:40
-
-
Save imdanielch/f89f53a405a11fe9077b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path'); | |
var HtmlwebpackPlugin = require('html-webpack-plugin'); | |
var webpack = require('webpack'); | |
var merge = require('webpack-merge'); | |
const TARGET = process.env.npm_lifecycle_event; | |
const PATHS = { | |
app: path.join(__dirname, 'dev'), | |
build: path.join(__dirname, 'build') | |
}; | |
process.env.BABEL_ENV = TARGET; | |
var common = { | |
// Entry accepts a path of an object of entries. | |
entry: PATHS.app, | |
// Add resolve.exteionss '' is needed to allow imports an extension | |
// Note the .'s before extensions, without those matching will fail | |
resolve: { | |
extensions: ['', '.js', '.jsx'] | |
}, | |
module: { | |
loaders: [ | |
{ | |
test: /\.jsx?$/, | |
exclude: /(node_modules)/, | |
loader: 'babel', | |
query: {cacheDirectory: true, plugins: ['object-assign']}, | |
include: PATHS.app | |
}, | |
{ | |
test: /\.(png|woff(2)?|eot|ttf|svg)(\?[a-z0-9=\.]+)?$/, | |
loaders: ['url-loader?limit=100000'] | |
}, | |
{ | |
// Test expects a RegExp! note the slashes! | |
test: /\.css$/, | |
loaders: ['style', 'css'], | |
// Include accepts either a path or an array of paths. | |
include: PATHS.app | |
} | |
] | |
}, | |
plugins: [ | |
new webpack.NoErrorsPlugin(), | |
new HtmlwebpackPlugin({ | |
title: 'Project Title', | |
template: './dev/index.html', | |
inject: 'body' | |
}) | |
] | |
}; | |
if(TARGET === 'start' || !TARGET) { | |
module.exports = merge(common, { | |
devtool: 'eval-source-map', | |
devServer: { | |
historyApiFallback: true, | |
hot: true, | |
inline: true, | |
progress: true, | |
// Display only errors to reduce the amount of output. | |
stats: 'errors-only', | |
// Parse host and port from env so this is easy to customize. | |
host: process.env.HOST, | |
port: process.env.PORT | |
}, | |
plugins: [ | |
new webpack.HotModuleReplacementPlugin() | |
] | |
}); | |
} | |
if(TARGET === 'build') { | |
module.exports = merge(common, { | |
output: { | |
path: PATHS.build, | |
filename: 'bundle.js' | |
}, | |
devtool: 'source-map', | |
plugins: [ | |
// Setting DefinePlugin affects React library size! | |
new webpack.DefinePlugin({ | |
'process.env.NODE_ENV': JSON.stringify('production') | |
}), | |
new webpack.optimize.UglifyJsPlugin({ | |
compress: { | |
warnings: false | |
} | |
}) | |
] | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment