Skip to content
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

introduce support for <base> (matching <title> and <meta>) #1160

Merged
merged 1 commit into from Feb 17, 2019
Merged

introduce support for <base> (matching <title> and <meta>) #1160

merged 1 commit into from Feb 17, 2019

Conversation

atstp
Copy link
Contributor

@atstp atstp commented Feb 7, 2019

this will let users inject a base tag in a manner similar to the current implementation for title and meta.

It also includes docs along with two new tests (adds a base tag with attributes and adds a base tag short syntax) for the introduced features.

I didn't see a contributing guide, so if you have any other questions or requests just let me know.

@atstp atstp changed the title introduce support for <base> introduce support for <base> (matching <title> and <meta ...>) Feb 7, 2019
@atstp atstp changed the title introduce support for <base> (matching <title> and <meta ...>) introduce support for <base> (matching <title> and <meta>) Feb 7, 2019
@jantimon
Copy link
Owner

jantimon commented Feb 7, 2019

Why wouldn’t that be possible with the webpack publicPath option or a custom template?

@atstp
Copy link
Contributor Author

atstp commented Feb 7, 2019

base and publicPath

It's not possible with publicPath because base, aside from a small scenario, serves a different role. They are similar in that they both can affect how paths are interpreted, but that's about it. How they do it, what they can affect, and the context they work in are all different. Here's a few significant differences:

  • Webpack's publicPath sets a prefix string only for assets that webpack manages.
  • The base tag's href determines how all relative urls are resolved, including relative hyperlinks.
  • There's also base's target attribute. If it's set, it specifies the default browsing context when navigating via links and forms (e.g. setting target=_blank in base will cause links to open in a new tab).

first-class support vs. templates vs. plugins

It's is possible with templates, or plugins for that matter. But, implementing it in html-webpack-plugin was cleaner and less obtuse than the alternatives.

Here's our use-case if you're curious:

  • We didn't need templates for anything else
    • Introducing a file just to get a single line seemed heavy handed
  • We use base (and sometimes its target) conditionally, depending on where we're deploying, thanks to some legacy requirements.
    • so if we did add a template it would need a bit of logic and new template plus template-logic seemed even less appealing
    • it would be nice to as much build configuration in webpack.config.js. moving decision making to templates isn't ideal.
  • We're doing it with a plugin (for now)
    • it seems goofy to hook into webpack's compilation just to add a line that doesn't involve any assets being compiled

On the user side, for each alternative above, the implementation was about as long and significantly more obtuse than implementing the same thing in html-webpack-plugin.

Alternatives aside, specifying base would fit well as an option to html-webpack-plugin in its own right. title, meta, and base are unique HTML elements: They're the only standardized head elements that are configured with a few short strings and don't load external assets. html-webpack-plugin already supports the first two (for obvious reasons); supporting base would make sense for the same reasons, and would make html-webpack-plugin's behavior consistent.

Hope it helps, and if you've got any further questions, let me know.

Copy link
Owner

@jantimon jantimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code you provide looks awesome - my only concern is if that’s a common requirement or an edge case 🤔

Do you know if base target blank is vulnerable to window opener attacks?

README.md Show resolved Hide resolved
@jantimon
Copy link
Owner

jantimon commented Feb 8, 2019

Right now this feature would not work if inject is false - I think that should be okay.. or do you think we should also add it to the default template?

@atstp
Copy link
Contributor Author

atstp commented Feb 8, 2019

Yeah, I understand your caution: the real cost comes from maintenance.

For what it's worth, you're welcome to ping me here on github if this needs attention in the future. I'll be happy to write up a patch or field questions (i'll be doing that no matter what, this PR just affects where).

It's your project though, so we'll work with whatever your final decision is.

Either way, thanks for actively maintaining this project.

@atstp
Copy link
Contributor Author

atstp commented Feb 8, 2019

I agree. The inject: false behavior seems fine as is.

@jantimon jantimon merged commit c5d4b86 into jantimon:master Feb 17, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants