@plaudit/webpack-extensions 2.0.0-beta.9 → 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[];
|
|
@@ -6,11 +6,11 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
6
6
|
const node_path_1 = __importDefault(require("node:path"));
|
|
7
7
|
const AdditionalDependencyInjectorPlugin_1 = __importDefault(require("./wordpress-scripts-wrapper/AdditionalDependencyInjectorPlugin"));
|
|
8
8
|
const BlockJSONStyleRemappingPlugin_1 = __importDefault(require("./wordpress-scripts-wrapper/BlockJSONStyleRemappingPlugin"));
|
|
9
|
+
const browser_sync_webpack_plugin_1 = __importDefault(require("browser-sync-webpack-plugin"));
|
|
9
10
|
const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
|
|
10
11
|
const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
|
|
11
12
|
const webpack_remove_empty_scripts_1 = __importDefault(require("webpack-remove-empty-scripts"));
|
|
12
13
|
const cssnano_1 = __importDefault(require("cssnano"));
|
|
13
|
-
const browser_sync_webpack_plugin_1 = __importDefault(require("browser-sync-webpack-plugin"));
|
|
14
14
|
function joinPossiblyAbsolutePaths(...paths) {
|
|
15
15
|
return paths.reduce((res, p) => !res || node_path_1.default.isAbsolute(p) ? p : node_path_1.default.join(res, p), '') || '.';
|
|
16
16
|
}
|
|
@@ -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();
|
|
@@ -155,11 +165,17 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
155
165
|
plugins.push(new BlockJSONStyleRemappingPlugin_1.default());
|
|
156
166
|
}
|
|
157
167
|
plugins.push(new AdditionalDependencyInjectorPlugin_1.default());
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
168
|
+
if (first) {
|
|
169
|
+
first = false;
|
|
170
|
+
if (process.argv.includes('--browser-sync') || process.env['BROWSER_SYNC'] === 'true') {
|
|
171
|
+
plugins.push(new browser_sync_webpack_plugin_1.default({
|
|
172
|
+
host: 'localhost',
|
|
173
|
+
port: 3000,
|
|
174
|
+
https: true,
|
|
175
|
+
proxy: 'https://localhost:8443'
|
|
176
|
+
}));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
163
179
|
let entry;
|
|
164
180
|
if (srcIsDirectory) {
|
|
165
181
|
entry = node_fs_1.default.readdirSync(srcRoot, 'utf8')
|
|
@@ -231,33 +247,9 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
231
247
|
path: joinPossiblyAbsolutePaths(process.cwd(), node_path_1.default.dirname(dest))
|
|
232
248
|
};
|
|
233
249
|
}
|
|
234
|
-
let devServer = undefined;
|
|
235
|
-
if (first) {
|
|
236
|
-
first = false;
|
|
237
|
-
devServer = {
|
|
238
|
-
devMiddleware: {
|
|
239
|
-
writeToDisk: true,
|
|
240
|
-
},
|
|
241
|
-
static: {
|
|
242
|
-
directory: '/'
|
|
243
|
-
},
|
|
244
|
-
proxy: {
|
|
245
|
-
'/': {
|
|
246
|
-
target: 'https://localhost:8443',
|
|
247
|
-
changeOrigin: false,
|
|
248
|
-
secure: false
|
|
249
|
-
},
|
|
250
|
-
},
|
|
251
|
-
allowedHosts: 'all',
|
|
252
|
-
host: 'localhost',
|
|
253
|
-
port: 3000,
|
|
254
|
-
server: 'https'
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
250
|
return {
|
|
258
251
|
...webpackConfig,
|
|
259
252
|
devtool: 'source-map',
|
|
260
|
-
// devServer,
|
|
261
253
|
output: {
|
|
262
254
|
...webpackConfig.output,
|
|
263
255
|
...output
|