Skip to content

Instantly share code, notes, and snippets.

@gitexec
Created July 26, 2018 01:30
Show Gist options
  • Save gitexec/cfbcea00719dd83efdab94024e55829c to your computer and use it in GitHub Desktop.
Save gitexec/cfbcea00719dd83efdab94024e55829c to your computer and use it in GitHub Desktop.
Simple Production ready webpack file
'use strict';
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
module.exports = function (env) {
let outputFile = 'bundle';
const plugins = [
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env)
}),
new webpack.optimize.OccurrenceOrderPlugin(),
new HtmlWebpackPlugin({
template: 'public/index.html'
})
];
if (env === 'production') {
plugins.push(new webpack.optimize.UglifyJsPlugin(
{
minimize: true,
compress: {
warnings: false
},
mangle: true
}
));
outputFile = outputFile.toLowerCase() + '.min.js';
} else {
outputFile = outputFile.toLowerCase() + '.js';
}
const config = {
entry: './docs/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: outputFile
},
module: {
rules: [
{ test: /\.(js)$/, use: 'babel-loader', exclude: /node_modules/ },
{ test: /\..*css$/,use: ['style-loader', 'css-loader', 'sass-loader']},
{ test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file-loader'},
{ test: /\.(woff|woff2)$/, loader: 'url-loader?prefix=font/&limit=5000' },
{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/octet-stream' },
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=image/svg+xml' },
{ test: /\.png(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=image/png' },
{ test: /\.gif(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=image/gif' }
]
},
resolve: {
alias: {
mdbreact: path.resolve('./src/index')
},
extensions: ['.js', '.json']
},
plugins: plugins
};
return config;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment