This repository was archived by the owner on Feb 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
This repository was archived by the owner on Feb 1, 2020. It is now read-only.
Contenthash with MiniCssExtractPlugin does not change even if content has changed #65
Copy link
Copy link
Open
Description
I'm using the contenthash in the filenames to allow long term caching:
https://webpack.js.org/guides/caching/
Unfortunately if the content is changed by the PurgeCss plugin only, for example since I have removed a usage of an class or I'm using a class which hasn't been used before, the contenthash does not change. This leads to old files being served to the users and therefore a breaking app.
The content hash changes as soon as I do an actual modification of the CSS files. My guess would be that the contenthash is calculated to early?
webpack config:
const path = require('path');
const glob = require('glob-all')
const ManifestPlugin = require('webpack-manifest-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CleanWebpackPlugin = require('clean-webpack-plugin'); //installed via npm
const PurgecssPlugin = require('purgecss-webpack-plugin');
const webpack = require('webpack');
// the path(s) that should be cleaned
let pathsToClean = [
'dist'
];
// the clean options to use
let cleanOptions = {
root: '..................../public',
verbose: true,
dry: false
};
function collectWhitelistPatterns() {
return [/^pcr-/];
}
module.exports = {
plugins: [
new CleanWebpackPlugin(pathsToClean, cleanOptions),
new ManifestPlugin(),
new PurgecssPlugin({
paths: glob.sync(['./src-js/**/*', './templates/**/*'], { nodir: true }),
whitelistPatterns: collectWhitelistPatterns,
}),
new MiniCssExtractPlugin({
filename: "[name]-[contenthash].css",
chunkFilename: "[id]-[contenthash].css"
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
})
],
entry: {
one: './src-js/index-one.js',
two: './src-js/index-two.js',
three: './src-js/index-three.js',
},
output: {
path: path.resolve(__dirname, 'public/dist'),
filename: dev?'[name]-min.js':'[name]-[contenthash]-min.js',
publicPath: "/dist/"
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "entry",
"targets": "> 0.25%, not dead",
}
]
],
"plugins": ["transform-remove-console"]
}
}
},
{
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader',
],
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
'file-loader'
]
}
]
},
externals: {
jquery: 'jQuery'
},
};
PutziSan
Metadata
Metadata
Assignees
Labels
No labels