I\'ve been trying to use webpack with a nodejs application, and the client side is going fine - a reasonably good documentation on their website + links from google search.
I want to highlight the difference from client side config:
target: 'node'
externals: [nodeExternals()]
for node.js, it doesn't make much sense to bundle node_modules/
output.libraryTarget: 'commonjs2'
without this, you cannot require('your-library')
import nodeExternals from 'webpack-node-externals'
const config = {
target: 'node',
externals: [nodeExternals()],
entry: {
'src/index': './src/index.js',
'test/index': './test/index.js'
},
output: {
path: __dirname,
filename: '[name].bundle.js',
libraryTarget: 'commonjs2'
},
module: {
rules: [{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: [
['env', {
'targets': {
'node': 'current'
}
}]
]
}
}
}]
}
}
export default [config]