Skip to content

Instantly share code, notes, and snippets.

@teamco
Created December 17, 2019 20:31
Show Gist options
  • Select an option

  • Save teamco/8ec5b0e72902bf25310476fa558ec65c to your computer and use it in GitHub Desktop.

Select an option

Save teamco/8ec5b0e72902bf25310476fa558ec65c to your computer and use it in GitHub Desktop.
webpack.dev.config.js
const path = require('path');
const webpack = require('webpack');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const StartServerPlugin = require('start-server-webpack-plugin');
const NodemonPlugin = require('nodemon-webpack-plugin');
const SimpleProgressWebpackPlugin = require('simple-progress-webpack-plugin');
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
const config = {
entry: {
main: [
'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000',
'./app/javascript/packs/development.js'
]
},
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/',
filename: '[name].js',
libraryTarget: 'umd',
globalObject: `(typeof self !== 'undefined' ? self : this)`
},
mode: 'development',
target: 'web',
devtool: 'source-map',
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
emitWarning: true,
failOnError: false,
failOnWarning: false
}
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
// Loads the javacript into html template provided.
// Entry point is set below in HtmlWebPackPlugin in Plugins
test: /\.html$/,
use: [
{
loader: 'html-loader'
//options: { minimize: true }
}
]
},
{
test: /\.s[ac]ss$/i,
use: [
'style-loader',
'css-loader',
'resolve-url-loader',
{
loader: 'sass-loader?sourceMap',
options: {
// Prefer `dart-sass`
sourceMap: true,
implementation: require('sass')
}
}
]
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff'
},
{
test: /\.(png|ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader'
}
]
},
plugins: [
new HtmlWebPackPlugin({
template: './app/javascript/packs/html/index.html',
filename: './index.html',
excludeChunks: ['server']
}),
new webpack.HotModuleReplacementPlugin(),
new NodemonPlugin({}),
new SimpleProgressWebpackPlugin(),
new FriendlyErrorsWebpackPlugin(),
new StartServerPlugin({
name: 'main.js',
signal: true,
nodeArgs: ['--inspect']
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
}),
new CleanWebpackPlugin()
]
};
module.exports = config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment