@fluentui/react-icons-font-subsetting-webpack-plugin 2.0.318 → 2.0.320-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -31,26 +31,28 @@ Atomic imports provide better tree-shaking and faster build times for applicatio
31
31
 
32
32
  ```js
33
33
  // webpack.config.js
34
- const {default: FluentUIReactIconsFontSubsettingPlugin} = require('@fluentui/react-icons-font-subsetting-webpack-plugin');
34
+ const {
35
+ default: FluentUIReactIconsFontSubsettingPlugin,
36
+ } = require('@fluentui/react-icons-font-subsetting-webpack-plugin');
35
37
 
36
38
  module.exports = {
37
- module: {
38
- rules: [
39
- // Treat the font files as webpack assets
40
- {
41
- test: /\.(ttf|woff2?)$/,
42
- type: 'asset',
43
- }
44
- ]
45
- },
46
- resolve: {
47
- // Include 'fluentIconFont' to use the font implementation of the Fluent icons
48
- conditionNames: ['fluentIconFont', 'import']
49
- },
50
- plugins: [
51
- // Include this plugin
52
- new FluentUIReactIconsFontSubsettingPlugin(),
39
+ module: {
40
+ rules: [
41
+ // Treat the font files as webpack assets
42
+ {
43
+ test: /\.(ttf|woff2?)$/,
44
+ type: 'asset',
45
+ },
53
46
  ],
47
+ },
48
+ resolve: {
49
+ // Include 'fluentIconFont' to use the font implementation of the Fluent icons
50
+ conditionNames: ['fluentIconFont', 'import'],
51
+ },
52
+ plugins: [
53
+ // Include this plugin
54
+ new FluentUIReactIconsFontSubsettingPlugin(),
55
+ ],
54
56
  };
55
57
  ```
56
58
 
