Have ideas to improve npm?Join in the discussion! »

    babel-plugin-hash-strings

    1.0.0 • Public • Published

    babel-plugin-hash-strings

    Replace all instances of "@@strings like this" with hashes.

    This might be useful for decreasing the size of your JavaScript bundles. But note that gzip might actually be better for your code because hashes do not compress well.

    Install

    npm install --save-dev babel-plugin-hash-strings

    Usage

    It's recommended that you only use this plugin in a production build.

    // babel.config.js
    let presets = [ ... ]
    let plugins = [ ... ]
     
    if (process.env.NODE_ENV === "production") {
      plugins.push("babel-plugin-hash-strings")
    }
     
    module.exports = { presets, plugins }

    Example

    Input:

    let value = "@@hash me"

    Output:

    let value = "5953c"

    options.chars

    This plugin defaults to really short hashes because you probably won't have that many strings that uniqueness matters all that much. But just in case you do have a duplicate, the plugin has a built-in check for them and you can increase the length of your strings using options.chars

    // babel.config.js
    let presets = [ ... ]
    let plugins = [ ... ]
     
    if (process.env.NODE_ENV === "production") {
      plugins.push(["babel-plugin-hash-strings", {
        chars: 8 // (default: 5)
      }])
    }
     
    module.exports = { presets, plugins }

    Install

    npm i babel-plugin-hash-strings

    DownloadsWeekly Downloads

    1

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    4.66 kB

    Total Files

    7

    Last publish

    Collaborators

    • avatar