We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I try to inline webpack manifest but with the following config is not working:
module.exports = { optimization: { runtimeChunk: { name: 'runtime' } }, plugins: [ new HtmlWebpackPlugin({ inject: false, template: require('html-webpack-template'), inlineManifestWebpackName: 'runtime' }), new InlineManifestWebpackPlugin() ] };
Note: 'runtime' is the default name for webpack manifest.
'runtime'
My devDependencies versions:
devDependencies
"html-webpack-plugin": "^3.2.0", "html-webpack-template": "^6.2.0", "inline-manifest-webpack-plugin": "^4.0.0", "webpack": "^4.10.1"
Looking inside html-webpack-template.ejs I see:
html-webpack-template.ejs
<% if (htmlWebpackPlugin.options.inlineManifestWebpackName) { %> <%= htmlWebpackPlugin.files[htmlWebpackPlugin.options.inlineManifestWebpackName] %> <% } %>
Logging htmlWebpackPlugin.files, there is no plain manifest code inside this object but only a reference to 'runtime' chunk.
htmlWebpackPlugin.files
We can use the compilation object and add the following code to the template:
compilation
webpackManifestName
<!DOCTYPE html>
<% const webpackManifestName = htmlWebpackPlugin.options.inlineManifestWebpackName ? new RegExp(htmlWebpackPlugin.options.inlineManifestWebpackName, 'g') : '' %>
inlineManifestWebpackName
<% if (webpackManifestName) { %> <script type="text/javascript"> <% const webpackManifest = htmlWebpackPlugin.files.js .filter( file => file.match(webpackManifestName) ); %> <%= compilation.assets[webpackManifest].source() %> </script> <% } %>
<% Object.keys(htmlWebpackPlugin.files.chunks) .filter(chunk => webpackManifestName ? !chunk.match(webpackManifestName) : chunk) .forEach(chunk => { if (htmlWebpackPlugin.files.jsIntegrity) { %> <script src="<%= htmlWebpackPlugin.files.chunks[chunk].entry %>" type="text/javascript" integrity="<%= htmlWebpackPlugin.files.jsIntegrity[htmlWebpackPlugin.files.js.indexOf(htmlWebpackPlugin.files.chunks[chunk].entry)] %>" crossorigin="<%= webpackConfig.output.crossOriginLoading %>"> </script> <% } else { %> <script src="<%= htmlWebpackPlugin.files.chunks[chunk].entry %>" type="text/javascript"></script> <% } %> <% }) %>
Note: InlineManifestWebpackPlugin is not strictly necessary, in this case it's used to delete runtime.js chunk in the dist/ folder.
InlineManifestWebpackPlugin
dist/
The text was updated successfully, but these errors were encountered:
I ran into this issue as well - @pldg 's solution worked with one alteration to support Webpack's publicPath config.
publicPath
<% if (webpackManifestName) { %> <script type="text/javascript"> <% const webpackManifest = htmlWebpackPlugin.files.js .filter( file => file.match(webpackManifestName) )[0] .replace(webpackConfig.output.publicPath, '') %> <%= compilation.assets[webpackManifest].source() %> </script> <% } %>
Sorry, something went wrong.
Would be nice a solution that works without adding InlineManifestWebpackPlugin to delete dist/runtime.js but for now I'm closing this issue.
Successfully merging a pull request may close this issue.
I try to inline webpack manifest but with the following config is not working:
Note:
'runtime'
is the default name for webpack manifest.My
devDependencies
versions:What's happen
Looking inside
html-webpack-template.ejs
I see:Logging
htmlWebpackPlugin.files
, there is no plain manifest code inside this object but only a reference to'runtime'
chunk.Solution
We can use the
compilation
object and add the following code to the template:webpackManifestName
above<!DOCTYPE html>
inlineManifestWebpackName
logic with a new oneNote:
InlineManifestWebpackPlugin
is not strictly necessary, in this case it's used to delete runtime.js chunk in thedist/
folder.The text was updated successfully, but these errors were encountered: