Skip to content

Commit ede7c30

Browse files
committed
Add cache-busting content hash to JS filename
The scratch directory webpack config now dynamically injects a script tag and includes a content hash in the scratch.js filename, e.g. scratch.dc000fc4af51426aea0c.js. We're hoping that this will bust the Cloudflare cache whenever the source, `scratch/src/index.jsx`, changes.
1 parent b422e06 commit ede7c30

File tree

5 files changed

+271
-11
lines changed

5 files changed

+271
-11
lines changed

scratch/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@babel/preset-react": "7.14.5",
2020
"@webpack-cli/generators": "^3.0.7",
2121
"babel-loader": "8.2.2",
22+
"html-webpack-plugin": "^5.6.3",
2223
"webpack": "^5.97.1",
2324
"webpack-cli": "^6.0.1"
2425
},

scratch/webpack.config.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
// Generated using webpack-cli https://github.com/webpack/webpack-cli
22

33
const path = require("path");
4+
const HtmlWebpackPlugin = require("html-webpack-plugin");
45

56
const isProduction = process.env.NODE_ENV == "production";
67

78
const config = {
89
entry: "./src/index.jsx",
910
output: {
11+
filename: 'scratch.[contenthash].js',
1012
path: path.resolve(__dirname, "dist"),
1113
},
1214
optimization: {
1315
minimize: false
1416
},
1517
plugins: [
16-
// Add your plugins here
17-
// Learn more about plugins from https://webpack.js.org/configuration/plugins/
18+
new HtmlWebpackPlugin({
19+
inject: "head",
20+
template: "index.html",
21+
filename: "scratch-component.html",
22+
}),
1823
],
1924
module: {
2025
rules: [

0 commit comments

Comments
 (0)