Skip to content

Instantly share code, notes, and snippets.

@icebob
Last active February 23, 2021 17:52
Show Gist options
  • Save icebob/a37de30311fbfd770eaf5027bf779f5c to your computer and use it in GitHub Desktop.
Save icebob/a37de30311fbfd770eaf5027bf779f5c to your computer and use it in GitHub Desktop.
NodeJS server/backend bundle with webpack
var webpack = require('webpack');
var path = require('path');
var fs = require('fs');
var nodeModules = {};
fs.readdirSync('node_modules')
.filter(function(x) {
return ['.bin'].indexOf(x) === -1;
})
.forEach(function(mod) {
nodeModules[mod] = 'commonjs ' + mod;
});
module.exports = {
target: 'node',
node: {
console: false,
global: false,
process: false,
Buffer: false,
__filename: true,
__dirname: true
},
entry: './index.js',
output: {
path: __dirname,
filename: 'bundle.js'
},
externals: nodeModules,
plugins: [
new webpack.IgnorePlugin(/\.(css|less)$/),
new webpack.BannerPlugin('require("source-map-support").install();', {
raw: true,
entryOnly: false
})
],
devtool: 'sourcemap',
module: {
loaders: [
{ test: /\.json$/, loader: "json-loader" }
]
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
mangle: true
})
]
}
@icebob
Copy link
Author

icebob commented Sep 6, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment