Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ module.exports = {
// note: these settings are mutually exclusive and allowedFilesRegex has priority over skippedFilesRegex
allowedFilesRegex: null, // RegExp to only target specific fonts by their names
skippedFilesRegex: null, // RegExp to skip specific fonts by their names
fontRegex: /\.(eot|ttf|svg|woff|woff2)(\?.+)?$/, // RegExp for searching font files
textRegex: /\.(js|css|html)$/, // RegExp for searching text reference
webpackCompilationHook: 'thisCompilation', // Webpack compilation hook (for example PurgeCss webpack plugin use 'compilation' )
}),
Expand Down
10 changes: 5 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class FontminPlugin {
allowedFilesRegex: null,
skippedFilesRegex: null,
appendHash: false,
fontRegex: FONT_REGEX,
textRegex: TEXT_REGEX,
webpackCompilationHook: WEBPACK_COMPILATION,
},
Expand All @@ -49,7 +50,7 @@ class FontminPlugin {
}

hasFontAsset(assets) {
return _.find(assets, (val, key) => FONT_REGEX.test(key))
return _.find(assets, (val, key) => this._options.fontRegex.test(key))
}

findFontFiles(compilation) {
Expand All @@ -65,9 +66,8 @@ class FontminPlugin {
return _(Array.from(compilation.modules))
.filter(module => this.hasFontAsset(module.buildInfo.assets))
.map(module => {
const filename = Array.from(module.buildInfo.assetsInfo.values())[0].sourceFilename
const font = path.basename(filename, path.extname(filename))
return _.keys(module.buildInfo.assets).map(asset => {
const font = path.basename(asset).split('.').shift()
const buffer = module.buildInfo.assets[asset].source()
const extension = path.extname(getFilenameWithoutQueryString(asset))
return {asset, extension, font, buffer}
Expand All @@ -85,7 +85,7 @@ class FontminPlugin {
),
)
.flatten()
.filter(filename => FONT_REGEX.test(filename))
.filter(filename => this._options.fontRegex.test(filename))
.map(getFilenameWithoutQueryString)
.map(filename => {
return {
Expand All @@ -97,7 +97,7 @@ class FontminPlugin {

return _(compilation.assets)
.keys()
.filter(name => FONT_REGEX.test(name))
.filter(name => this._options.fontRegex.test(name))
.map(asset => {
const assetFilename = getFilenameWithoutQueryString(asset)
const buffer = compilation.assets[asset].source()
Expand Down
Loading