@fluentui/react-icons-font-subsetting-webpack-plugin 2.0.340 → 2.0.342
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 +7 -0
- package/lib/index.js +9 -2
- package/lib/selector-protocol.d.ts +3 -0
- package/lib/selector-protocol.js +27 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,6 +39,13 @@ The plugin subsets the same shared font files used by the standard API, based on
|
|
|
39
39
|
|
|
40
40
|
> **Tip 💡:** You don't have to write atomic headless imports by hand. Pair this plugin with [`@fluentui/react-icons-atomic-webpack-loader`](../react-icons-atomic-webpack-loader) using `{ headless: true, iconVariant: 'fonts' }` — it rewrites plain barrel imports (`import { AddFilled } from '@fluentui/react-icons'`) into headless font atoms, which this plugin then subsets. You still import `@fluentui/react-icons/headless/fonts/styles.css` yourself.
|
|
41
41
|
|
|
42
|
+
The plugin is query-aware for the atomic loader's
|
|
43
|
+
`moduleGranularity: 'icon'` mode. Queried modules are attributed through their
|
|
44
|
+
query-free physical paths while their exact selected exports are aggregated.
|
|
45
|
+
Use coordinated loader/plugin releases: the two packages perform a
|
|
46
|
+
compilation-level `v1` selector capability handshake and fail the build instead
|
|
47
|
+
of producing an incorrect subset when support is missing or incompatible.
|
|
48
|
+
|
|
42
49
|
## Usage
|
|
43
50
|
|
|
44
51
|
### With `fluentIconFont` condition
|
package/lib/index.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const subset_font_1 = __importDefault(require("subset-font"));
|
|
7
7
|
const path_1 = require("path");
|
|
8
8
|
const promises_1 = require("fs/promises");
|
|
9
|
+
const selector_protocol_1 = require("./selector-protocol");
|
|
9
10
|
const PLUGIN_NAME = 'FluentUIReactIconsFontSubsettingPlugin';
|
|
10
11
|
const FONT_FILES_BASE_NAMES = [
|
|
11
12
|
'FluentSystemIcons-Filled',
|
|
@@ -48,16 +49,18 @@ class FluentUIReactIconsFontSubsettingPlugin {
|
|
|
48
49
|
apply(compiler) {
|
|
49
50
|
const { Compilation, sources } = compiler.webpack;
|
|
50
51
|
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
52
|
+
(0, selector_protocol_1.registerSelectorCapability)(compilation);
|
|
51
53
|
compilation.hooks.processAssets.tapPromise({ name: PLUGIN_NAME, stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE }, async () => {
|
|
52
54
|
const runtime = getRuntimeSpec(compiler, compilation);
|
|
53
55
|
const packageUsages = new Map();
|
|
54
56
|
for (const m of compilation.modules) {
|
|
55
57
|
if (isFluentUIReactFontChunk(m)) {
|
|
58
|
+
(0, selector_protocol_1.assertSupportedSelector)(m.resource, compilation);
|
|
56
59
|
const icons = resolveUsedIconExports(m, compilation.moduleGraph, runtime);
|
|
57
60
|
if (icons === null) {
|
|
58
61
|
continue;
|
|
59
62
|
}
|
|
60
|
-
const outputRoot = (0, path_1.resolve)((0, path_1.dirname)(m.resource), '../..');
|
|
63
|
+
const outputRoot = (0, path_1.resolve)((0, path_1.dirname)(getPhysicalResource(m.resource)), '../..');
|
|
61
64
|
const packageRoot = (0, path_1.dirname)(outputRoot);
|
|
62
65
|
const usage = packageUsages.get(packageRoot) ?? {
|
|
63
66
|
outputRoots: new Set(),
|
|
@@ -260,7 +263,7 @@ function isFluentUIReactFontChunk(m) {
|
|
|
260
263
|
if (!isNormalModule(m)) {
|
|
261
264
|
return false;
|
|
262
265
|
}
|
|
263
|
-
const resource = m.resource;
|
|
266
|
+
const resource = getPhysicalResource(m.resource);
|
|
264
267
|
if (!resource) {
|
|
265
268
|
return false;
|
|
266
269
|
}
|
|
@@ -270,6 +273,10 @@ function isFluentUIReactFontChunk(m) {
|
|
|
270
273
|
}
|
|
271
274
|
return REACT_ICONS_FONT_MODULE_IMPORT_PATTERN.test(resource);
|
|
272
275
|
}
|
|
276
|
+
function getPhysicalResource(resource) {
|
|
277
|
+
const queryIndex = resource.indexOf('?');
|
|
278
|
+
return queryIndex === -1 ? resource : resource.slice(0, queryIndex);
|
|
279
|
+
}
|
|
273
280
|
/**
|
|
274
281
|
* Maps emitted font assets back to their codepoint tables.
|
|
275
282
|
*
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerSelectorCapability = exports.assertSupportedSelector = void 0;
|
|
4
|
+
const PLUGIN_NAME = 'FluentUIReactIconsFontSubsettingPlugin';
|
|
5
|
+
const SELECTOR_QUERY_KEY = '__fluentIcon';
|
|
6
|
+
const SELECTOR_PROTOCOL_VERSION = 'v1';
|
|
7
|
+
const SELECTOR_PROTOCOL_IDENTIFIER = `${SELECTOR_QUERY_KEY}=${SELECTOR_PROTOCOL_VERSION}`;
|
|
8
|
+
const SELECTOR_CAPABILITY = Symbol.for(`fluentui.react-icons.selector-protocol:${SELECTOR_PROTOCOL_IDENTIFIER}`);
|
|
9
|
+
const SELECTOR_PROTOCOL_PATTERN = new RegExp(`(?:\\?|&)${SELECTOR_QUERY_KEY}=([^&]+)`);
|
|
10
|
+
function assertSupportedSelector(resource, compilation) {
|
|
11
|
+
const match = SELECTOR_PROTOCOL_PATTERN.exec(resource);
|
|
12
|
+
if (match && match[1] !== SELECTOR_PROTOCOL_VERSION) {
|
|
13
|
+
compilation.errors.push(new Error(`${PLUGIN_NAME}: unsupported Fluent icon selector protocol "${match[1]}" ` +
|
|
14
|
+
`(expected "${SELECTOR_PROTOCOL_VERSION}") in "${resource}".`));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.assertSupportedSelector = assertSupportedSelector;
|
|
18
|
+
function registerSelectorCapability(compilation) {
|
|
19
|
+
const target = compilation;
|
|
20
|
+
let capabilities = target[SELECTOR_CAPABILITY];
|
|
21
|
+
if (!capabilities) {
|
|
22
|
+
capabilities = new Set();
|
|
23
|
+
target[SELECTOR_CAPABILITY] = capabilities;
|
|
24
|
+
}
|
|
25
|
+
capabilities.add('fonts');
|
|
26
|
+
}
|
|
27
|
+
exports.registerSelectorCapability = registerSelectorCapability;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui/react-icons-font-subsetting-webpack-plugin",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.342",
|
|
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": {
|