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

Delete InterpolateHtmlPlugin.js? #4202

Closed
jantimon opened this issue Mar 22, 2018 · 7 comments
Closed

Delete InterpolateHtmlPlugin.js? #4202

jantimon opened this issue Mar 22, 2018 · 7 comments
Milestone

Comments

@jantimon
Copy link

jantimon commented Mar 22, 2018

html-webpack-plugin 3.1.0 allows to overwrite the template variables:

jantimon/html-webpack-plugin#904

The change allows libraries like create-react-app and vue-cli to overwrite template variables.
Please let me know if this allows you to replace InterpolateHtmlPlugin

@jantimon jantimon changed the title Delete InterpolateHtmlPlugin.js Delete InterpolateHtmlPlugin.js? Mar 22, 2018
@Timer Timer added this to the 2.0.0 milestone Mar 23, 2018
@andriijas
Copy link
Contributor

Thanks @jantimon - i will look into this!

@andriijas
Copy link
Contributor

@jantimon I tried to follow the src and read the docs but I cant get it working.

    new HtmlWebpackPlugin({
      inject: true,
      templateParameters: {
        "%FOO%": 'BAR',
      },
      template: paths.appHtml,
    }),

Which is the correct way to access %FOO% in the template?

@jantimon
Copy link
Author

jantimon commented Mar 29, 2018

Exactly:
https://github.com/jantimon/html-webpack-plugin/blob/c05b31bddc2340d7b97c5b9b5e19ba62dac82826/spec/BasicSpec.js#L1674-L1689

The replacement is done by the template language (by default that's lodash).
So in your example - unless you are using a different loader it could be:

  new HtmlWebpackPlugin({
      inject: true,
      templateParameters: {
        "FOO": 'BAR',
      },
      template: paths.appHtml,
    }),
<h1><%= FOO =></h1>

Just like you used it before:
https://github.com/jantimon/html-webpack-plugin/blob/c05b31bddc2340d7b97c5b9b5e19ba62dac82826/default_index.ejs#L5

If you want to use a %XXXX% syntax you have to use a loader which works that way.

@andriijas
Copy link
Contributor

Im not sure we want to change from %FOO% to <%= FOO => - whats your take on this @Timer

@jantimon there is no way to pass options to lodash template compiler? it supports custom interpolate. creating a loader i think we want to avoid that, then our current implementation is simpler.

@jantimon
Copy link
Author

jantimon commented Mar 29, 2018

You can use any loader with any loader config (whatever would be possible in webpack is also possible for the plugin)

  new HtmlWebpackPlugin({
      inject: true,
      templateParameters: {
        "FOO": 'BAR',
      },
      template: '!!any-loader?anyloader-config!' + paths.appHtml,
    }),

@jantimon
Copy link
Author

But you can also keep 2 template systems like it is implemented right now.
Or you could set templateParameters:false if you want to skip the default parameter generation.

@andriijas
Copy link
Contributor

Okay if I get it right we need to switch from .html to .ejs or .js to get <%= %> syntax working and then we need to introduce that syntax to our users or create a custom webpack loader, while we already have a very simple wepack plugin, which is already migrated to wepack 4 I dont see the value of doing this right now. Appreciate the efforts though!

@lock lock bot locked and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants