@plaudit/webpack-extensions 2.50.0 → 2.52.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.
@@ -8,6 +8,7 @@ interface AdvancedOutputConfig {
8
8
  directoryLayout?: 'blocks' | 'extensions' | 'plain';
9
9
  assumeGlobalizedPlauditLibraries?: boolean;
10
10
  externalize?: Required<Configuration>['output']['library'];
11
+ bundleAnalyzer?: boolean;
11
12
  }
12
13
  type PlauditWordpressWebpackConfig = {
13
14
  standaloneBlocks?: boolean;
@@ -23,6 +24,7 @@ type PlauditWordpressWebpackConfig = {
23
24
  processTranslationConfigs?: boolean;
24
25
  combineAssetMetadata?: boolean;
25
26
  useWebpackResourceFiltering?: boolean;
27
+ outputDir?: string;
26
28
  };
27
29
  declare const _default: (config: PlauditWordpressWebpackConfig, webpackConfig?: Configuration[] | Configuration) => Configuration[];
28
30
  export = _default;
@@ -21,7 +21,8 @@ const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
21
21
  const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
22
22
  const webpack_remove_empty_scripts_1 = __importDefault(require("webpack-remove-empty-scripts"));
23
23
  function joinPossiblyAbsolutePaths(...paths) {
24
- return paths.reduce((res, p) => !res || node_path_1.default.isAbsolute(p) ? p : node_path_1.default.join(res, p), '') || '.';
24
+ return paths.filter((p) => !!p)
25
+ .reduce((res, p) => !res || node_path_1.default.isAbsolute(p) ? p : node_path_1.default.join(res, p), '') || '.';
25
26
  }
26
27
  function mapToRealEntrypoints(entrypoint, dir, mapper = (entrypoint) => entrypoint, lazyDependent, associatedQuery) {
27
28
  return (Array.isArray(entrypoint) ? entrypoint : [entrypoint])
@@ -167,7 +168,7 @@ function replaceDefaultURLProcessing(useWebpackResourceFiltering) {
167
168
  }
168
169
  function injectPostcssConfigOverrides(rules, variables, postcssFunctionsConfig, verbose) {
169
170
  const postcssConfig = (0, static_configs_1.postcssConfigBuilder)(verbose, name => variables(name) ?? (name === 'ENV' ? '' : undefined), postcssFunctionsConfig);
170
- return rules.map(rule => {
171
+ return recursivelyAddParentDirectoryStepToImagesAndFonts(rules.map(rule => {
171
172
  if (rule && typeof rule === 'object') {
172
173
  if (Array.isArray(rule.use)) {
173
174
  for (const useItem of rule.use) {
@@ -190,15 +191,32 @@ function injectPostcssConfigOverrides(rules, variables, postcssFunctionsConfig,
190
191
  }
191
192
  }
192
193
  if (rule.type === "asset/inline" && rule.test instanceof RegExp && rule.issuer instanceof RegExp && rule.test.test("test.svg") && rule.issuer.test("test.pcss")) {
193
- rule.type = "asset/resource";
194
- rule.generator = { filename: "images/[name].[hash:8][ext]" };
194
+ const { type: originalType, ...commonRuleParams } = rule;
195
+ return {
196
+ ...commonRuleParams,
197
+ oneOf: [
198
+ { type: originalType, resourceQuery: /string|inline/i },
199
+ { type: "asset/resource", generator: { filename: "images/[name].[hash:8][ext]" } }
200
+ ]
201
+ };
195
202
  }
203
+ }
204
+ return rule;
205
+ }));
206
+ }
207
+ function recursivelyAddParentDirectoryStepToImagesAndFonts(rules) {
208
+ return rules.map(rule => {
209
+ if (rule && typeof rule === 'object') {
196
210
  if (typeof rule.generator === 'object') {
197
211
  const ruleGeneratorFilename = rule.generator["filename"];
198
212
  if (typeof ruleGeneratorFilename === 'string' && (ruleGeneratorFilename.startsWith("images/") || ruleGeneratorFilename.startsWith("fonts/"))) {
199
213
  rule.generator["filename"] = `../${ruleGeneratorFilename}`;
214
+ rule = { ...rule, generator: { ...rule.generator, filename: `../${ruleGeneratorFilename}` } };
200
215
  }
201
216
  }
217
+ if (rule.oneOf) {
218
+ rule = { ...rule, oneOf: recursivelyAddParentDirectoryStepToImagesAndFonts(rule.oneOf) };
219
+ }
202
220
  }
203
221
  return rule;
204
222
  });
@@ -298,6 +316,9 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, sharedCa
298
316
  })
299
317
  ?? [];
300
318
  plugins.splice(0, 0, new PackageConfigSanityChecker_1.PackageConfigSanityChecker());
319
+ if (typeof dest !== 'string' && dest.bundleAnalyzer) {
320
+ plugins.splice(0, 0, new (require("webpack-bundle-analyzer").BundleAnalyzerPlugin)({ analyzerMode: 'static' }));
321
+ }
301
322
  if (process.env["NO_TS_CHECKER"] !== "true") {
302
323
  const include = (Array.isArray(srcRoot) ? srcRoot : [srcRoot])
303
324
  .filter(sr => node_path_1.default.extname(sr).length === 0 || scriptOrStyleTest(sr, scriptExtension) === "script")
@@ -467,7 +488,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, sharedCa
467
488
  [baseDest.includes('.') ? node_path_1.default.basename(baseDest, node_path_1.default.extname(baseDest)) : baseDest]: srcRoot
468
489
  });
469
490
  }
470
- const outPath = joinPossiblyAbsolutePaths(process.cwd(), srcIsDirectory ? destPath : node_path_1.default.dirname(destPath));
491
+ const outPath = joinPossiblyAbsolutePaths(process.cwd(), config.outputDir, srcIsDirectory ? destPath : node_path_1.default.dirname(destPath));
471
492
  let publicPath = webpackConfig.output?.publicPath;
472
493
  if (isInTheme()) {
473
494
  let prefix = process.cwd();
@@ -586,7 +607,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources, sharedCa
586
607
  }
587
608
  module.exports = function (config, webpackConfig = require("@wordpress/scripts/config/webpack.config")) {
588
609
  testForDuplicatedEntryPaths(config);
589
- const { standaloneBlocks = false, stats = 'errors-warnings', variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true', postcss = {}, externals, assumeGlobalizedPlauditLibraries = true, processTranslationConfigs = true, combineAssetMetadata = true, useWebpackResourceFiltering = true } = config;
610
+ const { standaloneBlocks = false, stats = 'errors-warnings', variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true', postcss = {}, externals, assumeGlobalizedPlauditLibraries = true, processTranslationConfigs = true, combineAssetMetadata = true, useWebpackResourceFiltering = true, outputDir = "" } = config;
590
611
  let variablesFilePath = undefined;
591
612
  const currentVariables = rawVariables ?? {};
592
613
  if (!rawVariables) {
@@ -594,7 +615,7 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
594
615
  }
595
616
  const cfg = {
596
617
  currentVariables, postcss, standaloneBlocks, stats, variablesFilePath, verbose, externals, assumeGlobalizedPlauditLibraries, processTranslationConfigs, combineAssetMetadata,
597
- useWebpackResourceFiltering
618
+ useWebpackResourceFiltering, outputDir
598
619
  };
599
620
  const sources = Array.isArray(config.src) ? config.src.map(s => [s, s]) : Object.entries(config.src);
600
621
  const sharedCache = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.50.0",
3
+ "version": "2.52.0",
4
4
  "license": "UNLICENSED",
5
5
  "files": [
6
6
  "/build"
@@ -26,7 +26,8 @@
26
26
  "postcss-load-config": "^4.0.2",
27
27
  "postcss-loader": "^7.3.4",
28
28
  "ts-node": "^10.9.2",
29
- "typescript": "^5.8.3"
29
+ "typescript": "^5.8.3",
30
+ "webpack-bundle-analyzer": "^4.10.2"
30
31
  },
31
32
  "dependencies": {
32
33
  "@plaudit/postcss-color-function": "^5.0.0",