paco_sako/webpack.config.js

115 lines
2.8 KiB
JavaScript

const path = require('path');
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { InjectManifest } = require('workbox-webpack-plugin');
module.exports = {
mode: 'production',
entry: {
index: './index.js'
},
output: {
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'public'),
publicPath: ''
},
module: {
rules: [
{
test: /\.css$/,
loaders: [MiniCssExtractPlugin.loader, "css-loader"]
},
{
test: { and: [ /\.(jpe?g|png|gif|svg|ttf|eot|woff2?)$/i, /jquery-ui/i ] },
loader: "file-loader",
options: {
name: '[name].[contenthash].[ext]',
outputPath: 'assets/jquery-ui'
}
},
{
test: { and: [ /\.(jpe?g|png|gif|mp3|wav|ttf|eot|woff2?)$/i, { not: [ /jquery-ui/i ] } ] },
loader: "file-loader",
options: {
name: '[path][name].[contenthash].[ext]',
outputPath: 'assets/'
}
},
{
test: { and: [ /\.svg$/i, { not: [ /jquery-ui/i ] } ] },
use: [
{
loader: "file-loader",
options: {
name: '[path][name].[contenthash].[ext]',
outputPath: 'assets/'
}
},
{
loader: "svgo-loader",
options: {
plugins: [
{ cleanupIDs: false }
]
}
}
]
},
{
test: /(^|[/\\])manifest.js$/i,
use: [
{
loader: "file-loader",
options: {
name: "[path]manifest.webmanifest",
},
},
"extract-loader"
],
},
]
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
title: 'Paco Ŝako',
template: 'index.html',
}),
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
chunkFilename: '[id].[contenthash].css',
}),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery'",
"window.$": "jquery"
}),
new CopyPlugin([
{ from: '.htaccess' },
]),
new InjectManifest({
swSrc: './sw.js',
dontCacheBustURLsMatching: /\.[0-9a-f]{16,}\.\w{2,4}$/,
exclude: [ /(^|[/\\])\.htaccess$/ ],
}),
],
optimization: {
moduleIds: 'hashed',
splitChunks: {
chunks: 'all',
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
},
},
},
},
};
/* vim:set expandtab sw=2 ts=8: */