0.0.13 • Published 7 years ago

hashed-map-webpack-plugin v0.0.13

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

hashed-map-webpack-plugin

This plugin maps the filepaths of files output by a webpack compilation from their hashed version to their unhashed version.

Example output

{
  "/site.js": "https://assets.my-site.com/site.123123.js",
  "/images/edison.jpg": "https://assets.my-site.com/images/edison.123123.jpg",
  "/site.css": "https://assets.my-site.com/site.123123.css"
}

Installation

npm install hashed-map-webpack-plugin --save-dev

Configuration

In your webpack config include the plug-in. And add it to your config:

var path = require('path')
var HashedMapPlugin = require('hashed-map-webpack-plugin')

module.exports = {
    plugins: [HashedMapPlugin(), ...]
    output: {
        path: path.join(__dirname, '../www'),
        filename: '[path].[name].[hash].js',
        publicPath: 'https://assets.my-site.com/'
    },
    ...
}

Options

You can pass the following options:

exclude

Regex to match for excluded content.

filepath

Where to save the JSON file output by the plugin.

Optional. static-assets.json by default.

preset

If you wish you can preset the map to a JavaScript object. This can be useful for adding in metadata or mappings outside the webpack compilation scope.

Note: Any conflicting filepaths in the preset will be overridden during compilation.

stripHash

A function used to strip the hash from the filepath. The default function splits the filename using the dot (.) character and rejoins minus the last but one part, e.g:

function stripHash(filepath) {
    var parts = filepath.split('.');
    parts.splice(parts.length - 2, 1);
    return parts.join('.');
}

stripHash('/site.123123.js')

> '/site.js'

Testing

To test the plugin run:

npm test