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

120 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-09-05 17:44:09 +02:00
const Webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
2020-09-05 17:44:09 +02:00
const HtmlWebpackPlugin = require("html-webpack-plugin");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const path = require("path");
const join = (...paths) => path.join(__dirname, ...paths);
2020-09-13 10:22:12 +02:00
module.exports = (env, { mode, watch }) => ({
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: "",
},
2020-09-10 00:04:48 +02:00
watch,
2020-09-05 17:44:09 +02:00
performance: {
hints: false,
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"],
},
},
},
{
2020-09-10 00:04:48 +02:00
test: /\.(png|jpg|svg)$/,
2020-09-05 17:44:09 +02:00
use: [
{
2020-09-10 00:04:48 +02:00
loader: "file-loader",
2020-09-05 17:44:09 +02:00
options: {
2020-09-13 10:22:12 +02:00
name: "[name].[ext]",
outputPath: "images",
2020-09-10 00:04:48 +02:00
},
},
],
},
{
test: /\.(woff|woff2|ttf|eot)$/,
use: [
{
loader: "file-loader",
options: {
2020-09-13 10:22:12 +02:00
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
},
},
{
loader: "postcss-loader",
options: {
config: {
path: "postcss.config.js",
2020-09-05 17:44:09 +02:00
},
},
},
],
2020-09-05 17:44:09 +02:00
},
],
},
optimization: {
splitChunks: {
name: "vendor",
minChunks: 2,
},
minimizer: [
new UglifyJsPlugin({
sourceMap: true,
}),
],
},
plugins: [
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [join("static/assets")],
2020-09-13 10:22:12 +02:00
cleanAfterEveryBuildPatterns: [
"!images/**/*",
"!fonts/**/*",
// Remove unused file for a production build.
mode === "production" && join("static/assets/style.js"),
],
verbose: true,
}),
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css",
}),
],
});