Created
January 19, 2018 01:14
-
-
Save Hebilicious/fa4fde55171f4ebffa3b93a51e6ab796 to your computer and use it in GitHub Desktop.
Webpack & Node 2018 Starter Config
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
/** | |
* 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