@plaudit/webpack-extensions 2.2.0 → 2.3.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.
@@ -1,5 +1,7 @@
1
1
  import type { Compiler, WebpackPluginInstance } from "webpack";
2
2
  export default class BlockJSONStyleRemappingPlugin implements WebpackPluginInstance {
3
+ private readonly standaloneBlocks;
4
+ constructor(standaloneBlocks: boolean);
3
5
  apply(compiler: Compiler): void;
4
6
  findCommonAncestor(...paths: string[]): string[];
5
7
  findRelativeRouteBetween(path1: string, path2: string): string;
@@ -7,6 +7,10 @@ const node_fs_1 = __importDefault(require("node:fs"));
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
8
  const webpack_sources_1 = require("webpack-sources");
9
9
  class BlockJSONStyleRemappingPlugin {
10
+ standaloneBlocks;
11
+ constructor(standaloneBlocks) {
12
+ this.standaloneBlocks = standaloneBlocks;
13
+ }
10
14
  apply(compiler) {
11
15
  compiler.hooks.compilation.tap("BlockJSONStyleRemappingPlugin", compilation => {
12
16
  compilation.hooks.afterProcessAssets.tap("BlockJSONStyleRemappingPlugin_ProcessAssets", compilationAssets => {
@@ -70,7 +74,7 @@ class BlockJSONStyleRemappingPlugin {
70
74
  }
71
75
  }
72
76
  }
73
- if (json["plaudit"] !== "simple") {
77
+ if (!this.standaloneBlocks && json["plaudit"] !== "simple") {
74
78
  const sourceDir = node_path_1.default.join(compiler.context, dirname);
75
79
  const outputDir = node_path_1.default.join(compiler.outputPath, node_path_1.default.dirname(name));
76
80
  const stripFilePrefix = (file) => file.startsWith("file:./") ? file.substring(7) : file;
@@ -1,5 +1,6 @@
1
1
  import type { Configuration } from "webpack";
2
2
  interface PlauditWordpressWebpackConfig {
3
+ standaloneBlocks?: boolean;
3
4
  variables?: Record<string, any>;
4
5
  verbose?: boolean;
5
6
  src: string[] | Record<string, string>;
@@ -106,7 +106,7 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
106
106
  console.error(`Encountered multiple paths that produce the same effective bundle name:${duplicatedPaths}`);
107
107
  process.exit(1);
108
108
  }
109
- const { variables = ["variables.js", "src/site/variables.js"].map(p => node_path_1.default.join(process.cwd(), p)).filter(p => node_fs_1.default.existsSync(p)).map(p => require(p))[0] ?? {}, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true' } = config;
109
+ const { standaloneBlocks = false, variables = ["variables.js", "src/site/variables.js"].map(p => node_path_1.default.join(process.cwd(), p)).filter(p => node_fs_1.default.existsSync(p)).map(p => require(p))[0] ?? {}, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true' } = config;
110
110
  const cssLoader = require.resolve('css-loader');
111
111
  if (cssLoader && webpackConfig.module?.rules) {
112
112
  for (const rule of webpackConfig.module.rules) {
@@ -169,7 +169,7 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
169
169
  }
170
170
  }), new webpack_remove_empty_scripts_1.default({ stage: webpack_remove_empty_scripts_1.default.STAGE_AFTER_PROCESS_PLUGINS, extensions: ['css', 'scss', 'sass', 'less', 'styl', 'pcss'] }));
171
171
  if (copyFiles) {
172
- plugins.push(new BlockJSONStyleRemappingPlugin_1.default());
172
+ plugins.push(new BlockJSONStyleRemappingPlugin_1.default(standaloneBlocks));
173
173
  }
174
174
  plugins.push(new AdditionalDependencyInjectorPlugin_1.default());
175
175
  if (first) {
@@ -279,7 +279,8 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
279
279
  },
280
280
  plugins: copyFiles
281
281
  ? plugins.map(plugin => plugin.constructor.name === 'CopyPlugin'
282
- ? new copy_webpack_plugin_1.default({ patterns: [{ from: '**/(block.json|*.(php|twig|svg))', context: srcRoot, noErrorOnMissing: true }] })
282
+ ? new copy_webpack_plugin_1.default({ patterns: [{ from: standaloneBlocks ? '**/(block.json|*.(php|twig|svg))' : '**/(block.json|*.(asset\.php|svg))',
283
+ context: srcRoot, noErrorOnMissing: true }] })
283
284
  : plugin)
284
285
  : (srcIsDirectory
285
286
  ? plugins.filter(plugin => plugin.constructor.name !== 'CopyPlugin' && plugin.constructor.name !== 'CleanWebpackPlugin')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "scripts": {
5
5
  "prepublishOnly": "rm -rf build && mkdir build && tsc",
6
6
  "build": "tsc",