@plaudit/webpack-extensions 2.83.1 → 2.84.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/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.84.0] - 2026-01-30
9
+ ### Added
10
+ - Support for using `lazyLoader` on plain entrypoints
11
+
8
12
  ## [2.83.1] - 2026-01-27
9
13
  ### Fixed
10
14
  - An issue wherein the theme-level styles would pollute the editor's UI styles
@@ -1,14 +1,14 @@
1
- import { BlockEntrypointInfo, ParsedAssetJsonProvider, NormalizedUsageLocations } from "../shared";
1
+ import { BlockEntrypointInfo, ParsedAssetJsonProvider, VerifiedAdvancedOutputConfig } from "../shared";
2
2
  import type { VerifiedPlauditWordpressWebpackConfig } from "../utils/common-config-helpers";
3
3
  import { AbstractBiPhasicGroupAndEntryPlugin, EntryProvider } from "./AbstractBiPhasicGroupAndEntryPlugin";
4
4
  import { Compilation } from "webpack";
5
5
  export declare class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryPlugin<BlockEntrypointInfo> {
6
6
  private readonly buildRoot;
7
7
  private readonly outputDir;
8
- private readonly usageLocations;
8
+ private readonly dest;
9
9
  private readonly useUnifiedLoader;
10
10
  private static readonly semaphore;
11
- constructor(config: VerifiedPlauditWordpressWebpackConfig, buildRoot: string, outputDir: string, usageLocations: NormalizedUsageLocations, useUnifiedLoader: boolean, context: string, entry: EntryProvider<BlockEntrypointInfo>);
11
+ constructor(config: VerifiedPlauditWordpressWebpackConfig, buildRoot: string, outputDir: string, dest: VerifiedAdvancedOutputConfig, useUnifiedLoader: boolean, context: string, entry: EntryProvider<BlockEntrypointInfo>);
12
12
  private generatePlainEntrypointsLoader;
13
13
  private static addHandlesToHandleLists;
14
14
  private static appendEnqueuingHandleLists;
@@ -15,14 +15,14 @@ const webpack_1 = require("webpack");
15
15
  class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAndEntryPlugin_1.AbstractBiPhasicGroupAndEntryPlugin {
16
16
  buildRoot;
17
17
  outputDir;
18
- usageLocations;
18
+ dest;
19
19
  useUnifiedLoader;
20
20
  static semaphore = new pseduo_semaphore_1.PseudoSemaphore("Plain");
21
- constructor(config, buildRoot, outputDir, usageLocations, useUnifiedLoader, context, entry) {
21
+ constructor(config, buildRoot, outputDir, dest, useUnifiedLoader, context, entry) {
22
22
  super(config, "plain-entrypoints-v2", [PlainEntrypointsConfigFileGeneratorPlugin.semaphore, UnifiedLoaderGenerator_1.UnifiedLoaderGenerator.semaphore], context, entry);
23
23
  this.buildRoot = buildRoot;
24
24
  this.outputDir = outputDir;
25
- this.usageLocations = usageLocations;
25
+ this.dest = dest;
26
26
  this.useUnifiedLoader = useUnifiedLoader;
27
27
  }
28
28
  generatePlainEntrypointsLoader(compilation, assets) {
@@ -41,7 +41,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
41
41
  .map(handle => [handle.handleName, handle.src]))]));
42
42
  const plainEntrypointsConfig = { scriptHandles: {}, script_moduleHandles: {}, styleHandles: {} };
43
43
  for (const { handles, handlePrefix } of assets) {
44
- for (const { src, rest, locations, type, handleName } of handles) {
44
+ for (const { src, rest, locations, type, handleName, lazyLoader } of handles) {
45
45
  const basename = node_path_1.default.basename(src).replace(/_(?:script(?:-\d+)?\.js|style(?:-\d+)?\.css)$|(?<!_(script|style))\.(js|css)$/, "");
46
46
  let finalHandleName;
47
47
  if (typeof handleName === 'string') {
@@ -55,12 +55,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
55
55
  }
56
56
  handleNameMap[finalHandleName] = src;
57
57
  }
58
- plainEntrypointsConfig[`${type}Handles`][finalHandleName] = {
59
- src,
60
- rest,
61
- locations,
62
- type
63
- };
58
+ plainEntrypointsConfig[`${type}Handles`][finalHandleName] = { src, rest, locations, type, lazyLoader };
64
59
  }
65
60
  }
66
61
  PlainEntrypointsConfigFileGeneratorPlugin.addHandlesToHandleLists('script', Object.entries(plainEntrypointsConfig.scriptHandles)
@@ -105,6 +100,25 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
105
100
  writer.call("add_editor_style", [(0, shared_1.leadingSlashIt)(handlePath)]);
106
101
  }
107
102
  }
103
+ const lazyLoadedHandles = Object.values(handleLists)
104
+ .flatMap(handleList => handleList.map(handle => [handle.data.lazyLoader, handle]))
105
+ .filter((entry) => entry[0] !== undefined)
106
+ .sort((a, b) => a[0].localeCompare(b[0]) || a[1].priority - b[1].priority);
107
+ if (lazyLoadedHandles.length > 0) {
108
+ writer.linebreak();
109
+ const groupedLazyLoadedHandles = Object.entries(lazyLoadedHandles
110
+ .reduce((a, b) => {
111
+ (a[b[0]] ??= []).push(b[1]);
112
+ return a;
113
+ }, {}));
114
+ for (const [lazyLoader, handles] of groupedLazyLoadedHandles) {
115
+ writer.function(lazyLoader, [], writer => {
116
+ for (const handle of handles) {
117
+ writer.call(`wp_enqueue_${handle.type}`, [handle.handle]);
118
+ }
119
+ }, { returnType: "void" });
120
+ }
121
+ }
108
122
  (0, shared_1.emitPHPWriterAsAsset)(writer, compilation, "plain-entrypoints-loader.php");
