-
Notifications
You must be signed in to change notification settings - Fork 817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
workbox-webpack-plugin doesn't add an entry in the array for my index.html #1692
Comments
I also have this issue, I have no index.html in my generated manifest but I use webpack to generate one. Did you get anywhere with this? |
No, I haven't. Had to resort to using the Workbox CLI after running Webpack. |
I've resolved my issue, it was to do with the ordering of webpack plugins, it seems the Workbox plugin must be last for it to pick up on some files. Hope this helps with your issue. |
Hey @Richienb |
All of the code including the Webpack configuration was given in the original comment in step 1 of reproducing the problem. |
Oh true I didn't see the GitHub repo |
Given that the steps in #1692 (comment) were not able to reproduce the issue, I'm going to close this for now. If there are a different set of steps that can reproduce the issue, please let us know and I'll reopen. |
Yes this is painfull. I worked out previously in the same issue. I'm not even sure, but i remember this is a html-webpack-plugin problem. But whatever, i found a solution to this. This will add try thisInject a HTML balise Work with webpack This will force your template to change every build and You should also use
// htmlWebpackPlugin options used
{
template: 'src/index.ejs',
filename: 'index.html',
minify: true,
xhtml: true,
...
} To make your template with other template engine : https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md My production webpack plugins array config : ...
plugins: [
new CleanWebpackPlugin([configInstance.path.relativeFolderBuild], {
root: configInstance.path.root
}),
new CircularDependencyPlugin({
exclude: /node_modules/,
failOnError: true,
allowAsyncCycles: true,
cwd: process.cwd()
}),
new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /en|fr/),
new webpack.DefinePlugin(configInstance.exported_variables),
new webpack.optimize.MinChunkSizePlugin({
minChunkSize: 20000
}),
new webpack.HashedModuleIdsPlugin(),
new HtmlWebPackPlugin({
meta: configInstance.config.html.meta,
title: configInstance.config.html.title,
template: configInstance.path.html,
filename: 'index.html',
favicon: configInstance.favicon,
minify: true,
xhtml: true
}),
new WebpackPwaManifest({
name: configInstance.config.pwa.name,
short_name: configInstance.config.pwa.short_name,
description: configInstance.config.html.meta.description,
display: configInstance.config.pwa.display,
theme_color: configInstance.config.pwa.theme_color,
background_color: configInstance.config.pwa.background_color,
inject: true,
fingerprints: true,
start_url: '.',
ios: true,
icons: configInstance.pwaIcons
}),
new MiniCssExtractPlugin({
filename: configInstance.path.cssFileName,
chunkFilename: configInstance.path.cssChunkFileName,
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true
}
}),
new webpack.BannerPlugin({
banner: configInstance.banner
}),
new CopyWebpackPlugin(
[
{
from: path.join(configInstance.path.public, 'humans.txt'),
to: configInstance.path.toServe,
transform: content => `${content} Last update: ${configInstance.startBuildTime}`,
cache: true
}
],
{ debug: 'warning' }
),
new ResourceHintWebpackPlugin(),
new WebpackMonitor(configInstance.monitor),
new BundleAnalyzerPlugin(configInstance.analyzer),
new WorkboxPlugin.InjectManifest({
swSrc: path.join(configInstance.path.public, 'service-worker.js'),
swDest: 'service-worker.js',
importWorkboxFrom: 'cdn'
})
]
... My <!DOCTYPE html>
<html lang="fr" prefix="og: http://ogp.me/ns#">
<head>
<base href="/" />
<meta charset="utf-8" />
<title><%= htmlWebpackPlugin.options.title %></title>
<link rel="author" href="/humans.txt" />
<meta name="hash" content="<%= webpack.hash %>" />
</head>
<body>
<noscript>
You need to enable JavaScript to run the application :
<a src="https://www.enable-javascript.com/">https://www.enable-javascript.com/</a>
</noscript>
<div id="app"></div>
</body>
</html>
The resulting precache-manifest build by |
Thanks @blephy , I've been searching for days to find a solution! Adding the meta tag to my index.html fixed my problem with workbox v4 serving outdated precached files. For anyone else running into this issue, I'm using GenerateSW with webpack v4 and workbox 4.3.1. |
I have the same issue with |
Yep, you can use this #2299 (comment) |
@blephy thank you, that was the missing link for me. I had to adjust for webpack5, but you got me close enough I could connect the dots from there. For anyone visiting this using webpack5 and htmlWebpackPlugin 5.x the setup is a little different to access the hash in your template now as the options have changed a fair bit and you need to inject the hash using customized templateParameters:
<meta name="hash" content="<%= hash %>" /> |
Library Affected:
workbox-webpack-plugin
Browser & Platform:
irrelevant
Issue or Feature Request Description:
When I use workbox-webpack-plugin's injectmanifest command in Webpack 3 and inspect the generated file, the output looks something like this:
The problem is that webpack doesn't cache my index.html despite being specified in the
webpack.config.js
file.Reproduction steps:
Step 1: Cloning
The source code is here on GitHub but you can reproduce it locally by running:
git clone https://github.com/Richienb/richienb.github.io.git git checkout 89bf8314fee14a8f994915d26db3a80b6df0589a .
Step 2: Navigate to directory
Fairly simple:
Step 3: Installation
This repository uses yarn so for this step, install yarn then install all the packages in a development environment
npm install -g yarn yarn install --production false
Step 4: Locally host the site
In this step, tell webpack-dev-server to host a local server of the site
Step 5: Find the generated file
Inspect the command line output and find the file starting with
precache-manifest
. An example is pointed out below:Step 6: Navigate to the site
Navigate to the generated file. For the example above, you would navigate to
127.0.0.1/precache-manifest.15dc3d014eed9db2538054395c7d9c0b.js
.Step 7: View the resulting file
The file will look similar to this:
As you can see, an entry for
index.html
clearly does not exist but in thewebpack.config.js
it is clearly declared. That is the problem.The text was updated successfully, but these errors were encountered: