Giter Site home page Giter Site logo

interpolate-html-plugin's Introduction

interpolate-html-plugin

NPM version NPM downloads Build Status donate

Extracted from create-react-app

Install

This plugin is supposed to work with html-webpack-plugin

yarn add interpolate-html-plugin --dev

Usage

module.exports = {
  plugins: [
    new InterpolateHtmlPlugin({
      'NODE_ENV': 'development'
    })
  ]
}

Then you can use %NODE_ENV% in your template html file, and you can use it with html-webpack-plugin's default template syntax (lodash.template):

<% if ('%NODE_ENV%' === 'development') { %>
do something
<% } %>

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

interpolate-html-plugin © egoist, Released under the MIT License.
Authored and maintained by egoist with help from contributors (list).

egoistian.com · GitHub @egoist · Twitter @_egoistlily

interpolate-html-plugin's People

Contributors

egoist avatar keithgabryelski avatar nucllear avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

interpolate-html-plugin's Issues

URIError: Failed to decode param '/%PUBLIC_URL%/favicon-32x32.png'

Hi, I updated webpack to v4, and now having this error:

URIError: Failed to decode param '/%PUBLIC_URL%/favicon-32x32.png'

In my index html I have:

<link rel="icon" type="image/png" sizes="32x32" href="%PUBLIC_URL%/favicon-32x32.png">

I've seen that now the order matters and declared the plugin after HtmlWebpackPlugin

  plugins: [
    new HtmlWebpackPlugin({
      inject: true,
      template: paths.appHtml
    }),
    new InterpolateHtmlPlugin({
      PUBLIC_URL: ''
    }),
...

What else am I missing?

is it dead? what about webpack 4?

      compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing.tap(
TypeError: Cannot read property 'tap' of undefined
    at compiler.hooks.compilation.tap.compilation (/Users/mxtnr/rocket/felix-front/node_modules/interpolate-html-plugin/index.js:35:63)

Docs are misleading

I didn't think the plugin was working since it says "then you can use %NODE_ENV%" but really the delimiters are !! by default, not %. Almost gave up but looked at the docs one more time and saw the piece at the bottom about the defaults and it clicked.

webpack 4 support

hi

just wanted to ask, if you have plans to upgrade the api to support webpack 4 in the near future 😄 thanks for this great plugin!

Unable to access VARIABLE inside index.html file

I am not able to access my variable provided in the plugin like this

new InterpolateHtmlPlugin({
            MYVAR: 'myvariable',
}),

Here I am accessing variable like this
I want inside script like this

<script type="text/javascript">
if(%MYVAR%) {
do something
}
</script>

software version
windows 10
browser chrome 76.0.3809.132
webpack 4
react 16+

Cannot read property 'tap' of undefined

Getting this with 3.0.0 on Webpack 4.6.0.

compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing.tap(
                                                              ^

TypeError: Cannot read property 'tap' of undefined

Called just with example opts

new InterpolateHtmlPlugin({
      NODE_ENV: 'production'
   }),

    new HtmlWebpackPlugin({
      template: 'src/index.html',
      inject: false
    })

Support for nested objects

Can I submit a PR to allow for an object of objects to be passed to the interpolate plugin?

This would allow me to do

const config = {
'foo': 'bar',
'bar': {
 'foofoo': 'barbar'
 }
}

And then in my .html file

    <link href="//%bar.foofoo%/assets/css.css" rel="stylesheet" type="text/css"></link>

Inability to work with webpack@5 and html-webpack-plugin@^4.5.0

Attempting to build using a simple config object as described in the specs fails due to TypeError: Cannot read property 'tap' of undefined.

Webpack config

module.exports = {
    ...
    plugins: [
        new HtmlWebpackPlugin({
            title: indexHtmlTitle,
            template: paths.root + '/src/index.html',
            meta: indexHtmlMetaTagData
        }),
        new InterpolateHtmlPlugin(myConfigObj),
        ...
    ]
};

Output

TypeError: Cannot read property 'tap' of undefined
    at \myapp\node_modules\interpolate-html-plugin\index.js:36:63
    at Hook.eval [as call] (eval at create

Expected result

InterpolateHtmlPlugin to work as expected with webpack@5, html-webpack-plugin@^4.5.0, etc.

Edit: Added the HtmlWebpackPlugin config to plugins array to show that the suggestion in issue 5 to put HtmlWebpackPlugin above InterpolateHtmlPlugin does not solve the issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.