Last active
February 23, 2021 17:52
-
-
Save icebob/a37de30311fbfd770eaf5027bf779f5c to your computer and use it in GitHub Desktop.
NodeJS server/backend bundle with webpack
This file contains 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
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 | |
}) | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on http://jlongster.com/Backend-Apps-with-Webpack--Part-I