Skip to content

Instantly share code, notes, and snippets.

@harrylincoln
Created July 18, 2017 13:17
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 harrylincoln/c205e2dbb23dd19af0452f4d7d51fffb to your computer and use it in GitHub Desktop.
Save harrylincoln/c205e2dbb23dd19af0452f4d7d51fffb to your computer and use it in GitHub Desktop.
Monk, yeahhhhhh
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const path = require('path');
let prod = process.argv.indexOf('-p') !== -1;
let watchOption = process.argv.indexOf('--watch') !== -1;
module.exports = {
entry: ['./js/site.js'],
output: {
publicPath: '',
path: __dirname + '/js/build/',
filename: 'main.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['es2015']
}
},
{
loader: 'eslint-loader'
}
]
},
{
test: /\.css|sass|scss$/,
loader: ExtractTextPlugin.
extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader?sourcemaps',
options: {
minimize: prod,
sourceMap: !prod
}
},
{
loader: 'postcss-loader',
options: {
plugins: function () {
return [
require('autoprefixer')
];
}
}
},
{
loader: 'sass-loader'
}
]
})
},
{
test: /\.(ttf|eot|woff(2)?)(\?[a-z0-9=&.]+)?$/,
loader: 'file-loader?name=../../fonts/[name].[ext]'
},
{
test: /\.(ico|svg|jpeg|jpg|png)(\?[a-z0-9=&.]+)?$/,
loader: 'file-loader?name=../../[path][name].[ext]'
},
],
},
resolve: {
alias: {
'matchHeight': path.resolve(__dirname, 'node_modules/jquery-match-height/dist/jquery.matchHeight.js'),
'videoJS': path.resolve(__dirname, 'node_modules/video.js/dist/video.min')
}
},
watch: watchOption,
plugins: ((prod) => {
let plugins = [
new ExtractTextPlugin('../../css/build/styles.css'),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
}),
new webpack.ProvidePlugin({
'videojs': 'videoJS',
'window.videojs': 'videoJS'
})
];
if (prod) {
plugins.push(new UglifyJSPlugin({
compress: {
warnings: false
},
mangle: {
except: ['$', 'exports', 'require', 'import']
}
}));
}
return plugins;
})(prod)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment