-
Notifications
You must be signed in to change notification settings - Fork 38
/
index.js
52 lines (42 loc) · 1.35 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// @ts-check
'use strict';
const assert = require('assert');
/**
* The main plugin
*
* Options:
* @param {{
fontNamePrefix?: string,
enforcedSvgHeight?: number,
resolve?: any
}} [userOptions]
*/
function IconfontWebpackPlugin (userOptions) {
// Default options
const options = Object.assign({
// allows to prefix the font name to prevent collisions
fontNamePrefix: '',
// the svg size requires all svgs to have the same height
// usually scaling the icons to 1000px should be fine but if you prefer
// another value set it here
enforcedSvgHeight: 1000,
// resolve function to translate webpack urls into absolute filepaths
// e.g. url('demo.svg') -> '/Users/me/project-x/demo.svg'
// usually you should pass on the postcss loader
// https://webpack.js.org/api/loaders/#this-resolve
resolve: undefined
}, userOptions);
// Verify resolve function
assert(typeof options.resolve === 'function',
'Please pass a resolve function to the IconFontWebpackPlugin.\n' +
'For example: \n' +
'{\n' +
' loader: \'postcss-loader\',\n' +
' options: {\n' +
' plugins: (loader) => [\n' +
' require(\'iconfont-webpack-plugin\')({ resolve: loader.resolve }), \n\n'
);
// Call postcss plugin
return require('./lib/postcss-plugin')(options);
}
module.exports = IconfontWebpackPlugin;