0.1.1 • Published 8 years ago

webpack-rev-replace-plugin v0.1.1

Weekly downloads
11
License
ISC
Repository
github
Last release
8 years ago

webpack-rev-replace-plugin

Rewrite occurrences of filenames which have been renamed by webpack.

###demo code

var RevReplacePlugin = require('webpack-rev-replace-plugin');

module.exports = {
	entry: {},
	output: {
		path: './dist',
		publicPath: '/',
		filename: 'script/[name].[hash:6].js',
	},
	module: {
		loaders: [
			{
				test: /\.swig$/,
				loader: 'html'
			}
		]
	},
	plugins: [
		new RevReplacePlugin({
			cwd: './src',
			files: '**/*.swig',
			outputPageName: function (filename) {
				return filename;
			},
			modifyReved: function(filename) {
              return filename.replace(/(\/style\/|\/script\/)/, '')
            }
		})
	]
};

###before

<!DOCTYPE html>
<html>
<head>
	<title></title>
	<script href='app.js'></script>
</head>
<body>

</body>
</html>

###after

<!DOCTYPE html>
<html>
<head>
	<title></title>
	<script href='app.c54df8.js'></script>
</head>
<body>

</body>
</html>

API

options.modifyUnreved, options.modifyReved

Type: Function

Modify the name of the unreved/reved files before using them. The filename is passed to the function as the first argument.

For example, if in your manifest you have:

{"js/app.js.map": "js/app-98adc164.js.map"}

If you wanted to get rid of the js/ path just for .map files (because they are sourcemaps and the references to them are relative, not absolute) you could do the following:

function modifyUnreved(filename) {
    if (filename.indexOf('.map') > -1) {
        return filename.replace('js/', '');
    }
    return filename;
}
0.1.1

8 years ago

0.1.0

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago