@plaudit/webpack-extensions 2.6.0 → 2.6.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.
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class VariablesJSMonitorPlugin {
|
|
4
|
+
variablesFilePath;
|
|
5
|
+
constructor(variablesFilePath) {
|
|
6
|
+
this.variablesFilePath = variablesFilePath;
|
|
7
|
+
}
|
|
8
|
+
apply(compiler) {
|
|
9
|
+
compiler.hooks.make.tap('VariablesJSMonitorPlugin', compilation => {
|
|
10
|
+
if (!compilation.fileDependencies.has(this.variablesFilePath)) {
|
|
11
|
+
compilation.fileDependencies.add(this.variablesFilePath);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.default = VariablesJSMonitorPlugin;
|
|
@@ -11,6 +11,7 @@ const browser_sync_webpack_plugin_1 = __importDefault(require("browser-sync-webp
|
|
|
11
11
|
const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
|
|
12
12
|
const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
|
|
13
13
|
const webpack_remove_empty_scripts_1 = __importDefault(require("webpack-remove-empty-scripts"));
|
|
14
|
+
const VariablesJSMonitorPlugin_1 = __importDefault(require("./wordpress-scripts-wrapper/VariablesJSMonitorPlugin"));
|
|
14
15
|
function joinPossiblyAbsolutePaths(...paths) {
|
|
15
16
|
return paths.reduce((res, p) => !res || node_path_1.default.isAbsolute(p) ? p : node_path_1.default.join(res, p), '') || '.';
|
|
16
17
|
}
|
|
@@ -138,7 +139,7 @@ function disableDefaultURLProcessing(webpackConfig) {
|
|
|
138
139
|
function injectPostcssConfigOverrides(webpackConfig, variables, verbose) {
|
|
139
140
|
if (webpackConfig.module?.rules) {
|
|
140
141
|
const postcssConfig = (0, static_configs_1.postcssConfigBuilder)(verbose, (name) => {
|
|
141
|
-
return variables
|
|
142
|
+
return variables(name) ?? (name === 'ENV' ? '' : undefined);
|
|
142
143
|
});
|
|
143
144
|
for (const rule of webpackConfig.module.rules) {
|
|
144
145
|
if (isTruthy(rule) && typeof rule === 'object' && Array.isArray(rule.use)) {
|
|
@@ -188,9 +189,14 @@ function parseEntrypointsJSON(dir) {
|
|
|
188
189
|
}
|
|
189
190
|
module.exports = function (config, webpackConfig = require("@wordpress/scripts/config/webpack.config")) {
|
|
190
191
|
testForDuplicatedEntryPaths(config);
|
|
191
|
-
const { standaloneBlocks = false, variables
|
|
192
|
+
const { standaloneBlocks = false, variables: rawVariables, verbose = process.argv.includes('--verbose') || process.env['VERBOSE'] === 'true' } = config;
|
|
193
|
+
let variablesFilePath = undefined;
|
|
194
|
+
let currentVariables = rawVariables ?? {};
|
|
195
|
+
if (!rawVariables) {
|
|
196
|
+
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];
|
|
197
|
+
}
|
|
192
198
|
disableDefaultURLProcessing(webpackConfig);
|
|
193
|
-
injectPostcssConfigOverrides(webpackConfig,
|
|
199
|
+
injectPostcssConfigOverrides(webpackConfig, name => currentVariables[name], verbose);
|
|
194
200
|
let first = true;
|
|
195
201
|
const sources = Array.isArray(config.src) ? config.src.map(s => [s, s]) : Object.entries(config.src);
|
|
196
202
|
return sources.map(([src, dest]) => {
|
|
@@ -214,6 +220,9 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
214
220
|
stage: webpack_remove_empty_scripts_1.default.STAGE_AFTER_PROCESS_PLUGINS,
|
|
215
221
|
extensions: ['css', 'scss', 'sass', 'less', 'styl', 'pcss']
|
|
216
222
|
}));
|
|
223
|
+
if (variablesFilePath) {
|
|
224
|
+
plugins.push(new VariablesJSMonitorPlugin_1.default(variablesFilePath));
|
|
225
|
+
}
|
|
217
226
|
if (copyFiles) {
|
|
218
227
|
plugins.push(new BlockJSONStyleRemappingPlugin_1.default(standaloneBlocks));
|
|
219
228
|
}
|
|
@@ -281,9 +290,9 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
281
290
|
}
|
|
282
291
|
else {
|
|
283
292
|
const baseDest = node_path_1.default.basename(destPath);
|
|
284
|
-
entry = {
|
|
293
|
+
entry = () => ({
|
|
285
294
|
[baseDest.includes('.') ? node_path_1.default.basename(baseDest, node_path_1.default.extname(baseDest)) : baseDest]: srcRoot
|
|
286
|
-
};
|
|
295
|
+
});
|
|
287
296
|
}
|
|
288
297
|
return {
|
|
289
298
|
...webpackConfig,
|
|
@@ -301,7 +310,13 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
301
310
|
: (srcIsDirectory
|
|
302
311
|
? plugins.filter(plugin => plugin.constructor.name !== 'CopyPlugin' && plugin.constructor.name !== 'CleanWebpackPlugin')
|
|
303
312
|
: plugins.filter(plugin => plugin.constructor.name !== 'CopyPlugin')),
|
|
304
|
-
entry
|
|
313
|
+
entry() {
|
|
314
|
+
if (variablesFilePath) {
|
|
315
|
+
delete require.cache[require.resolve(variablesFilePath)];
|
|
316
|
+
currentVariables = require(variablesFilePath);
|
|
317
|
+
}
|
|
318
|
+
return entry();
|
|
319
|
+
}
|
|
305
320
|
};
|
|
306
321
|
});
|
|
307
322
|
};
|