@plaudit/webpack-extensions 2.17.0 → 2.18.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.
@@ -25,6 +25,10 @@ function mapToRealEntrypoints(entrypoint, dir, mapper = (entrypoint) => entrypoi
25
25
  return [joinPossiblyAbsolutePaths(node_path_1.default.basename(parsedEntrypoint.dir), parsedEntrypoint.name), { import: ep }];
26
26
  });
27
27
  }
28
+ let isInThemeCache = undefined;
29
+ function isInTheme() {
30
+ return isInThemeCache ?? (isInThemeCache = node_fs_1.default.existsSync(node_path_1.default.join(process.cwd(), "theme.json")));
31
+ }
28
32
  function isTruthy(value) {
29
33
  return !!value;
30
34
  }
@@ -317,14 +321,27 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
317
321
  [baseDest.includes('.') ? node_path_1.default.basename(baseDest, node_path_1.default.extname(baseDest)) : baseDest]: srcRoot
318
322
  });
319
323
  }
324
+ const outPath = joinPossiblyAbsolutePaths(process.cwd(), srcIsDirectory ? destPath : node_path_1.default.dirname(destPath));
325
+ let publicPath = webpackConfig.output?.publicPath;
326
+ if (isInTheme()) {
327
+ let prefix = process.cwd();
328
+ while (prefix.length > 5 && node_path_1.default.basename(prefix) !== "wp-content") {
329
+ prefix = node_path_1.default.dirname(prefix);
330
+ }
331
+ if (prefix.length > 5) {
332
+ prefix = node_path_1.default.dirname(prefix);
333
+ publicPath = `/${node_path_1.default.relative(prefix, outPath)}/`;
334
+ }
335
+ }
320
336
  return {
321
337
  ...webpackConfig,
322
338
  devtool: 'source-map',
323
339
  mode: "production",
324
340
  output: {
325
341
  ...webpackConfig.output,
326
- path: joinPossiblyAbsolutePaths(process.cwd(), srcIsDirectory ? destPath : node_path_1.default.dirname(destPath)),
342
+ path: outPath,
327
343
  chunkFilename: 'webpack-chunks/[id].js',
344
+ publicPath: publicPath
328
345
  },
329
346
  stats: config.stats ?? 'errors-warnings',
330
347
  plugins: copyFiles
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.17.0",
3
+ "version": "2.18.0",
4
4
  "scripts": {
5
5
  "prepublishOnly": "rm -rf build && mkdir build && tsc",
6
6
  "build": "tsc",