Skip to content

Instantly share code, notes, and snippets.

@stevepiercy
Created August 14, 2015 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevepiercy/3c2f127e36eab78e516b to your computer and use it in GitHub Desktop.
Save stevepiercy/3c2f127e36eab78e516b to your computer and use it in GitHub Desktop.
webpack.config.js in attempt to integrate Bootswatch theme Readable
var path = require('path');
var webpack = require('webpack');
var HtmlwebpackPlugin = require('html-webpack-plugin');
var merge = require('webpack-merge');
var Clean = require('clean-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var pkg = require('./package.json');
var TARGET = process.env.TARGET;
var ROOT_PATH = path.resolve(__dirname);
var common = {
entry: path.resolve(ROOT_PATH, 'app/main'),
resolve: {
extensions: ['', '.js', '.jsx']
},
output: {
path: path.resolve(ROOT_PATH, 'build'),
filename: 'bundle.js'
},
plugins: [
new HtmlwebpackPlugin({
title: 'Readable theme from Bootswatch'
})
]
};
if(TARGET === 'dev') {
module.exports = merge(common, {
devtool: 'eval',
module: {
loaders: [
{
test: /\.css$/,
loaders: ['style', 'css']
},
{
test: /\.jsx?$/,
loaders: ['react-hot', 'babel?stage=1'],
include: path.resolve(ROOT_PATH, 'app')
}
]
},
devServer: {
colors: true,
historyApiFallback: true,
hot: true,
inline: true,
progress: true
},
plugins: [
new webpack.HotModuleReplacementPlugin()
]
});
}
if(TARGET === 'build') {
module.exports = merge(common, {
entry: {
app: path.resolve(ROOT_PATH, 'app/main'),
vendor: Object.keys(pkg.dependencies)
},
output: {
path: path.resolve(ROOT_PATH, 'build'),
filename: 'app.[chunkhash].js'
},
devtool: 'source-map',
module: {
loaders: [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style', 'css'),
include: path.resolve(ROOT_PATH, 'app')
},
{
test: /\.jsx?$/,
loaders: ['babel?stage=1'],
include: path.resolve(ROOT_PATH, 'app')
},
{
test: /\.less$/,
loader: ExtractTextPlugin.extract('style','css','less'),
include: path.resolve(ROOT_PATH, 'app')
// }, {
// test: /\.(png|jpg|ico)$/,
// loader: 'file?name=img/[name].[ext]'
// }, {
// test: /\.(woff|woff2|ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
// loader: 'file?name=fonts/[name].[ext]'
}
]
},
plugins: [
new ExtractTextPlugin('styles.css'),
new Clean(['build']),
new webpack.optimize.CommonsChunkPlugin(
'vendor',
'vendor.[chunkhash].js'
),
new webpack.DefinePlugin({
'process.env': {
// This affects react lib size
'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