@umijs/bundler-webpack 4.1.9 → 4.1.10

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.
@@ -25,5 +25,7 @@ export interface IOpts {
25
25
  };
26
26
  pkg?: Record<string, any>;
27
27
  disableCopy?: boolean;
28
+ host?: string;
29
+ port?: number;
28
30
  }
29
31
  export declare function getConfig(opts: IOpts): Promise<Configuration>;
@@ -84,7 +84,9 @@ async function getConfig(opts) {
84
84
  targets: userConfig.targets
85
85
  }),
86
86
  useHash,
87
- staticPathPrefix: opts.staticPathPrefix !== void 0 ? opts.staticPathPrefix : "static/"
87
+ staticPathPrefix: opts.staticPathPrefix !== void 0 ? opts.staticPathPrefix : "static/",
88
+ port: opts.port,
89
+ host: opts.host
88
90
  };
89
91
  config.name(opts.name);
90
92
  config.mode(opts.env);
@@ -1,15 +1,14 @@
1
1
  import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
- import { Env, IConfig } from '../types';
2
+ import type { Env, IConfig } from '../types';
3
3
  interface IOpts {
4
4
  config: Config;
5
5
  userConfig: IConfig;
6
6
  cwd: string;
7
7
  env: Env;
8
+ host?: string;
9
+ port?: number;
8
10
  }
9
- export declare function resolveDefine(opts: {
10
- define: any;
11
- publicPath?: string;
12
- }): {
11
+ export declare function resolveDefine(opts: IOpts): {
13
12
  'process.env': Record<string, any>;
14
13
  };
15
14
  export declare function addDefinePlugin(opts: IOpts): Promise<void>;
@@ -26,21 +26,41 @@ module.exports = __toCommonJS(definePlugin_exports);
26
26
  var import_webpack = require("@umijs/bundler-webpack/compiled/webpack");
27
27
  var prefixRE = /^UMI_APP_/;
28
28
  var ENV_SHOULD_PASS = ["NODE_ENV", "HMR", "SOCKET_SERVER", "ERROR_OVERLAY"];
29
+ var SOCKET_IGNORE_HOSTS = ["0.0.0.0", "127.0.0.1", "localhost"];
30
+ var CUSTOM_ENV_GETTER = {
31
+ SOCKET_SERVER: (opts) => {
32
+ const { userConfig, host, port } = opts;
33
+ const socketServer = process.env.SOCKET_SERVER;
34
+ if (socketServer) {
35
+ return socketServer;
36
+ }
37
+ if (host && !SOCKET_IGNORE_HOSTS.includes(host)) {
38
+ const protocol = userConfig.https ? "https:" : "http:";
39
+ return `${protocol}//${host}:${port || 8e3}`;
40
+ }
41
+ return;
42
+ }
43
+ };
29
44
  function resolveDefine(opts) {
45
+ const { userConfig } = opts;
30
46
  const env = {};
31
- Object.keys(process.env).forEach((key) => {
32
- if (prefixRE.test(key) || ENV_SHOULD_PASS.includes(key)) {
33
- env[key] = process.env[key];
47
+ ENV_SHOULD_PASS.concat(
48
+ Object.keys(process.env).filter((k) => prefixRE.test(k))
49
+ ).forEach((key) => {
50
+ const envValue = CUSTOM_ENV_GETTER[key] ? CUSTOM_ENV_GETTER[key](opts) : process.env[key];
51
+ if (typeof envValue === "undefined") {
52
+ return;
34
53
  }
54
+ env[key] = envValue;
35
55
  });
36
- env.PUBLIC_PATH = opts.publicPath || "/";
56
+ env.PUBLIC_PATH = userConfig.publicPath || "/";
37
57
  for (const key in env) {
38
58
  env[key] = JSON.stringify(env[key]);
39
59
  }
40
60
  const define = {};
41
- if (opts.define) {
42
- for (const key in opts.define) {
43
- define[key] = JSON.stringify(opts.define[key]);
61
+ if (userConfig.define) {
62
+ for (const key in userConfig.define) {
63
+ define[key] = JSON.stringify(userConfig.define[key]);
44
64
  }
45
65
  }
46
66
  return {
@@ -49,13 +69,8 @@ function resolveDefine(opts) {
49
69
  };
50
70
  }
51
71
  async function addDefinePlugin(opts) {
52
- const { config, userConfig } = opts;
53
- config.plugin("define").use(import_webpack.DefinePlugin, [
54
- resolveDefine({
55
- define: userConfig.define || {},
56
- publicPath: userConfig.publicPath
57
- })
58
- ]);
72
+ const { config } = opts;
73
+ config.plugin("define").use(import_webpack.DefinePlugin, [resolveDefine(opts)]);
59
74
  }
60
75
  // Annotate the CommonJS export names for ESM import in node:
61
76
  0 && (module.exports = {
package/dist/dev.js CHANGED
@@ -150,7 +150,9 @@ async function setup(opts) {
150
150
  )
151
151
  } : void 0,
152
152
  pkg: opts.pkg,
153
- disableCopy: opts.disableCopy
153
+ disableCopy: opts.disableCopy,
154
+ port: opts.port,
155
+ host: opts.host
154
156
  });
155
157
  const depConfig = await configModule.getConfig({
156
158
  cwd: opts.cwd,
@@ -168,7 +170,9 @@ async function setup(opts) {
168
170
  buildDependencies: (_j = opts.cache) == null ? void 0 : _j.buildDependencies,
169
171
  cacheDirectory: (0, import_path.join)(cacheDirectoryPath, "mfsu-deps")
170
172
  },
171
- pkg: opts.pkg
173
+ pkg: opts.pkg,
174
+ port: opts.port,
175
+ host: opts.host
172
176
  });
173
177
  (_k = webpackConfig.resolve).alias || (_k.alias = {});
174
178
  ["@umijs/utils/compiled/strip-ansi", "react-error-overlay"].forEach((dep) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-webpack",
3
- "version": "4.1.9",
3
+ "version": "4.1.10",
4
4
  "description": "@umijs/bundler-webpack",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/bundler-webpack#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",
@@ -38,10 +38,10 @@
38
38
  "postcss-preset-env": "7.5.0",
39
39
  "react-error-overlay": "6.0.9",
40
40
  "react-refresh": "0.14.0",
41
- "@umijs/babel-preset-umi": "4.1.9",
42
- "@umijs/bundler-utils": "4.1.9",
43
- "@umijs/mfsu": "4.1.9",
44
- "@umijs/utils": "4.1.9"
41
+ "@umijs/babel-preset-umi": "4.1.10",
42
+ "@umijs/bundler-utils": "4.1.10",
43
+ "@umijs/mfsu": "4.1.10",
44
+ "@umijs/utils": "4.1.10"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@swc/core": "1.3.67",