Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Webpack & Node 2018 Starter Config
/**
* Inspired by https://jlongster.com/Backend-Apps-with-Webpack--Part-I
*/
const webpack = require('webpack');
const path = require('path');
const fs = require('fs');
//Use nodemon to livereload when using webpack --watch.
const NodemonPlugin = require('nodemon-webpack-plugin');
//Ignore node externals when bundling
const nodeExternals = require('webpack-node-externals');
module.exports = {
entry: 'app.js',
//The Banner plugin adds sourcemaps https://www.npmjs.com/package/source-map-support
plugins: [
new NodemonPlugin(),
new webpack.BannerPlugin({banner:'require("source-map-support").install();', raw: true, entryOnly: false })
],
module: {
//Add babel , and exclude directories that shouldn't be touched by babel. It will read a .babelrc.
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader'
}
}
]
},
//Node options
target: 'node',
node:{
console:true
},
output: {
filename: 'app.js',
path: path.resolve(__dirname, 'dist')
},
externals: nodeExternals(),
devtool: 'sourcemap'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment