Skip to content
This repository has been archived by the owner on Apr 9, 2023. It is now read-only.

docs(README): How to handle duplicate style tags #110

Merged
merged 1 commit into from
Sep 26, 2017
Merged

docs(README): How to handle duplicate style tags #110

merged 1 commit into from
Sep 26, 2017

Conversation

o-alexandrov
Copy link
Contributor

No description provided.

@chrisvfritz chrisvfritz merged commit dbbf3b5 into chrisvfritz:master Sep 26, 2017
@edarioq
Copy link

edarioq commented Jun 24, 2018

Is this still a viable solution? Read:

Since webpack v4 the extract-text-webpack-plugin should not be used for css. Use mini-css-extract-plugin instead.

Also this problem occurs not only with CSS but with JS tags as well.

@o-alexandrov
Copy link
Contributor Author

o-alexandrov commented Jun 24, 2018

  • You should be using mini-css-extract-plugin the same way you would extract-text-webpack-plugin.
    • You should change the configuration accordingly, but the overall meaning is the same
    • Please be informed that there are still a few issues with mini-css-extract-plugin, such as this one
  • CSS and JS handling would be different and it depends on how you are using scripts in your project.
    • The config from the newest prerender-spa-plugin, postProcess, should help you to resolve your issue.

@edarioq
Copy link

edarioq commented Jun 30, 2018

The postProcess replaces everything that vueand the prerenderplugin renders into the HTML. So I can't just use it because I strip away all script tags generated in the final HTML.

@o-alexandrov
Copy link
Contributor Author

Please be informed that postProcess can do absolutely whatever you'd like.
Virtually unlimited manipulations on the result as you define what you would like to do with the produced HTML via a function.

Most common one is to use regex to find what you would like to remove and do it.

@edarioq
Copy link

edarioq commented Jul 1, 2018

Thanks @o-alexandrov but that suggestion removes all the script tags. All of them, even the ones not duplicated. Could you point me to a working example of what you're suggesting?

I have:

postProcess(renderedRoute) {
  renderedRoute.html = renderedRoute.html.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,'');
  return renderedRoute;
}

The above leaves me with ZERO script tags in the final rendered HTML file.

@o-alexandrov
Copy link
Contributor Author

@edarioq
You might try inserting your text into a playground for regex manipulations, for example here:
https://regexr.com/

Then, come up with a regex that would achieve what you would like.

In other words, your code is fine, you just need to write proper regex for your particular case.

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.

3 participants