@plaudit/webpack-extensions 2.0.0 → 2.0.1
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.
|
@@ -2,6 +2,7 @@ import type { Configuration } from "webpack";
|
|
|
2
2
|
interface PlauditWordpressWebpackConfig {
|
|
3
3
|
legacyPostcssPlugins?: boolean;
|
|
4
4
|
variables?: Record<string, any>;
|
|
5
|
+
verbose?: boolean;
|
|
5
6
|
src: string[] | Record<string, string>;
|
|
6
7
|
}
|
|
7
8
|
declare const _default: (config: PlauditWordpressWebpackConfig, webpackConfig?: Configuration) => Configuration[];
|
|
@@ -24,7 +24,7 @@ function addEntryPointWithMapper(entrypoints, entrypoint, dir, mapper = (entrypo
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
module.exports = function (config, webpackConfig = require("@wordpress/scripts/config/webpack.config")) {
|
|
27
|
-
const { legacyPostcssPlugins = false, variables = ["variables.js", "preprocess/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] ?? {}, } = config;
|
|
27
|
+
const { legacyPostcssPlugins = false, variables = ["variables.js", "preprocess/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') } = config;
|
|
28
28
|
// Nano Config
|
|
29
29
|
// http://cssnano.co/guides/optimisations/ For the value to use click on one and then
|
|
30
30
|
const nanoConfig = {
|
|
@@ -85,6 +85,7 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
+
let currentEntrypoint = '';
|
|
88
89
|
if (webpackConfig.module?.rules) {
|
|
89
90
|
// Options: calc
|
|
90
91
|
const calcOptions = { precision: 4, mediaQueries: true, selectors: true };
|
|
@@ -93,9 +94,17 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
93
94
|
const postcssConfig = {
|
|
94
95
|
plugins: [
|
|
95
96
|
require("postcss-import")(),
|
|
96
|
-
require("@plaudit/postcss-silent-extend")(),
|
|
97
|
+
require("@plaudit/postcss-silent-extend")({ warnOfUnused: verbose }),
|
|
97
98
|
require("postcss-mixins")(),
|
|
98
|
-
require("@plaudit/postcss-variables")(variables)
|
|
99
|
+
require("@plaudit/postcss-variables")({ variables: (name, srcNode) => {
|
|
100
|
+
if (variables[name]) {
|
|
101
|
+
return variables[name];
|
|
102
|
+
}
|
|
103
|
+
if (name === 'ENV') { // This is purely a backwards-compatibility issue.
|
|
104
|
+
return currentEntrypoint.endsWith('public.pcss') ? 'PUBLIC' : (currentEntrypoint.endsWith('block-editor.pcss') ? 'EDITOR' : '');
|
|
105
|
+
}
|
|
106
|
+
return undefined;
|
|
107
|
+
} }),
|
|
99
108
|
...(legacyPostcssPlugins ? [
|
|
100
109
|
require("postcss-quantity-queries")(),
|
|
101
110
|
require("postcss-short-position")(),
|
|
@@ -138,6 +147,7 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
138
147
|
let first = true;
|
|
139
148
|
const sources = Array.isArray(config.src) ? config.src.map(s => [s, s]) : Object.entries(config.src);
|
|
140
149
|
return sources.map(([src, dest]) => {
|
|
150
|
+
currentEntrypoint = src;
|
|
141
151
|
const srcRoots = src.split(',');
|
|
142
152
|
const srcRoot = srcRoots.length === 1 ? joinPossiblyAbsolutePaths(process.cwd(), src) : srcRoots.map(s => joinPossiblyAbsolutePaths(process.cwd(), s));
|
|
143
153
|
const srcIsDirectory = !Array.isArray(srcRoot) && node_fs_1.default.lstatSync(srcRoot).isDirectory();
|
|
@@ -157,7 +167,7 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
157
167
|
plugins.push(new AdditionalDependencyInjectorPlugin_1.default());
|
|
158
168
|
if (first) {
|
|
159
169
|
first = false;
|
|
160
|
-
if (process.argv.includes('--browser-sync')) {
|
|
170
|
+
if (process.argv.includes('--browser-sync') || process.env['BROWSER_SYNC'] === 'true') {
|
|
161
171
|
plugins.push(new browser_sync_webpack_plugin_1.default({
|
|
162
172
|
host: 'localhost',
|
|
163
173
|
port: 3000,
|