109
123
  }
110
124
  static addHandlesToHandleLists(type, handles, handleLists) {
@@ -151,11 +165,12 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
151
165
  else {
152
166
  continue;
153
167
  }
154
- handleLists[location].push({ handle, type, priority, hook_name });
168
+ handleLists[location].push({ data, handle, type, priority, hook_name });
155
169
  }
156
170
  }
157
171
  }
158
172
  static appendEnqueuingHandleLists(writer, handleLists) {
173
+ const lazyLoadableHandles = {};
159
174
  for (const [sln, { action, supports_hook_name, additional_action_code }] of (0, shared_1.constantEntries)(shared_1.standardLocationNamesMeta)) {
160
175
  const handleList = handleLists[sln];
161
176
  if (handleList.length > 0) {
@@ -189,6 +204,7 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
189
204
  }
190
205
  }
191
206
  }
207
+ return lazyLoadableHandles;
192
208
  }
193
209
  static separateHandleListByPriority(handleItems) {
194
210
  const lists = new Map();
@@ -261,13 +277,14 @@ class PlainEntrypointsConfigFileGeneratorPlugin extends AbstractBiPhasicGroupAnd
261
277
  const type = extension === ".js" ? 'script' : (extension === ".mjs" ? 'script_module' : 'style');
262
278
  const isScript = type !== 'style';
263
279
  const dependencies = isScript === entrypointChunkIsScript ? assetData.dependencies : [];
264
- const rest = isScript && this.usageLocations.registerScriptArgs !== undefined
265
- ? [dependencies, assetData.version, this.usageLocations.registerScriptArgs] : [dependencies, assetData.version];
280
+ const { registerScriptArgs } = this.dest.locations;
281
+ const rest = isScript && registerScriptArgs !== undefined ? [dependencies, assetData.version, registerScriptArgs] : [dependencies, assetData.version];
266
282
  const destPath = node_path_1.default.join(compilation.outputOptions.path, file);
267
283
  handles.push({
268
284
  src: destPath, rest, type,
269
- locations: this.usageLocations,
270
- handleName: useHandleName ? this.usageLocations.handle : undefined,
285
+ locations: this.dest.locations,
286
+ handleName: useHandleName ? this.dest.locations.handle : undefined,
287
+ lazyLoader: this.dest.lazyLoader
271
288
  });
272
289
  }
273
290
  myAssetHandles.push({ handles, handlePrefix: this.config.targetHandlePrefix });
@@ -548,7 +548,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, canClean
548
548
  const entry = srcIsDirectory // This being true implies that srcRoot is not an array
549
549
  ? (0, common_config_helpers_1.resolveEntryFromDirectory)(commonConfig, srcRoot, dest)
550
550
  : () => ({ [baseDest]: { import: Array.isArray(srcRoot) ? srcRoot : [srcRoot], plauditMetadata: { purpose: "plain-entrypoint", dest, absoluteSrc } } });
551
- plugin = new PlainEntrypointsConfigFileGeneratorPlugin_1.PlainEntrypointsConfigFileGeneratorPlugin(config, process.cwd(), config.outputDir, dest.locations, config.useUnifiedLoader, contextPath, entry);
551
+ plugin = new PlainEntrypointsConfigFileGeneratorPlugin_1.PlainEntrypointsConfigFileGeneratorPlugin(config, process.cwd(), config.outputDir, dest, config.useUnifiedLoader, contextPath, entry);
552
552
  }
553
553
  else {
554
554
  if (srcIsDirectory) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.83.1",
3
+ "version": "2.84.0",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "files": [
6
6
  "/build",
@@ -25,7 +25,7 @@
25
25
  "devDependencies": {
26
26
  "@plaudit/gutenberg-api-extensions": "^2.84.3",
27
27
  "@types/browser-sync-webpack-plugin": "^2.2.5",
28
- "@types/node": "^25.0.10",
28
+ "@types/node": "^25.1.0",
29
29
  "@types/postcss-functions": "^4.0.4",
30
30
  "@types/tapable": "^2.3.0",
31
31
  "@types/webpack": "^5.28.5",
@@ -42,9 +42,9 @@
42
42
  "@plaudit/postcss-silent-extend": "^3.0.0",
43
43
  "@plaudit/postcss-strip-units": "^3.0.0",
44
44
  "@plaudit/postcss-variables": "^1.1.0",
45
- "@wordpress/dependency-extraction-webpack-plugin": "^6.38.0",
46
- "@wordpress/scripts": "^31.3.0",
47
- "autoprefixer": "^10.4.23",
45
+ "@wordpress/dependency-extraction-webpack-plugin": "^6.39.0",
46
+ "@wordpress/scripts": "^31.4.0",
47
+ "autoprefixer": "^10.4.24",
48
48
  "browser-sync": "^3.0.4",
49
49
  "copy-webpack-plugin": "10.2.4",
50
50
  "css-minimizer-webpack-plugin": "^6.0.0",