hugo-theme-hello-friend/webpack.config.js

112 lines
2.5 KiB
JavaScript
Raw Normal View History

const { CleanWebpackPlugin } = require("clean-webpack-plugin");
2021-11-01 14:33:13 +01:00
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const TerserPlugin = require("terser-webpack-plugin");
2020-09-05 17:44:09 +02:00
const path = require("path");
const join = (...paths) => path.join(__dirname, ...paths);
2021-11-01 14:33:13 +01:00
module.exports = (env, { mode }) => ({
2020-09-05 17:44:09 +02:00
resolve: {
extensions: [".js", ".css"],
modules: ["assets", "node_modules"],
},
entry: {
main: [join("assets", "js", "menu.js"), join("assets", "js", "theme.js")],
prism: join("assets", "js", "prism.js"),
style: join("assets", "css", "style.css"),
2020-09-05 17:44:09 +02:00
},
output: {
filename: "[name].js",
2020-09-05 17:44:09 +02:00
path: join("static/assets"),
publicPath: "",
},
performance: {
hints: false,
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"],
},
},
},
{
2021-11-01 15:54:04 +01:00
test: /\.(png|jpg|svg)$/,
2020-09-05 17:44:09 +02:00
use: [
{
2021-11-01 15:54:04 +01:00
loader: "file-loader",
2020-09-05 17:44:09 +02:00
options: {
2021-11-01 15:54:04 +01:00
name: "[name].[ext]",
outputPath: "images",
},
},
],
},
{
test: /\.(woff|woff2|ttf|eot)$/,
use: [
{
loader: "file-loader",
options: {
name: "[name].[ext]",
outputPath: "fonts",
2020-09-05 17:44:09 +02:00
},
},
],
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
modules: {
2020-09-05 17:44:09 +02:00
localIdentName: "[local]",
},
import: true,
importLoaders: 1,
2020-09-05 17:44:09 +02:00
},
},
2021-11-01 14:33:13 +01:00
"postcss-loader",
],
2020-09-05 17:44:09 +02:00
},
2021-11-01 15:54:04 +01:00
{
test: /\.(eot|ttf|woff|woff2)$/i,
// More information here https://webpack.js.org/guides/asset-modules/
type: "asset",
},
2020-09-05 17:44:09 +02:00
],
},
optimization: {
splitChunks: {
name: "vendor",
minChunks: 2,
},
2021-11-01 14:33:13 +01:00
minimize: true,
2020-09-05 17:44:09 +02:00
minimizer: [
2021-11-01 14:33:13 +01:00
new TerserPlugin({
parallel: true,
extractComments: false,
2020-09-05 17:44:09 +02:00
}),
],
},
plugins: [
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [join("static/assets")],
2021-11-01 15:54:04 +01:00
cleanAfterEveryBuildPatterns: [join("static/assets/style.js")],
verbose: true,
}),
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css",
}),
],
});