@umijs/bundler-webpack 4.0.0-canary.20230210.1 → 4.0.0-canary.20230216.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.
package/dist/build.d.ts CHANGED
@@ -15,6 +15,7 @@ declare type IOpts = {
15
15
  extraBabelPlugins?: any[];
16
16
  extraBabelPresets?: any[];
17
17
  clean?: boolean;
18
+ watch?: boolean;
18
19
  } & Pick<IConfigOpts, 'cache' | 'pkg'>;
19
20
  export declare function build(opts: IOpts): Promise<webpack.Stats>;
20
21
  export {};
package/dist/build.js CHANGED
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -69,13 +73,16 @@ async function build(opts) {
69
73
  import_utils.rimraf.sync(webpackConfig.output.path);
70
74
  }
71
75
  const compiler = (0, import_webpack.default)(webpackConfig);
72
- compiler.run((err, stats) => {
76
+ let closeWatching;
77
+ const handler = (err, stats) => {
73
78
  var _a;
74
79
  (_a = opts.onBuildComplete) == null ? void 0 : _a.call(opts, {
75
80
  err,
76
81
  stats,
77
82
  isFirstCompile,
78
- time: stats ? stats.endTime - stats.startTime : null
83
+ time: stats ? stats.endTime - stats.startTime : null,
84
+ // pass close function to close watching
85
+ ...opts.watch ? { close: closeWatching } : {}
79
86
  });
80
87
  isFirstCompile = false;
81
88
  if (err || (stats == null ? void 0 : stats.hasErrors())) {
@@ -89,9 +96,19 @@ async function build(opts) {
89
96
  } else {
90
97
  resolve2(stats);
91
98
  }
92
- compiler.close(() => {
93
- });
94
- });
99
+ if (!opts.watch)
100
+ compiler.close(() => {
101
+ });
102
+ };
103
+ if (opts.watch) {
104
+ const watching = compiler.watch(
105
+ webpackConfig.watchOptions || {},
106
+ handler
107
+ );
108
+ closeWatching = watching.close.bind(watching);
109
+ } else {
110
+ compiler.run(handler);
111
+ }
95
112
  });
96
113
  }
97
114
  // Annotate the CommonJS export names for ESM import in node:
