homepage/config/webpack.common.js

65 lines
1.8 KiB
JavaScript
Raw Permalink Normal View History

2023-03-14 07:16:12 +00:00
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const paths = require('./paths')
2023-03-16 07:54:45 +00:00
const path = require('path')
2023-03-14 07:16:12 +00:00
module.exports = {
// Where webpack looks to start building the bundle
2023-03-16 07:54:45 +00:00
entry: {
app: './_assets/index.js'
2023-03-14 07:16:12 +00:00
},
// Customize the webpack build process
plugins: [
// Removes/cleans build folders and unused assets when rebuilding
2023-03-16 07:54:45 +00:00
// new CleanWebpackPlugin(),
2023-03-14 07:16:12 +00:00
// Copies files from target to destination folder
new CopyWebpackPlugin({
patterns: [
{
from: paths.public,
2023-03-16 07:54:45 +00:00
to: paths.build,
2023-03-14 07:16:12 +00:00
globOptions: {
ignore: ['*.DS_Store'],
},
noErrorOnMissing: true,
},
],
}),
// Generates an HTML file from a template
// Generates deprecation warning: https://github.com/jantimon/html-webpack-plugin/issues/1501
new HtmlWebpackPlugin({
2023-03-15 09:04:46 +00:00
// favicon: paths.src + '/images/favicon.png',
2023-03-16 07:54:45 +00:00
template: './_assets/template.html', // template file
filename: '../src/_layouts/default.html' // output file
2023-03-14 07:16:12 +00:00
}),
],
// Determine how modules within the project are treated
module: {
rules: [
// JavaScript: Use Babel to transpile JavaScript files
{ test: /\.js$/, use: ['babel-loader'] },
// Images: Copy image files to build folder
{ test: /\.(?:ico|gif|png|jpg|jpeg)$/i, type: 'asset/resource' },
// Fonts and SVGs: Inline files
{ test: /\.(woff(2)?|eot|ttf|otf|svg|)$/, type: 'asset/inline' },
],
},
resolve: {
modules: [paths.src, 'node_modules'],
extensions: ['.js', '.jsx', '.json'],
alias: {
'@': paths.src,
assets: paths.public,
},
},
}