Last active
May 16, 2017 21:21
-
-
Save chrisblackwell/ae64cc99b6847e682c249deff26b855b to your computer and use it in GitHub Desktop.
Webpack Example Configuration
This file contains hidden or 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
const path = require('path'); | |
const glob = require('glob'); | |
const webpack = require('webpack'); | |
const PurifyCSSPlugin = require('purifycss-webpack'); | |
const WebpackNotifierPlugin = require('webpack-notifier'); | |
const CleanWebpackPlugin = require('clean-webpack-plugin'); | |
const BrowserSyncPlugin = require('browser-sync-webpack-plugin'); | |
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
let isProduction = process.env.NODE_ENV === 'production'; | |
module.exports = { | |
entry: { | |
jdeglaw: [ | |
'./src/js/main.js', | |
'./src/sass/main.scss' | |
] | |
}, | |
output: { | |
path: path.resolve(__dirname + '/build'), | |
filename: 'js/[name]-[chunkhash].js' | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.js$/, | |
exclude: /node_modules/, | |
loader: "babel-loader" | |
}, | |
{ | |
test: /\.css$/, | |
loader: 'file-loader', | |
options: { | |
name: 'css/vendor/[name].[ext]' | |
} | |
}, | |
{ | |
test: /\.s[ac]ss*/, | |
use: ExtractTextPlugin.extract({ | |
use: [ | |
{ | |
loader: 'css-loader', | |
options: { url: false } | |
}, | |
'sass-loader' | |
], | |
fallback: 'style-loader' | |
}) | |
} | |
] | |
}, | |
plugins: [ | |
new ExtractTextPlugin('css/[name]-[chunkhash].css'), | |
new CleanWebpackPlugin(['build/css', 'build/js'], { | |
root: __dirname, | |
verbose: true, | |
dry: false | |
}), | |
new webpack.LoaderOptionsPlugin({ | |
minimize: isProduction | |
}), | |
new BrowserSyncPlugin({ | |
host: 'localhost', | |
port: 3000, | |
proxy: 'http://awesome.dev' | |
}), | |
new PurifyCSSPlugin({ | |
minimize: isProduction, | |
paths: glob.sync(path.join(__dirname, '*.php')), | |
}), | |
new WebpackNotifierPlugin({ | |
title: 'YabPack', | |
contentImage: path.join(__dirname, 'src/images/yab_icon.png') | |
}), | |
function() { | |
this.plugin('done', stats => { | |
require('fs').writeFileSync( | |
path.join(__dirname, 'assets/manifest.json'), | |
JSON.stringify(stats.toJson().assetsByChunkName) | |
); | |
}); | |
} | |
] | |
}; | |
if (isProduction) { | |
module.exports.plugins.push( | |
new webpack.optimize.UglifyJsPlugin() | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment