Skip to content

Commit

Permalink
Merge pull request #71 from Canic/master
Browse files Browse the repository at this point in the history
Bugfixes
  • Loading branch information
Jérôme Brunel authored Aug 28, 2019
2 parents d26edb2 + 5b49bab commit 77bc5e4
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 320 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

A Webpack loader that generates fonts from your SVG icons and allows you to use your icons in your HTML.

`webfonts-loader` uses the [`webfonts-generator`](https://github.com/sunflowerdeath/webfonts-generator) plugin to create fonts in any format. It also generates CSS files so that you can use your icons directly in your HTML, using CSS classes.
`webfonts-loader` uses the [`webfonts-generator`](https://github.com/vusion/webfonts-generator) plugin to create fonts in any format. It also generates CSS files so that you can use your icons directly in your HTML, using CSS classes.

## Installation

Expand Down Expand Up @@ -101,16 +101,16 @@ The loader will then generate:
##### `baseSelector`, String

The base CSS selector, under which each icon class is to be created.
See [webfonts-generator#templateoptions](https://github.com/sunflowerdeath/webfonts-generator#templateoptions)
See [webfonts-generator#templateoptions](https://github.com/vusion/webfonts-generator#templateoptions)

##### `classPrefix`, String

The prefix to be used with each icon class.
See [webfonts-generator#templateoptions](https://github.com/sunflowerdeath/webfonts-generator#templateoptions)
See [webfonts-generator#templateoptions](https://github.com/vusion/webfonts-generator#templateoptions)

##### `cssTemplate`, String

See [webfonts-generator#csstemplate](https://github.com/sunflowerdeath/webfonts-generator#csstemplate)
See [webfonts-generator#csstemplate](https://github.com/vusion/webfonts-generator#csstemplate)

##### `embed`, Boolean

Expand Down Expand Up @@ -182,43 +182,43 @@ This option can be also configured globally in the webpack loader options.

##### `files`, Array

See [webfonts-generator#files](https://github.com/sunflowerdeath/webfonts-generator#files)
See [webfonts-generator#files](https://github.com/vusion/webfonts-generator#files)

##### `fontName`, String

See [webfonts-generator#fontname](https://github.com/sunflowerdeath/webfonts-generator#fontname)
See [webfonts-generator#fontname](https://github.com/vusion/webfonts-generator#fontname)

##### `formatOptions`, Object

See [webfonts-generator#formatoptions](https://github.com/sunflowerdeath/webfonts-generator#formatoptions)
See [webfonts-generator#formatoptions](https://github.com/vusion/webfonts-generator#formatoptions)

##### `rename`, Function

See [webfonts-generator#rename](https://github.com/sunflowerdeath/webfonts-generator#rename)
See [webfonts-generator#rename](https://github.com/vusion/webfonts-generator#rename)

##### `types`, Array<String>

See [webfonts-generator#types](https://github.com/sunflowerdeath/webfonts-generator#types)
See [webfonts-generator#types](https://github.com/vusion/webfonts-generator#types)

##### `dest`, String

See [webfonts-generator#dest](https://github.com/sunflowerdeath/webfonts-generator#dest)
See [webfonts-generator#dest](https://github.com/vusion/webfonts-generator#dest)

##### `html`, Boolean

See [webfonts-generator#html](https://github.com/sunflowerdeath/webfonts-generator#html)
See [webfonts-generator#html](https://github.com/vusion/webfonts-generator#html)

##### `htmlDest`, String

See [webfonts-generator#htmldest](https://github.com/sunflowerdeath/webfonts-generator#htmldest)
See [webfonts-generator#htmldest](https://github.com/vusion/webfonts-generator#htmldest)

##### `writeFiles`, Boolean (default false)

See [webfonts-generator#writefiles](https://github.com/sunflowerdeath/webfonts-generator#writefiles)
See [webfonts-generator#writefiles](https://github.com/vusion/webfonts-generator#writefiles)

##### `cssFontsUrl`, String (before cssFontsPath)

See [webfonts-generator#cssfontspath](https://github.com/sunflowerdeath/webfonts-generator#cssfontspath)
See [webfonts-generator#cssfontspath](https://github.com/vusion/webfonts-generator#cssfontspath)

##### `htmlTemplate`, String
#### Example
Expand All @@ -228,4 +228,4 @@ htmlTemplate: path.resolve(__dirname, 'src/html.hbs'),
...
```

See [webfonts-generator#htmltemplate](https://github.com/sunflowerdeath/webfonts-generator#htmltemplate)
See [webfonts-generator#htmltemplate](https://github.com/vusion/webfonts-generator#htmltemplate)
35 changes: 27 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var loaderUtils = require('loader-utils');
var webfontsGenerator = require('webfonts-generator');
var webfontsGenerator = require('@vusion/webfonts-generator');
var path = require('path');
var glob = require('glob');
var url = require('url');
Expand Down Expand Up @@ -66,7 +66,6 @@ function wpGetOptions (context) {
module.exports = function (content) {
this.cacheable();

var webpackOptions = this.options || {}; // only makes sense in Webpack 1.x, or when LoaderOptionsPlugin is used
var options = wpGetOptions(this) || {};
var rawFontConfig;
try {
Expand Down Expand Up @@ -128,8 +127,8 @@ module.exports = function (content) {
generatorOptions.cssTemplate = path.resolve(this.context, fontConfig.cssTemplate);
}

if (fontConfig.cssFontsPath) {
generatorOptions.cssFontsPath = path.resolve(this.context, fontConfig.cssFontsPath);
if (fontConfig.cssFontsUrl) {
generatorOptions.cssFontsUrl = path.resolve(this.context, fontConfig.cssFontsUrl);
}

if (fontConfig.htmlTemplate) {
Expand All @@ -141,7 +140,12 @@ module.exports = function (content) {
}

if (fontConfig.dest) {
generatorOptions.dest = path.resolve(this.context, fontConfig.dest);
generatorOptions.dest = '';
if (fontConfig.dest.endsWith('/')) {
generatorOptions.dest = fontConfig.dest;
} else {
generatorOptions.dest = `${fontConfig.dest}/`;
}
}

// Spit out SCSS file to same path as CSS file to easily use mixins (scssFile must be true)
Expand All @@ -166,15 +170,29 @@ module.exports = function (content) {

var cb = this.async();

var publicPath = options.publicPath || (webpackOptions.output && webpackOptions.output.publicPath) || '/';
let publicPath = '';
if (typeof options.publicPath === 'string') {
if (options.publicPath === '' || options.publicPath.endsWith('/')) {
publicPath = options.publicPath;
} else {
publicPath = `${options.publicPath}/`;
}
} else {
if (typeof options.publicPath === 'function') {
publicPath = options.publicPath(this.resourcePath, this.rootContext);
} else {
publicPath = this._compilation.outputOptions.publicPath;
}
}

var embed = !!generatorOptions.embed;

if (generatorOptions.cssTemplate) {
this.addDependency(generatorOptions.cssTemplate);
}

if (generatorOptions.cssFontsPath) {
this.addDependency(generatorOptions.cssFontsPath);
if (generatorOptions.cssFontsUrl) {
this.addDependency(generatorOptions.cssFontsUrl);
}

webfontsGenerator(generatorOptions, (err, res) => {
Expand All @@ -188,6 +206,7 @@ module.exports = function (content) {
var chunkHash = filename.indexOf('[chunkhash]') !== -1
? hashFiles(generatorOptions.files, options.hashLength) : '';

filename = generatorOptions.dest.concat(filename);
filename = filename
.replace('[chunkhash]', chunkHash)
.replace('[fontname]', generatorOptions.fontName)
Expand Down
Loading

0 comments on commit 77bc5e4

Please sign in to comment.