@@ -58,21 +60,23 @@ module.exports = {
58
60
 
59
61
  ```js
60
62
  // webpack.config.js
61
- const {default: FluentUIReactIconsFontSubsettingPlugin} = require('@fluentui/react-icons-font-subsetting-webpack-plugin');
63
+ const {
64
+ default: FluentUIReactIconsFontSubsettingPlugin,
65
+ } = require('@fluentui/react-icons-font-subsetting-webpack-plugin');
62
66
 
63
67
  module.exports = {
64
- module: {
65
- rules: [
66
- // Treat the font files as webpack assets
67
- {
68
- test: /\.(ttf|woff2?)$/,
69
- type: 'asset',
70
- }
71
- ]
72
- },
73
- plugins: [
74
- // Include this plugin
75
- new FluentUIReactIconsFontSubsettingPlugin(),
68
+ module: {
69
+ rules: [
70
+ // Treat the font files as webpack assets
71
+ {
72
+ test: /\.(ttf|woff2?)$/,
73
+ type: 'asset',
74
+ },
76
75
  ],
76
+ },
77
+ plugins: [
78
+ // Include this plugin
79
+ new FluentUIReactIconsFontSubsettingPlugin(),
80
+ ],
77
81
  };
78
- ```
82
+ ```
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as webpack from "webpack";
1
+ import * as webpack from 'webpack';
2
2
  export default class FluentUIReactIconsFontSubsettingPlugin implements webpack.WebpackPluginInstance {
3
3
  /**
4
4
  * Entry point for the Webpack plugin that registers hooks to perform font subsetting for `@fluentui/react-icons`.
package/lib/index.js CHANGED
@@ -30,18 +30,14 @@ const webpack = __importStar(require("webpack"));
30
30
  const subset_font_1 = __importDefault(require("subset-font"));
31
31
  const path_1 = require("path");
32
32
  const promises_1 = require("fs/promises");
33
- const PLUGIN_NAME = "FluentUIReactIconsFontSubsettingPlugin";
33
+ const PLUGIN_NAME = 'FluentUIReactIconsFontSubsettingPlugin';
34
34
  const FONT_FILES_BASE_NAMES = [
35
- "FluentSystemIcons-Filled",
36
- "FluentSystemIcons-Resizable",
37
- "FluentSystemIcons-Regular",
38
- "FluentSystemIcons-Light"
39
- ];
40
- const FONT_EXTENSIONS = [
41
- '.ttf',
42
- '.woff',
43
- '.woff2'
35
+ 'FluentSystemIcons-Filled',
36
+ 'FluentSystemIcons-Resizable',
37
+ 'FluentSystemIcons-Regular',
38
+ 'FluentSystemIcons-Light',
44
39
  ];
40
+ const FONT_EXTENSIONS = ['.ttf', '.woff', '.woff2'];
45
41
  /**
46
42
  * Match both chunk files and atomic font imports:
47
43
  * - lib/fonts/sizedIcons/chunk-0.js (chunk-based)
@@ -108,7 +104,7 @@ async function optimizeFontAsset(codepointMap, usedExports, compilation, assetNa
108
104
  }
109
105
  }
110
106
  let source = compilation.assets[assetName].source();
111
- if (typeof source === "string") {
107
+ if (typeof source === 'string') {
112
108
  source = Buffer.from(source);
113
109
  }
114
110
  compilation.assets[assetName] = new webpack.sources.RawSource(await (0, subset_font_1.default)(source, subsetText, {
@@ -117,12 +113,12 @@ async function optimizeFontAsset(codepointMap, usedExports, compilation, assetNa
117
113
  }
118
114
  function getTargetFormat(assetName) {
119
115
  switch ((0, path_1.extname)(assetName)) {
120
- case ".woff":
121
- return "woff";
122
- case ".woff2":
123
- return "woff2";
116
+ case '.woff':
117
+ return 'woff';
118
+ case '.woff2':
119
+ return 'woff2';
124
120
  default:
125
- return "sfnt";
121
+ return 'sfnt';
126
122
  }
127
123
  }
128
124
  function isNormalModule(m) {
@@ -144,8 +140,11 @@ function isFluentUIReactFontChunk(m) {
144
140
  }
145
141
  async function getFontAssetsAndCodepoints(pkgLibPath, compilation) {
146
142
  const utilsFontsFolder = (0, path_1.resolve)(pkgLibPath, 'utils/fonts');
147
- const codepoints = Object.fromEntries(await Promise.all(FONT_FILES_BASE_NAMES.map(async (fontBaseName) => [fontBaseName, JSON.parse(await (0, promises_1.readFile)((0, path_1.resolve)(utilsFontsFolder, `${fontBaseName}.json`), 'utf8'))])));
148
- const fontPaths = new Map(FONT_FILES_BASE_NAMES.flatMap(fontBaseName => FONT_EXTENSIONS.map(ext => [(0, path_1.resolve)(utilsFontsFolder, `${fontBaseName}${ext}`), codepoints[fontBaseName]])));
143
+ const codepoints = Object.fromEntries(await Promise.all(FONT_FILES_BASE_NAMES.map(async (fontBaseName) => [
144
+ fontBaseName,
145
+ JSON.parse(await (0, promises_1.readFile)((0, path_1.resolve)(utilsFontsFolder, `${fontBaseName}.json`), 'utf8')),
146
+ ])));
147
+ const fontPaths = new Map(FONT_FILES_BASE_NAMES.flatMap((fontBaseName) => FONT_EXTENSIONS.map((ext) => [(0, path_1.resolve)(utilsFontsFolder, `${fontBaseName}${ext}`), codepoints[fontBaseName]])));
149
148
  const result = [];
150
149
  for (const m of compilation.modules) {
151
150
  if (isNormalModule(m) && fontPaths.has(m.resource)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-icons-font-subsetting-webpack-plugin",
3
- "version": "2.0.318",
3
+ "version": "2.0.320-alpha.0",
4
4
  "description": "Webpack plugin to subset the icon fonts used by @fluentui/react-icons based on which icons are used.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -25,7 +25,6 @@
25
25
  "devDependencies": {
26
26
  "typescript": "5.0.4",
27
27
  "webpack": "^5.72.0",
28
- "@fluentui/react-icons": "*",
29
28
  "@types/node": "14"
30
29
  },
31
30
  "dependencies": {