webpack/webpack — pull request #427 by diurnalist (2014-08-25 08:48:20+00:00)
Title: Add TemplatedPathPlugin to generically handle asset paths w/ template vars

This consolidates all the areas where webpack is templating asset paths (replacing stuff like [id], [hash], etc.) into one plugin. The benefit of this is that now other plugins could theoretically hook in to this mechanism to support new template variables (for example, see diurnalist/git-sha-webpack-plugin).

Currently, this plugin is applied to the MainTemplate object, under the name "asset-path".

#### Usage
The normal usage remains completely unchanged. This does not add support for chunk hashes where they were not before, nor does it add any new areas where assets are being templated.

#### Variable hash lengths
This also adds a bit of syntactic sugar to the hash variables (`[hash]`, `[chunkhash]`). A developer can now specify how long they want the hash to be.

```javascript
// webpack.config.js
{
...
output: {
// include the first 6 characters of the build md5 hash
filename: "[name]-[hash:6].js"
}
}
```

#### Plugging in
Plugginable via the "asset-path" hook:

```javascript
function MyPlugin() {}
MyPlugin.prototype.apply = function(compiler) {
compiler.plugin("compilation", function(compilation) {
compilation.mainTemplate.plugin("asset-path", function(_, templateData) {
return _.replace(/\[customthing\]/ig, "my-replacement");
});
};
```