@plaudit/webpack-extensions 2.21.3 → 2.22.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.
@@ -128,14 +128,18 @@ function testForDuplicatedEntryPaths(config) {
128
128
  process.exit(1);
129
129
  }
130
130
  }
131
- function disableDefaultURLProcessing(webpackConfig) {
131
+ function replaceDefaultURLProcessing(webpackConfig) {
132
132
  const cssLoader = require.resolve('css-loader');
133
133
  if (cssLoader && webpackConfig.module?.rules) {
134
134
  for (const rule of webpackConfig.module.rules) {
135
135
  if (isTruthy(rule) && typeof rule === 'object' && "use" in rule && Array.isArray(rule.use)) {
136
136
  for (const useElement of rule.use) {
137
137
  if (isTruthy(useElement) && typeof useElement === 'object' && useElement.loader === cssLoader && typeof useElement.options === 'object') {
138
- useElement.options['url'] = false;
138
+ useElement.options['url'] = {
139
+ filter(url) {
140
+ return !url.startsWith("/") && !!url.match(/\.(woff|woff2|eot|ttf|otf|png|jpe?g|svg|webp|avif|gif)[^.]*?(\?.*)?/i);
141
+ }
142
+ };
139
143
  }
140
144
  }
141
145
  }
@@ -146,24 +150,32 @@ function injectPostcssConfigOverrides(webpackConfig, variables, verbose) {
146
150
  if (webpackConfig.module?.rules) {
147
151
  const postcssConfig = (0, static_configs_1.postcssConfigBuilder)(verbose, name => variables(name) ?? (name === 'ENV' ? '' : undefined));
148
152
  return webpackConfig.module.rules.map(rule => {
149
- if (isTruthy(rule) && typeof rule === 'object' && Array.isArray(rule.use)) {
150
- for (const useItem of rule.use) {
151
- if (isTruthy(useItem) && typeof useItem === 'object' && typeof useItem.options === 'object') {
152
- if (useItem.options["sourceMap"] === false) {
153
- useItem.options["sourceMap"] = true;
154
- }
155
- if (useItem.loader?.includes('postcss-loader')) {
156
- if (useItem.options["postcssOptions"]) {
157
- useItem.options["postcssOptions"] = { ...useItem.options["postcssOptions"], ...postcssConfig, sourceMap: true };
153
+ if (isTruthy(rule) && typeof rule === 'object') {
154
+ if (Array.isArray(rule.use)) {
155
+ for (const useItem of rule.use) {
156
+ if (isTruthy(useItem) && typeof useItem === 'object' && typeof useItem.options === 'object') {
157
+ if (useItem.options["sourceMap"] === false) {
158
+ useItem.options["sourceMap"] = true;
158
159
  }
159
- else {
160
- useItem.options["postcssOptions"] = { ...postcssConfig, sourceMap: true };
160
+ if (useItem.loader?.includes('postcss-loader')) {
161
+ if (useItem.options["postcssOptions"]) {
162
+ useItem.options["postcssOptions"] = { ...useItem.options["postcssOptions"], ...postcssConfig, sourceMap: true };
163
+ }
164
+ else {
165
+ useItem.options["postcssOptions"] = { ...postcssConfig, sourceMap: true };
166
+ }
161
167
  }
162
168
  }
163
169
  }
170
+ if (rule.test instanceof RegExp && (rule.test.test("index.ts") || rule.test.test("index.mts"))) { // Then this is the javascript and typescript rule
171
+ rule.test = /\.m?[jt]sx?$/; // This hacks in support for mjs and mts files
172
+ }
164
173
  }
165
- if (rule.test instanceof RegExp && (rule.test.test("index.ts") || rule.test.test("index.mts"))) { // Then this is the javascript and typescript rule
166
- rule.test = /\.m?[jt]sx?$/; // This hacks in support for mjs and mts files
174
+ if (typeof rule.generator === 'object') {
175
+ const ruleGeneratorFilename = rule.generator["filename"];
176
+ if (typeof ruleGeneratorFilename === 'string' && (ruleGeneratorFilename.startsWith("images/") || ruleGeneratorFilename.startsWith("fonts/"))) {
177
+ rule.generator["filename"] = `../${ruleGeneratorFilename}`;
178
+ }
167
179
  }
168
180
  }
169
181
  return rule;
@@ -210,7 +222,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
210
222
  }
211
223
  const { standaloneBlocks, variablesFilePath, verbose } = config;
212
224
  let currentVariables = config.currentVariables;
213
- disableDefaultURLProcessing(webpackConfig);
225
+ replaceDefaultURLProcessing(webpackConfig);
214
226
  const fixedRules = injectPostcssConfigOverrides(webpackConfig, name => currentVariables[name], verbose);
215
227
  return sources.map(([src, dest]) => {
216
228
  const srcRoots = (typeof dest !== 'string' && dest.withLegacyBlocksIn
@@ -347,6 +359,26 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
347
359
  publicPath = `/${node_path_1.default.relative(prefix, outPath)}/`;
348
360
  }
349
361
  }
362
+ let viableRoots = [...(Array.isArray(webpackConfig.context) ? webpackConfig.context : [webpackConfig.context ?? process.cwd()])];
363
+ if (Array.isArray(srcRoot)) {
364
+ viableRoots.push(...(srcIsDirectory ? srcRoot : srcRoot.map(s => node_path_1.default.dirname(s))));
365
+ }
366
+ else {
367
+ viableRoots.push(srcIsDirectory ? srcRoot : node_path_1.default.dirname(srcRoot));
368
+ }
369
+ let wpContentHolderDirectory = process.cwd();
370
+ while (wpContentHolderDirectory.length > 5) {
371
+ if (node_path_1.default.basename(wpContentHolderDirectory) === 'wp-content') {
372
+ wpContentHolderDirectory = node_path_1.default.dirname(wpContentHolderDirectory);
373
+ if (wpContentHolderDirectory.length > 5) {
374
+ viableRoots.push(wpContentHolderDirectory);
375
+ }
376
+ break;
377
+ }
378
+ wpContentHolderDirectory = node_path_1.default.dirname(wpContentHolderDirectory);
379
+ }
380
+ const distinctViableRoots = new Set();
381
+ viableRoots = viableRoots.filter(value => distinctViableRoots.has(value) ? false : distinctViableRoots.add(value) && true);
350
382
  return {
351
383
  ...webpackConfig,
352
384
  devtool: 'source-map',
@@ -363,6 +395,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
363
395
  },
364
396
  resolve: {
365
397
  ...webpackConfig.resolve,
398
+ roots: viableRoots,
366
399
  extensions: ['.mjsx', '.mjs', '.mtsx', '.mts', '.jsx', '.tsx', '.ts', '...']
367
400
  },
368
401
  stats: config.stats,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/webpack-extensions",
3
- "version": "2.21.3",
3
+ "version": "2.22.0",
4
4
  "scripts": {
5
5
  "prepublishOnly": "rm -rf build && mkdir build && tsc",
6
6
  "build": "tsc",