@umijs/bundler-webpack 4.0.13 → 4.0.14

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.
@@ -36,7 +36,7 @@ async function addAssetRules(opts) {
36
36
  maxSize: inlineLimit
37
37
  }
38
38
  });
39
- const fallback = rule.oneOf("fallback").exclude.add(/^$/).add(/\.(js|mjs|jsx|ts|tsx)$/).add(/\.(css|less|sass|scss|stylus)$/).add(/\.html$/).add(/\.json$/);
39
+ const fallback = rule.oneOf("fallback").exclude.add(/^$/).add(/\.(js|mjs|cjs|jsx|ts|tsx)$/).add(/\.(css|less|sass|scss|stylus)$/).add(/\.html$/).add(/\.json$/);
40
40
  if (userConfig.mdx) {
41
41
  fallback.add(/\.mdx?$/);
42
42
  }
@@ -7,7 +7,7 @@ export interface IOpts {
7
7
  entry: Record<string, string>;
8
8
  extraBabelPresets?: any[];
9
9
  extraBabelPlugins?: any[];
10
- extraBabelIncludes?: string[];
10
+ extraBabelIncludes?: Array<string | RegExp>;
11
11
  extraEsbuildLoaderHandler?: any[];
12
12
  babelPreset?: any;
13
13
  chainWebpack?: Function;
@@ -107,6 +107,7 @@ async function getConfig(opts) {
107
107
  config.resolve.set("symlinks", true).modules.add("node_modules").end().alias.merge(userConfig.alias || {}).end().extensions.merge([
108
108
  ".wasm",
109
109
  ".mjs",
110
+ ".cjs",
110
111
  ".js",
111
112
  ".jsx",
112
113
  ".ts",
@@ -7,7 +7,7 @@ interface IOpts {
7
7
  env: Env;
8
8
  extraBabelPlugins: any[];
9
9
  extraBabelPresets: any[];
10
- extraBabelIncludes: string[];
10
+ extraBabelIncludes: Array<string | RegExp>;
11
11
  extraEsbuildLoaderHandler: any[];
12
12
  babelPreset: any;
13
13
  name?: string;
@@ -39,13 +39,16 @@ async function addJavaScriptRules(opts) {
39
39
  const useFastRefresh = isDev && userConfig.fastRefresh !== false && name !== import_constants.MFSU_NAME;
40
40
  const depPkgs = Object.assign({}, (0, import_depMatch.es5ImcompatibleVersionsToPkg)());
41
41
  const srcRules = [
42
- config.module.rule("src").test(/\.(js|mjs)$/).include.add([
42
+ config.module.rule("src").test(/\.(js|mjs|cjs)$/).include.add([
43
43
  cwd,
44
44
  ...process.env.APP_ROOT ? [process.cwd()] : []
45
45
  ]).end().exclude.add(/node_modules/).end(),
46
46
  config.module.rule("jsx-ts-tsx").test(/\.(jsx|ts|tsx)$/),
47
- config.module.rule("extra-src").test(/\.(js|mjs)$/).include.add([
47
+ config.module.rule("extra-src").test(/\.(js|mjs|cjs)$/).include.add([
48
48
  ...opts.extraBabelIncludes.map((p) => {
49
+ if (import_utils.lodash.isRegExp(p)) {
50
+ return p;
51
+ }
49
52
  if ((0, import_path.isAbsolute)(p)) {
50
53
  return p;
51
54
  }
@@ -77,7 +80,7 @@ async function addJavaScriptRules(opts) {
77
80
  srcRules.push(config.module.rule("markdown").test(/\.mdx?$/));
78
81
  }
79
82
  const depRules = [
80
- config.module.rule("dep").test(/\.(js|mjs)$/).include.add(/node_modules/).end().exclude.add((path) => {
83
+ config.module.rule("dep").test(/\.(js|mjs|cjs)$/).include.add(/node_modules/).end().exclude.add((path) => {
81
84
  try {
82
85
  return (0, import_depMatch.isMatch)({ path, pkgs: depPkgs });
83
86
  } catch (e) {
package/dist/dev.d.ts CHANGED
@@ -8,6 +8,7 @@ declare type IOpts = {
8
8
  onMFSUProgress?: Function;
9
9
  port?: number;
10
10
  host?: string;
11
+ ip?: string;
11
12
  babelPreset?: any;
12
13
  chainWebpack?: Function;
13
14
  modifyWebpackConfig?: Function;
@@ -21,6 +22,7 @@ declare type IOpts = {
21
22
  entry: Record<string, string>;
22
23
  mfsuStrategy?: 'eager' | 'normal';
23
24
  mfsuInclude?: string[];
25
+ mfsuServerBase?: string;
24
26
  srcCodeCache?: any;
25
27
  } & Pick<IConfigOpts, 'cache' | 'pkg'>;
26
28
  export declare function stripUndefined(obj: any): any;
package/dist/dev.js CHANGED
@@ -65,10 +65,6 @@ async function dev(opts) {
65
65
  const cacheDirectoryPath = (0, import_path.resolve)(opts.rootDir || opts.cwd, opts.config.cacheDirectoryPath || "node_modules/.cache");
66
66
  const enableMFSU = opts.config.mfsu !== false;
67
67
  let mfsu = null;
68
- let devHost = "localhost";
69
- if (opts.host && opts.host !== "0.0.0.0") {
70
- devHost = opts.host;
71
- }
72
68
  if (enableMFSU) {
73
69
  if (opts.config.srcTranspiler === import_types.Transpiler.swc) {
74
70
  import_utils.logger.warn(`Swc currently not supported for use with mfsu, recommended you use srcTranspiler: 'esbuild' in dev.`);
@@ -101,7 +97,7 @@ async function dev(opts) {
101
97
  publicPath: opts.config.publicPath
102
98
  });
103
99
  },
104
- serverBase: `${opts.config.https ? "https" : "http"}://${devHost}:${opts.port || 8e3}`
100
+ serverBase: opts.mfsuServerBase
105
101
  });
106
102
  }
107
103
  const webpackConfig = await (0, import_config.getConfig)({
@@ -174,7 +170,8 @@ async function dev(opts) {
174
170
  ...opts.beforeMiddlewares || []
175
171
  ],
176
172
  port: opts.port,
177
- host: devHost,
173
+ host: opts.host,
174
+ ip: opts.ip,
178
175
  afterMiddlewares: [...opts.afterMiddlewares || []],
179
176
  onDevCompileDone: opts.onDevCompileDone,
180
177
  onProgress: opts.onProgress
package/dist/schema.js CHANGED
@@ -73,7 +73,7 @@ function getSchemas() {
73
73
  devtool: (Joi) => Joi.alternatives().try(Joi.string().regex(DEVTOOL_REGEX), Joi.boolean()),
74
74
  esm: (Joi) => Joi.object(),
75
75
  externals: (Joi) => Joi.alternatives().try(Joi.object(), Joi.string(), Joi.func()),
76
- extraBabelIncludes: (Joi) => Joi.array().items(Joi.string()),
76
+ extraBabelIncludes: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.object().instance(RegExp))),
77
77
  extraBabelPlugins: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
78
78
  extraBabelPresets: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
79
79
  extraPostCSSPlugins: (Joi) => Joi.array(),
@@ -6,6 +6,7 @@ interface IOpts {
6
6
  cwd: string;
7
7
  port?: number;
8
8
  host?: string;
9
+ ip?: string;
9
10
  webpackConfig: Configuration;
10
11
  userConfig: IConfig;
11
12
  beforeMiddlewares?: any[];
@@ -58,6 +58,7 @@ async function createServer(opts) {
58
58
  const { webpackConfig, userConfig } = opts;
59
59
  const { proxy } = userConfig;
60
60
  const app = (0, import_express.default)();
61
+ let ws;
61
62
  app.use((0, import_cors.default)({
62
63
  origin: true,
63
64
  methods: ["GET", "HEAD", "PUT", "POST", "PATCH", "DELETE", "OPTIONS"],
@@ -148,7 +149,8 @@ async function createServer(opts) {
148
149
  });
149
150
  }
150
151
  function sendMessage(type, data, sender) {
151
- (sender || ws).send(JSON.stringify({ type, data }));
152
+ var _a;
153
+ (_a = sender || ws) == null ? void 0 : _a.send(JSON.stringify({ type, data }));
152
154
  }
153
155
  if (proxy) {
154
156
  const proxyArr = Array.isArray(proxy) ? proxy : proxy.target ? [proxy] : Object.keys(proxy).map((key) => {
@@ -209,11 +211,26 @@ async function createServer(opts) {
209
211
  next();
210
212
  }
211
213
  });
212
- const server = userConfig.https ? await (0, import_bundler_utils.createHttpsServer)(app, userConfig.https) : import_http.default.createServer(app);
214
+ let server;
215
+ if (userConfig.https) {
216
+ const httpsOpts = userConfig.https;
217
+ if (!httpsOpts.hosts) {
218
+ httpsOpts.hosts = import_utils.lodash.uniq([
219
+ ...httpsOpts.hosts || [],
220
+ "127.0.0.1",
221
+ "localhost",
222
+ opts.ip,
223
+ opts.host !== "0.0.0.0" && opts.host
224
+ ].filter(Boolean));
225
+ }
226
+ server = await (0, import_bundler_utils.createHttpsServer)(app, httpsOpts);
227
+ } else {
228
+ server = import_http.default.createServer(app);
229
+ }
213
230
  if (!server) {
214
231
  return null;
215
232
  }
216
- const ws = (0, import_ws.createWebSocketServer)(server);
233
+ ws = (0, import_ws.createWebSocketServer)(server);
217
234
  ws.wss.on("connection", (socket) => {
218
235
  if (stats) {
219
236
  sendStats(getStats(stats), false, socket);
package/dist/types.d.ts CHANGED
@@ -71,7 +71,7 @@ export interface IConfig {
71
71
  };
72
72
  extraBabelPlugins?: IBabelPlugin[];
73
73
  extraBabelPresets?: IBabelPlugin[];
74
- extraBabelIncludes?: string[];
74
+ extraBabelIncludes?: Array<string | RegExp>;
75
75
  extraPostCSSPlugins?: any[];
76
76
  hash?: boolean;
77
77
  ignoreMomentLocale?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-webpack",
3
- "version": "4.0.13",
3
+ "version": "4.0.14",
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",
@@ -34,11 +34,11 @@
34
34
  "@svgr/plugin-jsx": "^6.2.1",
35
35
  "@svgr/plugin-svgo": "^6.2.0",
36
36
  "@types/hapi__joi": "17.1.8",
37
- "@umijs/babel-preset-umi": "4.0.13",
38
- "@umijs/bundler-utils": "4.0.13",
37
+ "@umijs/babel-preset-umi": "4.0.14",
38
+ "@umijs/bundler-utils": "4.0.14",
39
39
  "@umijs/case-sensitive-paths-webpack-plugin": "^1.0.1",
40
- "@umijs/mfsu": "4.0.13",
41
- "@umijs/utils": "4.0.13",
40
+ "@umijs/mfsu": "4.0.14",
41
+ "@umijs/utils": "4.0.14",
42
42
  "cors": "^2.8.5",
43
43
  "css-loader": "6.7.1",
44
44
  "es5-imcompatible-versions": "^0.1.73",