Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jeerbl/webfonts-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
jeerbl committed Jul 20, 2017
2 parents 6708a8c + 52dc016 commit 8ab8f89
Show file tree
Hide file tree
Showing 184 changed files with 243 additions and 7 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# http://editorconfig.org

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
insert_final_newline = false
trim_trailing_whitespace = false

[*.sh]
indent_size = 4
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ You also can use a module like `glob` to pick up a variable set of icons, too. M
## Loader parameters

- `embed`, Boolean
Should the fonts be embedded in the CSS? By default the fonts are written to disk. If `embed` is specified the font is base64 encoded and embedded inside the `@font-face` declaration. Example configuration: `loader: "style!css!webfonts?embed&types=woff"`.
Should the fonts be embedded in the CSS? By default the fonts are written to disk. If `embed` is specified the font is base64 encoded and embedded inside the `@font-face` declaration.

- `hashLength`, Number
Optional. The length of hash in fileName, maximum value: 32, minimal value: 8.

Example configuration: `loader: "style!css!webfonts?embed&types=woff&hashLength=8"`.

## Font configuration (`*.font.js` or `*.font.json`)

Expand Down Expand Up @@ -130,3 +135,4 @@ There is one special configuration optin that exists in both, the actual font co
- `[fontname]`: The name of the font. I.e. "Awesomefont".
- `[ext]`: The extension. I.e.: `.woff`.
- `[hash]`: The hash of your current compilation.
- `[chunkhash]`: The hash of your source svg files.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var path = require('path');
var glob = require('glob');
var isUrl = require('is-url');
var url = require('url');
var hashFiles = require('./utils').hashFiles;

var mimeTypes = {
'eot': 'application/vnd.ms-fontobject',
Expand Down Expand Up @@ -168,8 +169,10 @@ module.exports = function (content) {
for (var i in formats) {
var format = formats[i];
if (!embed) {
var filename = config.fileName || params.fileName || '[hash]-[fontname].[ext]';
var filename = config.fileName || params.fileName || '[chunkhash]-[fontname].[ext]';
var chunkHash = filename.indexOf('[chunkhash]') !== -1 ? hashFiles(generatorConfiguration.files, params.hashLength) : '';
filename = filename
.replace('[chunkhash]', chunkHash)
.replace('[fontname]', generatorConfiguration.fontName)
.replace('[ext]', format);
var formatUrl = loaderUtils.interpolateName(this,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"license": "Unlicense",
"dependencies": {
"glob": "^7.1.1",
"hash-files": "^1.1.1",
"is-url": "^1.2.2",
"loader-utils": "^1.0.2",
"webfonts-generator": "^0.4.0"
Expand Down
26 changes: 26 additions & 0 deletions test/ava.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var test = require('ava');
var glob = require('glob').sync;
var hashFiles = require('../utils').hashFiles;

test('check consistency of files hash without hash length option', function (t) {
var files = glob('./test/test-svg/*.svg');
var expected = 'da39a3ee5e6b4b0d3255';

t.is(hashFiles(files), expected);
});

test('check consistency of files hash with min hash length option', function (t) {
var files = glob('./test/test-svg/*.svg');
var expected = 'da39a3ee';
var minHashLength = 8;

t.is(hashFiles(files, minHashLength), expected);
});

test('check consistency of files hash with max hash length option', function (t) {
var files = glob('./test/test-svg/*.svg');
var expected = 'da39a3ee5e6b4b0d3255bfef95601890';
var maxHashLength = 32;

t.is(hashFiles(files, maxHashLength), expected);
});
2 changes: 1 addition & 1 deletion test/octicons.font.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
'files': [
'node_modules/octicons/build/svg/*.svg'
'./test-svg/*.svg'
],
'fontName': 'octicons',
'classPrefix': 'octicon-',
Expand Down
6 changes: 2 additions & 4 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
"private": true,
"main": "entry.js",
"scripts": {
"test": "rimraf ./dist && webpack"
},
"dependencies": {
"octicons": "^5.0.1"
"test": "rimraf ./dist && webpack && ava -v ./ava.js"
},
"devDependencies": {
"ava": "^0.21.0",
"css-loader": "^0.28.0",
"rimraf": "^2.6.1",
"style-loader": "^0.18.1",
Expand Down
1 change: 1 addition & 0 deletions test/test-svg/alert.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/arrow-down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/arrow-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/arrow-right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/arrow-small-down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/arrow-small-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/arrow-small-right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/arrow-small-up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/arrow-up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/beaker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/bell.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/bold.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/book.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/bookmark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/briefcase.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/broadcast.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/browser.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/bug.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/calendar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/checklist.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/chevron-down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/chevron-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/chevron-right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/chevron-up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/test-svg/circle-slash.svg
1 change: 1 addition & 0 deletions test/test-svg/circuit-board.svg
1 change: 1 addition & 0 deletions test/test-svg/clippy.svg
1 change: 1 addition & 0 deletions test/test-svg/clock.svg
1 change: 1 addition & 0 deletions test/test-svg/cloud-download.svg
1 change: 1 addition & 0 deletions test/test-svg/cloud-upload.svg
1 change: 1 addition & 0 deletions test/test-svg/code.svg
1 change: 1 addition & 0 deletions test/test-svg/comment-discussion.svg
1 change: 1 addition & 0 deletions test/test-svg/comment.svg
1 change: 1 addition & 0 deletions test/test-svg/credit-card.svg
1 change: 1 addition & 0 deletions test/test-svg/dash.svg
1 change: 1 addition & 0 deletions test/test-svg/dashboard.svg
1 change: 1 addition & 0 deletions test/test-svg/database.svg
1 change: 1 addition & 0 deletions test/test-svg/desktop-download.svg
1 change: 1 addition & 0 deletions test/test-svg/device-camera-video.svg
1 change: 1 addition & 0 deletions test/test-svg/device-camera.svg
1 change: 1 addition & 0 deletions test/test-svg/device-desktop.svg
1 change: 1 addition & 0 deletions test/test-svg/device-mobile.svg
1 change: 1 addition & 0 deletions test/test-svg/diff-added.svg
1 change: 1 addition & 0 deletions test/test-svg/diff-ignored.svg
1 change: 1 addition & 0 deletions test/test-svg/diff-modified.svg
1 change: 1 addition & 0 deletions test/test-svg/diff-removed.svg
1 change: 1 addition & 0 deletions test/test-svg/diff-renamed.svg
Loading

0 comments on commit 8ab8f89

Please sign in to comment.