@plaudit/webpack-extensions 2.23.0 → 2.24.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,2 +1,3 @@
|
|
|
1
|
+
import type { Options as PostcssFunctionsOptions } from "postcss-functions";
|
|
1
2
|
import type { PostCSSLoaderOptions } from "postcss-loader/dist/config";
|
|
2
|
-
export declare function postcssConfigBuilder(verbose: boolean, variables: (name: string) => string | undefined): PostCSSLoaderOptions;
|
|
3
|
+
export declare function postcssConfigBuilder(verbose: boolean, variables: (name: string) => string | undefined, postCSSFunctions: (variables: (name: string) => unknown) => PostcssFunctionsOptions): PostCSSLoaderOptions;
|
|
@@ -57,13 +57,22 @@ const nanoConfig = {
|
|
|
57
57
|
}
|
|
58
58
|
]
|
|
59
59
|
};
|
|
60
|
-
function
|
|
60
|
+
function makeDefaultPostCSSFunctions(variables) {
|
|
61
|
+
const magnitude = new Intl.NumberFormat("en-US", { maximumFractionDigits: 4 });
|
|
62
|
+
return {
|
|
63
|
+
pxAsRem(value) {
|
|
64
|
+
return value ? `${magnitude.format(parseFloat(value.toString()) / (variables("font_size") || 16))}rem` : "1rem";
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function postcssConfigBuilder(verbose, variables, postCSSFunctions) {
|
|
61
69
|
return {
|
|
62
70
|
plugins: [
|
|
63
71
|
require("postcss-import")(), // Once
|
|
64
72
|
require("@plaudit/postcss-silent-extend")({ warnOfUnused: verbose }), // Once (marks), OnceExit (apply)
|
|
65
73
|
require("postcss-mixins")(), // There is a PostCSS 8 version, but we're forced to use the old one because the new one uses AtRule, which is too late in the process
|
|
66
74
|
require("@plaudit/postcss-variables")({ variables }), // Once
|
|
75
|
+
require("postcss-functions")({ functions: { ...makeDefaultPostCSSFunctions(variables), ...postCSSFunctions(variables) } }),
|
|
67
76
|
require("postcss-quantity-queries")(), // Legacy
|
|
68
77
|
require("postcss-short-position")(), // Legacy
|
|
69
78
|
require("postcss-short-size")(), // Legacy
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Options as PostcssFunctionsOptions } from "postcss-functions";
|
|
1
2
|
import type { Configuration } from "webpack";
|
|
2
3
|
interface AdvancedOutputConfig {
|
|
3
4
|
destination: string;
|
|
@@ -11,6 +12,9 @@ type PlauditWordpressWebpackConfig = {
|
|
|
11
12
|
verbose?: boolean;
|
|
12
13
|
src: string[] | Record<string, string | AdvancedOutputConfig>;
|
|
13
14
|
stats?: Configuration['stats'];
|
|
15
|
+
postcss?: {
|
|
16
|
+
functions?: (variables: (name: string) => unknown) => PostcssFunctionsOptions;
|
|
17
|
+
};
|
|
14
18
|
};
|
|
15
19
|
declare const _default: (config: PlauditWordpressWebpackConfig, webpackConfig?: Configuration[] | Configuration) => Configuration[];
|
|
16
20
|
export = _default;
|
|
@@ -146,9 +146,9 @@ function replaceDefaultURLProcessing(webpackConfig) {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
function injectPostcssConfigOverrides(webpackConfig, variables, verbose) {
|
|
149
|
+
function injectPostcssConfigOverrides(webpackConfig, variables, postcssFunctionsConfig, verbose) {
|
|
150
150
|
if (webpackConfig.module?.rules) {
|
|
151
|
-
const postcssConfig = (0, static_configs_1.postcssConfigBuilder)(verbose, name => variables(name) ?? (name === 'ENV' ? '' : undefined));
|
|
151
|
+
const postcssConfig = (0, static_configs_1.postcssConfigBuilder)(verbose, name => variables(name) ?? (name === 'ENV' ? '' : undefined), postcssFunctionsConfig);
|
|
152
152
|
return webpackConfig.module.rules.map(rule => {
|
|
153
153
|
if (isTruthy(rule) && typeof rule === 'object') {
|
|
154
154
|
if (Array.isArray(rule.use)) {
|
|
@@ -227,7 +227,7 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
|
|
|
227
227
|
const { standaloneBlocks, variablesFilePath, verbose } = config;
|
|
228
228
|
let currentVariables = config.currentVariables;
|
|
229
229
|
replaceDefaultURLProcessing(webpackConfig);
|
|
230
|
-
const fixedRules = injectPostcssConfigOverrides(webpackConfig, name => currentVariables[name], verbose);
|
|
230
|
+
const fixedRules = injectPostcssConfigOverrides(webpackConfig, name => currentVariables[name], config.postcss.functions ?? (() => ({})), verbose);
|
|
231
231
|
return sources.map(([src, dest]) => {
|
|
232
232
|
const srcRoots = (typeof dest !== 'string' && dest.withLegacyBlocksIn
|
|
233
233
|
? [...src.split(','), ...resolveLegacyBlockScriptsInFolder(dest.withLegacyBlocksIn)]
|
|
@@ -423,13 +423,13 @@ function processIndividualWebpackConfig(config, webpackConfig, sources) {
|
|
|
423
423
|
}
|
|
424
424
|
module.exports = function (config, webpackConfig = require("@wordpress/scripts/config/webpack.config")) {
|
|
425
425
|
testForDuplicatedEntryPaths(config);
|
|
426
|
-
const { standaloneBlocks = false, stats = 'errors-warnings', variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true' } = config;
|
|
426
|
+
const { standaloneBlocks = false, stats = 'errors-warnings', variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true', postcss = {} } = config;
|
|
427
427
|
let variablesFilePath = undefined;
|
|
428
428
|
const currentVariables = rawVariables ?? {};
|
|
429
429
|
if (!rawVariables) {
|
|
430
430
|
variablesFilePath = ["variables.js", "src/site/variables.js"].map(p => node_path_1.default.join(process.cwd(), p)).filter(p => node_fs_1.default.existsSync(p))[0];
|
|
431
431
|
}
|
|
432
|
-
const cfg = { currentVariables, standaloneBlocks, stats, variablesFilePath, verbose };
|
|
432
|
+
const cfg = { currentVariables, postcss, standaloneBlocks, stats, variablesFilePath, verbose };
|
|
433
433
|
const sources = Array.isArray(config.src) ? config.src.map(s => [s, s]) : Object.entries(config.src);
|
|
434
434
|
if (Array.isArray(webpackConfig)) {
|
|
435
435
|
return webpackConfig.flatMap(wpCfg => processIndividualWebpackConfig(cfg, wpCfg, sources));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/webpack-extensions",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.24.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepublishOnly": "rm -rf build && mkdir build && tsc",
|
|
6
6
|
"build": "tsc",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/browser-sync-webpack-plugin": "^2.2.5",
|
|
24
|
+
"@types/postcss-functions": "^4.0.3",
|
|
24
25
|
"@types/node": "^20.12.12",
|
|
25
26
|
"@types/tapable": "^2.2.7",
|
|
26
27
|
"@types/webpack": "^5.28.5",
|