@@ -107,6 +107,7 @@ async function addJavaScriptRules(opts) {
107
107
  rule.use("babel-loader").loader(require.resolve("../../compiled/babel-loader")).options({
108
108
  sourceType: "unambiguous",
109
109
  babelrc: false,
110
+ configFile: false,
110
111
  cacheDirectory: false,
111
112
  browserslistConfigFile: false,
112
113
  targets: userConfig.targets,
package/dist/dev.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  /// <reference types="node" />
2
+ import { MFSU } from '@umijs/mfsu';
2
3
  import type { Worker } from 'worker_threads';
4
+ import webpack from '../compiled/webpack';
3
5
  import { IOpts as IConfigOpts } from './config/config';
4
6
  import { IConfig } from './types';
5
7
  declare type IOpts = {
@@ -30,4 +32,8 @@ declare type IOpts = {
30
32
  } & Pick<IConfigOpts, 'cache' | 'pkg'>;
31
33
  export declare function ensureSerializableValue(obj: any): any;
32
34
  export declare function dev(opts: IOpts): Promise<void>;
35
+ export declare function setup(opts: IOpts): Promise<{
36
+ mfsu: MFSU | null;
37
+ webpackConfig: webpack.Configuration;
38
+ }>;
33
39
  export {};
package/dist/dev.js CHANGED
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -26,7 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
26
30
  var dev_exports = {};
27
31
  __export(dev_exports, {
28
32
  dev: () => dev,
29
- ensureSerializableValue: () => ensureSerializableValue
33
+ ensureSerializableValue: () => ensureSerializableValue,
34
+ setup: () => setup
30
35
  });
31
36
  module.exports = __toCommonJS(dev_exports);
32
37
  var import_mfsu = require("@umijs/mfsu");
@@ -53,6 +58,25 @@ function ensureSerializableValue(obj) {
53
58
  );
54
59
  }
55
60
  async function dev(opts) {
61
+ const { mfsu, webpackConfig } = await setup(opts);
62
+ await (0, import_server.createServer)({
63
+ webpackConfig,
64
+ userConfig: opts.config,
65
+ cwd: opts.cwd,
66
+ beforeMiddlewares: [
67
+ ...(mfsu == null ? void 0 : mfsu.getMiddlewares()) || [],
68
+ ...opts.beforeMiddlewares || []
69
+ ],
70
+ port: opts.port,
71
+ host: opts.host,
72
+ ip: opts.ip,
73
+ afterMiddlewares: [...opts.afterMiddlewares || []],
74
+ onDevCompileDone: opts.onDevCompileDone,
75
+ onProgress: opts.onProgress,
76
+ onBeforeMiddleware: opts.onBeforeMiddleware
77
+ });
78
+ }
79
+ async function setup(opts) {
56
80
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
57
81
  const cacheDirectoryPath = (0, import_path.resolve)(
58
82
  opts.rootDir || opts.cwd,
@@ -164,25 +188,14 @@ async function dev(opts) {
164
188
  import_utils.rimraf.sync(webpackConfig.cache.cacheDirectory);
165
189
  }
166
190
  }
167
- await (0, import_server.createServer)({
168
- webpackConfig,
169
- userConfig: opts.config,
170
- cwd: opts.cwd,
171
- beforeMiddlewares: [
172
- ...(mfsu == null ? void 0 : mfsu.getMiddlewares()) || [],
173
- ...opts.beforeMiddlewares || []
174
- ],
175
- port: opts.port,
176
- host: opts.host,
177
- ip: opts.ip,
178
- afterMiddlewares: [...opts.afterMiddlewares || []],
179
- onDevCompileDone: opts.onDevCompileDone,
180
- onProgress: opts.onProgress,
181
- onBeforeMiddleware: opts.onBeforeMiddleware
182
- });
191
+ return {
192
+ mfsu,
193
+ webpackConfig
194
+ };
183
195
  }
184
196
  // Annotate the CommonJS export names for ESM import in node:
185
197
  0 && (module.exports = {
186
198
  dev,
187
- ensureSerializableValue
199
+ ensureSerializableValue,
200
+ setup
188
201
  });
@@ -8,6 +8,6 @@ import { Server as HttpsServer } from 'https';
8
8
  import WebSocket from '../../compiled/ws';
9
9
  export declare function createWebSocketServer(server: HttpServer | HttpsServer | Http2Server | Server): {
10
10
  send(message: string): void;
11
- wss: WebSocket.Server<WebSocket.WebSocket>;
11
+ wss: WebSocket.Server;
12
12
  close(): void;
13
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-webpack",
3
- "version": "4.0.0-canary.20230210.1",
3
+ "version": "4.0.0-canary.20230216.1",
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",
@@ -33,11 +33,11 @@
33
33
  "@svgr/plugin-jsx": "^6.2.1",
34
34
  "@svgr/plugin-svgo": "^6.2.0",
35
35
  "@types/hapi__joi": "17.1.9",
36
- "@umijs/babel-preset-umi": "4.0.0-canary.20230210.1",
37
- "@umijs/bundler-utils": "4.0.0-canary.20230210.1",
36
+ "@umijs/babel-preset-umi": "4.0.0-canary.20230216.1",
37
+ "@umijs/bundler-utils": "4.0.0-canary.20230216.1",
38
38
  "@umijs/case-sensitive-paths-webpack-plugin": "^1.0.1",
39
- "@umijs/mfsu": "4.0.0-canary.20230210.1",
40
- "@umijs/utils": "4.0.0-canary.20230210.1",
39
+ "@umijs/mfsu": "4.0.0-canary.20230216.1",
40
+ "@umijs/utils": "4.0.0-canary.20230216.1",
41
41
  "cors": "^2.8.5",
42
42
  "css-loader": "6.7.1",
43
43
  "es5-imcompatible-versions": "^0.1.73",