Skip to content

Instantly share code, notes, and snippets.

@keeth
Last active Apr 8, 2020
Embed
What would you like to do?
Minimal Babel Webpack with dev server
{ "presets": ["@babel/preset-env"] }
/dist
/node_modules
yarn init
yarn add -D @babel/core @babel/preset-env babel-loader html-webpack-plugin webpack webpack-cli webpack-dev-server
{
"scripts": {
"dev": "webpack-dev-server --disable-host-check",
"build": "NODE_ENV=production webpack"
}
}
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const mode = process.env.NODE_ENV || 'development';
const dev = mode === 'development';
const config = {
mode,
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
],
},
};
if (dev) {
config.plugins = [new HtmlWebpackPlugin()];
config.devtool = 'cheap-module-eval-source-map';
config.devServer = {
historyApiFallback: true,
stats: 'minimal',
};
config.watch = true;
}
module.exports = config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment