51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
// generate a HTML5 file including all webpack bundles in the body using script tags
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
// path is used to resolve properly across the OS
|
|
const path = require('path');
|
|
|
|
module.exports = {
|
|
// bundle *.js from this entry point
|
|
entry: path.resolve(__dirname, '../src/index.jsx'),
|
|
// create output file to be linked to index.html
|
|
output: {
|
|
filename: '[name].bundle.js',
|
|
path: path.resolve(__dirname, '../dist'),
|
|
clean: true,
|
|
},
|
|
module: {
|
|
rules: [
|
|
{
|
|
// test all *.js using babel-loader
|
|
// test all *.jsx (e.g. React.js) using babel-loader
|
|
test: /\.(js|jsx)$/,
|
|
exclude: /node_modules/,
|
|
include: path.resolve(__dirname, '../src'),
|
|
use: {
|
|
loader: 'babel-loader',
|
|
options: {
|
|
presets: [
|
|
'@babel/preset-env',
|
|
'@babel/preset-react',
|
|
],
|
|
},
|
|
},
|
|
},
|
|
{
|
|
// test all *.css using style-loader and css-loader
|
|
test: /\.css$/i,
|
|
use: ['style-loader', 'css-loader'],
|
|
},
|
|
],
|
|
},
|
|
resolve: {
|
|
extensions: ['*', '.js', '.jsx'],
|
|
},
|
|
plugins: [
|
|
// create a plugin instance so that you can use it several times anywhere
|
|
new HtmlWebpackPlugin({
|
|
title: 'Production',
|
|
template: path.resolve(__dirname, '../public/index.html'),
|
|
}),
|
|
],
|
|
};
|