@plaudit/webpack-extensions 2.21.3 → 2.23.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,36 @@ 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
+ }
173
+ }
174
+ if (rule.type === "asset/inline" && rule.test instanceof RegExp && rule.issuer instanceof RegExp && rule.test.test("test.svg") && rule.issuer.test("test.pcss")) {
175
+ rule.type = "asset/resource";
176
+ rule.generator = { filename: "images/[name].[hash:8][ext]" };
164
177
  }
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
178
+ if (typeof rule.generator === 'object') {
179
+ const ruleGeneratorFilename = rule.generator["filename"];
180
+ if (typeof ruleGeneratorFilename === 'string' && (ruleGeneratorFilename.startsWith("images/") || ruleGeneratorFilename.startsWith("fonts/"))) {
181
+ rule.generator["filename"] = `../${ruleGeneratorFilename}`;
182
+ }
167
183
  }
168
184
  }
169
185
  return rule;
@@ -210,7 +226,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
210
226
  }
211
227
  const { standaloneBlocks, variablesFilePath, verbose } = config;
212
228
  let currentVariables = config.currentVariables;
213
- disableDefaultURLProcessing(webpackConfig);
229
+ replaceDefaultURLProcessing(webpackConfig);
214
230
  const fixedRules = injectPostcssConfigOverrides(webpackConfig, name => currentVariables[name], verbose);
215
231
  return sources.map(([src, dest]) => {
216
232
  const srcRoots = (typeof dest !== 'string' && dest.withLegacyBlocksIn
@@ -347,6 +363,26 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
347
363
  publicPath = `/${node_path_1.default.relative(prefix, outPath)}/`;
348
364
  }
349
365
  }
366
+ let viableRoots = [...(Array.isArray(webpackConfig.context) ? webpackConfig.context : [webpackConfig.context ?? process.cwd()])];
367
+ if (Array.isArray(srcRoot)) {
368
+ viableRoots.push(...(srcIsDirectory ? srcRoot : srcRoot.map(s => node_path_1.default.dirname(s))));
369
+ }
370
+ else {
371
+ viableRoots.push(srcIsDirectory ? srcRoot : node_path_1.default.dirname(srcRoot));
372
+ }
373
+ let wpContentHolderDirectory = process.cwd();
374
+ while (wpContentHolderDirectory.length > 5) {
375
+ if (node_path_1.default.basename(wpContentHolderDirectory) === 'wp-content') {
376
+ wpContentHolderDirectory = node_path_1.default.dirname(wpContentHolderDirectory);
377
+ if (wpContentHolderDirectory.length > 5) {
378
+ viableRoots.push(wpContentHolderDirectory);
379
+ }
380
+ break;
381
+ }
382
+ wpContentHolderDirectory = node_path_1.default.dirname(wpContentHolderDirectory);
383
+ }
384
+ const distinctViableRoots = new Set();
385
+ viableRoots = viableRoots.filter(value => distinctViableRoots.has(value) ? false : distinctViableRoots.add(value) && true);
350
386
  return {
351
387
  ...webpackConfig,
352
388
  devtool: 'source-map',
@@ -363,6 +399,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
363
399
  },
364
400
  resolve: {
365
401
  ...webpackConfig.resolve,
402
+ roots: viableRoots,
366
403
  extensions: ['.mjsx', '.mjs', '.mtsx', '.mts', '.jsx', '.tsx', '.ts', '...']
367
404
  },
368
405
  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.23.0",
4
4
  "scripts": {
5
5
  "prepublishOnly": "rm -rf build && mkdir build && tsc",
6
6
  "build": "tsc",