Skip to content

Instantly share code, notes, and snippets.

@ankkho
Created January 11, 2018 13:52
Show Gist options
  • Save ankkho/55b5180c964df848a503a896c962f311 to your computer and use it in GitHub Desktop.
Save ankkho/55b5180c964df848a503a896c962f311 to your computer and use it in GitHub Desktop.
Production ready webpack-config for serverless functions -- suggestions are welcome!
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');
const CompressionPlugin = require('compression-webpack-plugin')
const path = require('path');
module.exports = {
entry: ['babel-polyfill', './handler.js'],
target: 'node',
externals: [nodeExternals()],
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, './.webpack'),
filename: 'handler.js',
sourceMapFilename: 'handler.map.js',
},
devtool: 'eval',
module: {
loaders: [
{
test: /\.js?/,
exclude: ['node_modules'],
loader: 'babel-loader',
query: {
cacheDirectory: true,
plugins: [
'babel-plugin-root-import', 'transform-runtime', 'transform-regenerator',
],
presets: ['es2015', 'stage-0'],
},
},
],
},
plugins: [
// new webpack.IgnorePlugin(/aws-sdk/),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.optimize.UglifyJsPlugin({
mangle: true,
comments: false,
compress: {
warnings: false, // Suppress uglification warnings
pure_getters: true,
unsafe: true,
unsafe_comps: true,
},
output: {
comments: false,
},
exclude: [/\.min\.js$/gi], // skip pre-minified libs
}),
new CompressionPlugin({ asset: '[path].gz[query]', algorithm: 'gzip', test: /\.js/, threshold: 10240, minRatio: 0 }),
],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment