const path = require('path'); const CleanWebpackPlugin = require('clean-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin'); const PreloadWebpackPlugin = require('preload-webpack-plugin'); module.exports = { mode: 'development', entry: './src/index.js', module: { rules: [{ test: /\.txt$/, use: 'raw-loader' }, { test: /\.html$/, use: [{ loader: 'html-loader', options: { minimize: true } }] }, { test: /\.(jpe?g|png|gif|svg)$/, use: [{ loader: 'file-loader', options: { name: '[name].[ext]', outputPath: 'images/', publicPath: 'images/' } }] }, { test: /\.(woff|woff2|ttf|otf)$/, use: [{ loader: 'file-loader', options: { name: '[name].[ext]', outputPath: 'fonts/', publicPath: 'fonts/' } }] }, { test: /\.(sa|sc|c)ss$/, use: [ MiniCssExtractPlugin.loader, { loader: 'css-loader', options: { sourceMap: true } }, { loader: 'postcss-loader', options: { sourceMap: true } }, { loader: 'sass-loader', options: { sourceMap: true } } ] }, { test: /\.js$/, exclude: /(node_modules)/, use: { loader: 'babel-loader', options: { presets: ['@babel/preset-env'] } } } ] }, plugins: [ new CleanWebpackPlugin(['dist']), new HtmlWebpackPlugin({ title: 'tris-webpack-boilerplate', filename: 'index.html', template: './src/index.html', inject: 'head' }), new PreloadWebpackPlugin({ rel: 'preload', as(entry) { if (/\.(woff|woff2|ttf|otf)$/.test(entry)) return 'font'; }, fileWhitelist: [/\.(woff|woff2|ttf|otf)$/], include: 'allAssets' }), new ScriptExtHtmlWebpackPlugin({ defaultAttribute: 'defer' }), new MiniCssExtractPlugin({ filename: 'webpack-bundle.css', chunkFilename: '[id].css' }) ], externals: { $: 'jquery', jquery: 'jQuery', 'window.$': 'jquery', }, output: { filename: 'webpack-bundle.js', path: path.resolve(__dirname, 'dist') } };