-
-
Notifications
You must be signed in to change notification settings - Fork 205
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
Support <link href=""/> #17
Comments
Ok, so getting interesting results. I'd like this:
layout:
main.js
loader:
And the output to be:
where index.html has the path to the icon properly inserted. But I've tried a variety of combinations. Without the |
You cannot combine html-loader and file-loader this way. You can send a PR adding this syntax, but restrict it to known |
I can't get the build to output the html and the png together, even without file-loader renaming. That should be possible, right? Even just using |
+1 |
8 similar comments
👍 |
👍 |
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
Just for reference, I ended up using react helmet in my solutions. :) |
👍 Also, what about |
Sounds reasonable. We probably need a more configurable solution. I think, there is an infinite number of possible tags which reference other files :) |
Very true, a custom function that gets passed all the tags would be really nice! (Similar to how postcss works maybe?) |
This is still a prerelease, but it's almost finished so updating it on this branch is no problem. Thanks to @jantimon for the amazing work. v2 lets you load html files with loaders, so we now use html-loader to load the index.html file, which automatically require()s all img tags specified in the HTML file. This doesn't yet solve the meta image problem, but I've added to an issue in the html-loader repo and hope that this will be resolved soon! See webpack-contrib/html-loader#17
Currently I'm doing the following trick: {
test: /\.html$/,
loader: ExtractTextPlugin.extract('html?attrs=link:href')
}, |
@dazzz I'm pretty sure that's not a trick, that's intended usage of that option, but we need a better solution for tags like |
+1 |
Until there is no other solution, interpolation syntax may be used (with interpolate flag turned on): <link rel="shortcut icon" href="${require('./favicon.ico')}">
<meta property="og:image" content="${require('./someimage.jpg')}" /> And, of course, loaders should be configured appropriately: ...
module: {
loaders: [
...
{
test: /\.(ico|png|eot|svg|ttf|woff|woff2)$/,
loader: 'file?name=[name]-[hash:6].[ext]'
},
...
]
},
... |
posthtml maybe :) ? |
@vbarbarosh That's actually pretty interesting, what is the result like? |
@resistdesign As expected: |
Can we add an option to treat all attribute values starting with |
@gaearon Interesting, does that work for icons, js, css, manifest and all that? It just might. You have to also consider So what would be the result, it would run the file through a loader and return the new path/URL? The loader CAN'T return code or content because the result will be set as the value of an attribute. I mean it could be a data URL but that seems problematic for code and such I would think. |
Currently, we have a mixture between sane defaults (all This would be nice, because it reduces the need to configure things and many instances will just work out of the box. But we would still need to provide a way to exclude certain attributes because there are always exceptions and people will come and say: "Oh, webpack should not handle these kind of attributes". |
FYI we decided to stop using html-loader completely and just tell people to maintain a "public" folder for assets that go with HTML. Worked great for us. The biggest issue I couldn't figure out how to resolve are JSON files. When used in |
Totally understandable. It doesn't make sense to handle JSONs as javascript modules when referenced from an HTML file. Sometimes, it makes sense to express that as a directory-specific rule (like "all JSONs inside this directory should be emitted as separate files"), but the current way of configuring loaders lacks this type of expression. |
Webpack 2 has more powerful way to configure these loader rules. Now you can define loader rules based on the "issuer" which is the module that contains the import statement. Your use-case would be solved like this: module: {
rules: [
{
test: /\.json$/,
issuer: /\.html$/,
loader: "file-loader"
}
]
} |
Very neat. |
I have solve it like this,but not pure html-loader,I make it with html-webpack-plugin <link rel="apple-touch-icon" sizes="114*114" href="<%= require('../assets/images/logo.png') %>">
<link rel="icon" type="image/x-icon" href="<%= require('../assets/images/favicon.ico') %>" sizes="48x48"> loaders = [
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
exclude: '/nolimit/',
loader: 'url-loader',
query: {
limit: 10,
name: utils.assetsPath('img/[name].[hash:6].[ext]')
}
},
{
test: /.(ico)$/,
loader: 'file?name=[name].[hash:6].[ext]'
}
] then the finally rendered html like this <link rel="apple-touch-icon" sizes="114*114" href="static/img/logo.32893a.png">
<link rel="icon" type="image/x-icon" href="favicon.aacd9e.ico" sizes="48x48"> |
@baotang I doubt this will work with the html-loader. For it to work set somehwere in the WebPack config:
And then:
This works for me. |
I came here from google. https://www.npmjs.com/package/html-loader attrs: ['img:src', 'link:href'] |
This is still a prerelease, but it's almost finished so updating it on this branch is no problem. Thanks to @jantimon for the amazing work. v2 lets you load html files with loaders, so we now use html-loader to load the index.html file, which automatically require()s all img tags specified in the HTML file. This doesn't yet solve the meta image problem, but I've added to an issue in the html-loader repo and hope that this will be resolved soon! See webpack-contrib/html-loader#17
By default `html-loader@0.x` has a default `attrs` of `['img:src']`, which means only `<img src="...">` tags are followed when parsing the HTML: https://github.com/webpack-contrib/html-loader/blob/v0.5.5/README.md#usage https://github.com/webpack-contrib/html-loader/blob/v0.5.5/index.js#L29 With this change, favicons are included too, and have all the benefits of being included in the webpack build - such as being being inlined by url-loader (if small enough), or else being copied to the output directory automatically and given hashed filenames. This matches the default that will be used in `html-loader` v1.0.0: webpack-contrib/html-loader#17 ...and saves projects from having to resort to the manual Neutrino API to adjust the options used by `html-loader` (see #865).
This is still a prerelease, but it's almost finished so updating it on this branch is no problem. Thanks to @jantimon for the amazing work. v2 lets you load html files with loaders, so we now use html-loader to load the index.html file, which automatically require()s all img tags specified in the HTML file. This doesn't yet solve the meta image problem, but I've added to an issue in the html-loader repo and hope that this will be resolved soon! See webpack-contrib/html-loader#17
Hi, it is not very clear to me, is
But does not get picked up by webpack. |
I have all the suggestions from this topic, none has worked. Probably it is because I am on webpack 5, and many things have changed since then. I have ended up adding |
@ChoppinBlockParty could you humour me with the complete webpack config snippet I need to do this using todays tool versions? Thanks |
@trullock, and for anybody who may come across this in the future if it hasn't been fixed, this works as of webpack 5.21.2:
|
This is still a prerelease, but it's almost finished so updating it on this branch is no problem. Thanks to @jantimon for the amazing work. v2 lets you load html files with loaders, so we now use html-loader to load the index.html file, which automatically require()s all img tags specified in the HTML file. This doesn't yet solve the meta image problem, but I've added to an issue in the html-loader repo and hope that this will be resolved soon! See webpack-contrib/html-loader#17
This is still a prerelease, but it's almost finished so updating it on this branch is no problem. Thanks to @jantimon for the amazing work. v2 lets you load html files with loaders, so we now use html-loader to load the index.html file, which automatically require()s all img tags specified in the HTML file. This doesn't yet solve the meta image problem, but I've added to an issue in the html-loader repo and hope that this will be resolved soon! See webpack-contrib/html-loader#17
This is still a prerelease, but it's almost finished so updating it on this branch is no problem. Thanks to @jantimon for the amazing work. v2 lets you load html files with loaders, so we now use html-loader to load the index.html file, which automatically require()s all img tags specified in the HTML file. This doesn't yet solve the meta image problem, but I've added to an issue in the html-loader repo and hope that this will be resolved soon! See webpack-contrib/html-loader#17
This is still a prerelease, but it's almost finished so updating it on this branch is no problem. Thanks to @jantimon for the amazing work. v2 lets you load html files with loaders, so we now use html-loader to load the index.html file, which automatically require()s all img tags specified in the HTML file. This doesn't yet solve the meta image problem, but I've added to an issue in the html-loader repo and hope that this will be resolved soon! See webpack-contrib/html-loader#17
This is still a prerelease, but it's almost finished so updating it on this branch is no problem. Thanks to @jantimon for the amazing work. v2 lets you load html files with loaders, so we now use html-loader to load the index.html file, which automatically require()s all img tags specified in the HTML file. This doesn't yet solve the meta image problem, but I've added to an issue in the html-loader repo and hope that this will be resolved soon! See webpack-contrib/html-loader#17
This is still a prerelease, but it's almost finished so updating it on this branch is no problem. Thanks to @jantimon for the amazing work. v2 lets you load html files with loaders, so we now use html-loader to load the index.html file, which automatically require()s all img tags specified in the HTML file. This doesn't yet solve the meta image problem, but I've added to an issue in the html-loader repo and hope that this will be resolved soon! See webpack-contrib/html-loader#17
This is still a prerelease, but it's almost finished so updating it on this branch is no problem. Thanks to @jantimon for the amazing work. v2 lets you load html files with loaders, so we now use html-loader to load the index.html file, which automatically require()s all img tags specified in the HTML file. This doesn't yet solve the meta image problem, but I've added to an issue in the html-loader repo and hope that this will be resolved soon! See webpack-contrib/html-loader#17
Wanting to use it with a template that has this in the
head
tag:But it doesn't seem to pick it up! The syntax seems simple enough to add.. want a pull request?
The text was updated successfully, but these errors were encountered: