• Joe Haddad's avatar
    Turn on Babel `helpers` (#5093) · adfb20c4
    Joe Haddad authored
    * Turn on helpers and test importing something with async/await works
    
    * Compiling babel runtime breaks itself
    
    * Add helpers option to babel plugin with defaults
    
    * Make helpers off by default and on in our configuration
    
    * Hit eject and e2e
    
    * meh
    
    * copy'n'paste
    
    * change again
    
    * Turn off helpers by default in /prod, /dev, /test
    
    * oops
    
    * Spread undefined
    
    * Use object assign not object spread
    
    * Put preset in template since it's needed
    
    * Fix e2e tests
    Unverified
    adfb20c4
InterpolateHtmlPlugin.js 1.32 KiB
/**
 * Copyright (c) 2015-present, Facebook, Inc.
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
// This Webpack plugin lets us interpolate custom variables into `index.html`.
// Usage: `new InterpolateHtmlPlugin({ 'MY_VARIABLE': 42 })`
// Then, you can use %MY_VARIABLE% in your `index.html`.
// It works in tandem with HtmlWebpackPlugin.
// Learn more about creating plugins like this:
// https://github.com/ampedandwired/html-webpack-plugin#events
'use strict';
const escapeStringRegexp = require('escape-string-regexp');
class InterpolateHtmlPlugin {
  constructor(replacements) {
    this.replacements = replacements;
  apply(compiler) {
    compiler.hooks.compilation.tap('InterpolateHtmlPlugin', compilation => {
      compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing.tap(
        'InterpolateHtmlPlugin',
        data => {
          // Run HTML through a series of user-specified string replacements.
          Object.keys(this.replacements).forEach(key => {
            const value = this.replacements[key];
            data.html = data.html.replace(
              new RegExp('%' + escapeStringRegexp(key) + '%', 'g'),
              value
          });
    });
module.exports = InterpolateHtmlPlugin;