@plaudit/webpack-extensions 2.15.1 → 2.16.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.
|
@@ -5,6 +5,7 @@ export type PluginOptions = {
|
|
|
5
5
|
name: string;
|
|
6
6
|
callback?: (err: Error, bs: BrowserSyncInstance) => any;
|
|
7
7
|
injectCss: boolean;
|
|
8
|
+
middlewareBuilder?: (options: browserSync.Options) => browserSync.Options['middleware'];
|
|
8
9
|
};
|
|
9
10
|
export declare class BrowserSyncPlugin implements WebpackPluginInstance {
|
|
10
11
|
private static isBrowserSyncRunning;
|
|
@@ -31,7 +31,10 @@ class BrowserSyncPlugin {
|
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
33
|
if (!BrowserSyncPlugin.isBrowserSyncRunning) {
|
|
34
|
-
this.
|
|
34
|
+
const middleware = this.pluginOptions.middlewareBuilder?.(this.browserSyncOptions);
|
|
35
|
+
this.browserSyncInstance.init(middleware
|
|
36
|
+
? { ...this.browserSyncOptions, server: { middleware: Array.isArray(middleware) ? middleware : [middleware] } }
|
|
37
|
+
: this.browserSyncOptions, this.pluginOptions.callback);
|
|
35
38
|
BrowserSyncPlugin.isBrowserSyncRunning = true;
|
|
36
39
|
}
|
|
37
40
|
if (this.pluginOptions.reload) {
|
|
@@ -12,6 +12,8 @@ const BrowserSyncPlugin_1 = require("./wordpress-scripts-wrapper/BrowserSyncPlug
|
|
|
12
12
|
const static_configs_1 = require("./wordpress-scripts-wrapper/static-configs");
|
|
13
13
|
const copy_webpack_plugin_1 = __importDefault(require("copy-webpack-plugin"));
|
|
14
14
|
const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
|
|
15
|
+
const http_proxy_middleware_1 = require("http-proxy-middleware");
|
|
16
|
+
const open_1 = __importDefault(require("open"));
|
|
15
17
|
const webpack_remove_empty_scripts_1 = __importDefault(require("webpack-remove-empty-scripts"));
|
|
16
18
|
function joinPossiblyAbsolutePaths(...paths) {
|
|
17
19
|
return paths.reduce((res, p) => !res || node_path_1.default.isAbsolute(p) ? p : node_path_1.default.join(res, p), '') || '.';
|
|
@@ -260,13 +262,53 @@ module.exports = function (config, webpackConfig = require("@wordpress/scripts/c
|
|
|
260
262
|
plugins.push(new ExtensionsConfigFileGeneratorPlugin_1.default(srcRoot));
|
|
261
263
|
}
|
|
262
264
|
if (process.argv.includes('--browser-sync') || process.env['BROWSER_SYNC'] === 'true') {
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
265
|
+
const envFile = loadEnvFile();
|
|
266
|
+
const prefixes = envFile.match(/WORDPRESS_SITES=([^\r\n]+)/i)?.[1]?.split(/\s*,\s*/gi).map(domain => domain + ".");
|
|
267
|
+
const targetPort = envFile.match(/WEB_PORT_SSL=(\d+)/i)?.[1] ?? "8443";
|
|
268
|
+
const targetHost = targetPort === "443" ? "localhost" : `localhost:${targetPort}`;
|
|
269
|
+
if (prefixes === undefined) {
|
|
270
|
+
plugins.push(new BrowserSyncPlugin_1.BrowserSyncPlugin({
|
|
271
|
+
host: 'localhost',
|
|
272
|
+
port: 3000,
|
|
273
|
+
https: true,
|
|
274
|
+
proxy: `https://${targetHost}`
|
|
275
|
+
}));
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
plugins.push(new BrowserSyncPlugin_1.BrowserSyncPlugin({
|
|
279
|
+
port: 3000,
|
|
280
|
+
https: true,
|
|
281
|
+
open: false,
|
|
282
|
+
callbacks: {
|
|
283
|
+
ready(err, bsi) {
|
|
284
|
+
// This ensures that the opened URL is actually a valid one
|
|
285
|
+
(0, open_1.default)(`https://${prefixes[0]}localhost:${bsi.getOption("port") ?? 3000}`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}, {
|
|
289
|
+
middlewareBuilder: (options) => {
|
|
290
|
+
const proxyPort = options.port?.toString() ?? "3000";
|
|
291
|
+
const router = prefixes.reduce((router, prefix) => {
|
|
292
|
+
router[`${prefix}localhost:${proxyPort}`] = {
|
|
293
|
+
protocol: 'https:',
|
|
294
|
+
slashes: true,
|
|
295
|
+
auth: null,
|
|
296
|
+
host: `${prefix}localhost`,
|
|
297
|
+
port: targetPort,
|
|
298
|
+
hostname: targetHost,
|
|
299
|
+
hash: null,
|
|
300
|
+
search: null,
|
|
301
|
+
query: null,
|
|
302
|
+
pathname: '/',
|
|
303
|
+
path: '/',
|
|
304
|
+
href: `https://${targetHost}/`
|
|
305
|
+
};
|
|
306
|
+
return router;
|
|
307
|
+
}, {});
|
|
308
|
+
return (0, http_proxy_middleware_1.createProxyMiddleware)({ changeOrigin: true, router, secure: false, xfwd: true });
|
|
309
|
+
}
|
|
310
|
+
}));
|
|
311
|
+
}
|
|
270
312
|
}
|
|
271
313
|
let entry;
|
|
272
314
|
if (srcIsDirectory) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/webpack-extensions",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.16.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepublishOnly": "rm -rf build && mkdir build && tsc",
|
|
6
6
|
"build": "tsc",
|
|
@@ -18,36 +18,37 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@types/browser-sync-webpack-plugin": "^2.2.
|
|
22
|
-
"@types/node": "^20.11.
|
|
21
|
+
"@types/browser-sync-webpack-plugin": "^2.2.5",
|
|
22
|
+
"@types/node": "^20.11.30",
|
|
23
23
|
"@types/tapable": "^2.2.7",
|
|
24
24
|
"@types/webpack": "^5.28.5",
|
|
25
25
|
"@types/webpack-sources": "^3.2.3",
|
|
26
26
|
"postcss-load-config": "^4.0.2",
|
|
27
27
|
"postcss-loader": "^7.3.4",
|
|
28
28
|
"ts-node": "^10.9.2",
|
|
29
|
-
"typescript": "^5.
|
|
29
|
+
"typescript": "^5.4.3"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@plaudit/postcss-color-function": "^5.0.0",
|
|
33
33
|
"@plaudit/postcss-silent-extend": "^3.0.0",
|
|
34
34
|
"@plaudit/postcss-strip-units": "^3.0.0",
|
|
35
35
|
"@plaudit/postcss-variables": "^1.0.0",
|
|
36
|
-
"@wordpress/scripts": "^27.
|
|
37
|
-
"autoprefixer": "^10.4.
|
|
36
|
+
"@wordpress/scripts": "^27.5.0",
|
|
37
|
+
"autoprefixer": "^10.4.18",
|
|
38
38
|
"browser-sync": "^3.0.2",
|
|
39
39
|
"clean-webpack-plugin": "^4.0.0",
|
|
40
40
|
"copy-webpack-plugin": "^12.0.2",
|
|
41
|
-
"cssnano": "^6.
|
|
41
|
+
"cssnano": "^6.1.1",
|
|
42
42
|
"eslint": "^8.57.0",
|
|
43
|
-
"eslint-plugin-jsdoc": "^48.2.
|
|
43
|
+
"eslint-plugin-jsdoc": "^48.2.1",
|
|
44
44
|
"fork-ts-checker-webpack-plugin": "^9.0.2",
|
|
45
|
-
|
|
45
|
+
"http-proxy-middleware": "^3.0.0-beta.1",
|
|
46
|
+
"postcss": "^8.4.38",
|
|
46
47
|
"postcss-calc": "^9.0.1",
|
|
47
|
-
"postcss-discard-comments": "^6.0.
|
|
48
|
+
"postcss-discard-comments": "^6.0.2",
|
|
48
49
|
"postcss-fallback": "^0.1.0",
|
|
49
50
|
"postcss-functions": "^4.0.2",
|
|
50
|
-
"postcss-import": "^16.0
|
|
51
|
+
"postcss-import": "^16.1.0",
|
|
51
52
|
"postcss-inline-svg": "^6.0.0",
|
|
52
53
|
"postcss-media-minmax": "^5.0.0",
|
|
53
54
|
"postcss-mixins": "6.2.3",
|
|
@@ -62,7 +63,7 @@
|
|
|
62
63
|
"postcss-url": "^10.1.3",
|
|
63
64
|
"react": "^18.2.0",
|
|
64
65
|
"react-dom": "^18.2.0",
|
|
65
|
-
"webpack": "^5.
|
|
66
|
+
"webpack": "^5.91.0",
|
|
66
67
|
"webpack-remove-empty-scripts": "^1.0.4"
|
|
67
68
|
}
|
|
68
69
|
}
|