packingjs / replace-hash-webpack-plugin

This is a webpack plugin that update script references in HTML files by webpack bundle's hash.
6 stars 8 forks source link

当loader的options.name包含[path]时,替换正则有问题 #2

Closed sharonlx closed 6 years ago

sharonlx commented 7 years ago

url-loader配置:

{
                test: /\.(jpg|png|gif|ttf|woff|woff2|eot|svg)$/,
                use: [{
                    loader: 'url-loader',
                    options: {
                        limit: '10',
                        name: '[path][name]-[hash:10].[ext]'
                    }
                }]
            }

index.js中的

var regString = filename
                        .replace('\[name\]', '(\\S+)')
                        .replace('\[ext\]', ext.substr(1, ext.length))
                        .replace('\[chunkhash:' + hashLength + '\]', '\\w{' + hashLength + '}')
                        .replace('\[contenthash:' + hashLength + '\]', '\\w{' + hashLength + '}')
                        .replace('\[hash:' + hashLength + '\]', '\\w{' + hashLength + '}');
var matches = item.match(new RegExp(regString));

matches 结果不对。

测试case item="kuaishou/static/xxx/big-smart-1234567890.png";

zhongzhi107 commented 6 years ago

replace-hash-webpack-plugin@2.4.2