@umijs/mfsu 4.0.0-beta.3 → 4.0.0-beta.7

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/dep/dep.d.ts CHANGED
@@ -14,7 +14,7 @@ export declare class Dep {
14
14
  mfsu: MFSU;
15
15
  });
16
16
  buildExposeContent(): Promise<string>;
17
- getRealFile(): any;
17
+ getRealFile(): Promise<string | null>;
18
18
  static buildDeps(opts: {
19
19
  deps: Record<string, {
20
20
  file: string;
package/dist/dep/dep.js CHANGED
@@ -1,23 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -33,13 +14,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
14
  Object.defineProperty(exports, "__esModule", { value: true });
34
15
  exports.Dep = void 0;
35
16
  const assert_1 = __importDefault(require("assert"));
17
+ const enhanced_resolve_1 = __importDefault(require("enhanced-resolve"));
36
18
  const fs_1 = require("fs");
37
- const path_1 = require("path");
38
- const process = __importStar(require("process"));
39
19
  const constants_1 = require("../constants");
40
20
  const trimFileContent_1 = require("../utils/trimFileContent");
41
21
  const getExposeFromContent_1 = require("./getExposeFromContent");
42
- const getFilePath_1 = require("./getFilePath");
22
+ const resolver = enhanced_resolve_1.default.create({
23
+ mainFields: ['module', 'browser', 'main'],
24
+ extensions: ['.js', '.json', '.mjs'],
25
+ // TODO: support exports
26
+ // tried to add exports, but it don't work with swr
27
+ exportsFields: [],
28
+ });
29
+ function resolve(context, path) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ return new Promise((resolve, reject) => {
32
+ resolver(context, path, (err, result) => err ? reject(err) : resolve(result));
33
+ });
34
+ });
35
+ }
43
36
  class Dep {
44
37
  constructor(opts) {
45
38
  this.file = opts.file;
@@ -68,7 +61,7 @@ export * from '${this.file}';
68
61
  `);
69
62
  }
70
63
  // none node natives
71
- const realFile = this.getRealFile();
64
+ const realFile = yield this.getRealFile();
72
65
  (0, assert_1.default)(realFile, `filePath not found of ${this.file}`);
73
66
  const content = (0, fs_1.readFileSync)(realFile, 'utf-8');
74
67
  return yield (0, getExposeFromContent_1.getExposeFromContent)({
@@ -79,23 +72,16 @@ export * from '${this.file}';
79
72
  });
80
73
  }
81
74
  getRealFile() {
82
- // Support config dep module resolver
83
- for (const resolver of this.mfsu.opts.resolvers || []) {
84
- const ret = resolver(this.file);
85
- if (ret)
86
- return ret;
87
- }
88
- const absFiles = (0, path_1.isAbsolute)(this.file)
89
- ? [this.file]
90
- : [this.cwd, this.cwd !== process.cwd() && process.cwd()]
91
- .filter(Boolean)
92
- .map((base) => (0, path_1.join)(base, 'node_modules', this.file));
93
- for (const path of absFiles) {
94
- const realFile = (0, getFilePath_1.getFilePath)({ path });
95
- if (realFile)
96
- return realFile;
97
- }
98
- return null;
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ try {
77
+ // don't need to handle alias here
78
+ // it's already handled by babel plugin
79
+ return yield resolve(this.cwd, this.file);
80
+ }
81
+ catch (e) {
82
+ return null;
83
+ }
84
+ });
99
85
  }
100
86
  static buildDeps(opts) {
101
87
  return Object.keys(opts.deps).map((file) => {
@@ -8,9 +8,17 @@ export declare class DepBuilder {
8
8
  completeFns: Function[];
9
9
  isBuilding: boolean;
10
10
  constructor(opts: IOpts);
11
- build(opts: {
11
+ buildWithWebpack(opts: {
12
+ onBuildComplete: Function;
12
13
  deps: Dep[];
13
14
  }): Promise<unknown>;
15
+ buildWithESBuild(opts: {
16
+ onBuildComplete: Function;
17
+ deps: Dep[];
18
+ }): Promise<void>;
19
+ build(opts: {
20
+ deps: Dep[];
21
+ }): Promise<void>;
14
22
  onBuildComplete(fn: Function): void;
15
23
  writeMFFiles(opts: {
16
24
  deps: Dep[];
@@ -10,28 +10,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.DepBuilder = void 0;
13
+ const bundler_esbuild_1 = require("@umijs/bundler-esbuild");
13
14
  const utils_1 = require("@umijs/utils");
14
15
  const fs_1 = require("fs");
15
16
  const path_1 = require("path");
16
17
  const constants_1 = require("../constants");
17
18
  const depChunkIdPrefixPlugin_1 = require("../webpackPlugins/depChunkIdPrefixPlugin");
19
+ const stripSourceMapUrlPlugin_1 = require("../webpackPlugins/stripSourceMapUrlPlugin");
20
+ const getESBuildEntry_1 = require("./getESBuildEntry");
18
21
  class DepBuilder {
19
22
  constructor(opts) {
20
23
  this.completeFns = [];
21
24
  this.isBuilding = false;
22
25
  this.opts = opts;
23
26
  }
24
- build(opts) {
27
+ buildWithWebpack(opts) {
25
28
  return __awaiter(this, void 0, void 0, function* () {
26
- this.isBuilding = true;
27
- yield this.writeMFFiles({ deps: opts.deps });
28
29
  const config = this.getWebpackConfig({ deps: opts.deps });
29
30
  return new Promise((resolve, reject) => {
30
31
  const compiler = this.opts.mfsu.opts.implementor(config);
31
32
  compiler.run((err, stats) => {
32
- this.isBuilding = false;
33
- this.completeFns.forEach((fn) => fn());
34
- this.completeFns = [];
33
+ opts.onBuildComplete();
35
34
  if (err || (stats === null || stats === void 0 ? void 0 : stats.hasErrors())) {
36
35
  if (err) {
37
36
  reject(err);
@@ -50,6 +49,47 @@ class DepBuilder {
50
49
  });
51
50
  });
52
51
  }
52
+ // TODO: support watch and rebuild
53
+ buildWithESBuild(opts) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ const entryContent = (0, getESBuildEntry_1.getESBuildEntry)({ deps: opts.deps });
56
+ const ENTRY_FILE = 'esbuild-entry.js';
57
+ const tmpDir = this.opts.mfsu.opts.tmpBase;
58
+ const entryPath = (0, path_1.join)(tmpDir, ENTRY_FILE);
59
+ (0, fs_1.writeFileSync)(entryPath, entryContent, 'utf-8');
60
+ const date = new Date().getTime();
61
+ yield (0, bundler_esbuild_1.build)({
62
+ cwd: this.opts.mfsu.opts.cwd,
63
+ entry: {
64
+ [`${constants_1.MF_VA_PREFIX}remoteEntry`]: entryPath,
65
+ },
66
+ config: {
67
+ outputPath: tmpDir,
68
+ alias: this.opts.mfsu.alias,
69
+ externals: this.opts.mfsu.externals,
70
+ },
71
+ });
72
+ utils_1.logger.event(`[mfsu] compiled with esbuild successfully in ${+new Date() - date} ms`);
73
+ opts.onBuildComplete();
74
+ });
75
+ }
76
+ build(opts) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ this.isBuilding = true;
79
+ yield this.writeMFFiles({ deps: opts.deps });
80
+ const newOpts = Object.assign(Object.assign({}, opts), { onBuildComplete: () => {
81
+ this.isBuilding = false;
82
+ this.completeFns.forEach((fn) => fn());
83
+ this.completeFns = [];
84
+ } });
85
+ if (this.opts.mfsu.opts.buildDepWithESBuild) {
86
+ yield this.buildWithESBuild(newOpts);
87
+ }
88
+ else {
89
+ yield this.buildWithWebpack(newOpts);
90
+ }
91
+ });
92
+ }
53
93
  onBuildComplete(fn) {
54
94
  if (this.isBuilding) {
55
95
  this.completeFns.push(fn);
@@ -103,6 +143,9 @@ class DepBuilder {
103
143
  };
104
144
  depConfig.plugins = depConfig.plugins || [];
105
145
  depConfig.plugins.push(new depChunkIdPrefixPlugin_1.DepChunkIdPrefixPlugin());
146
+ depConfig.plugins.push(new stripSourceMapUrlPlugin_1.StripSourceMapUrlPlugin({
147
+ webpack: this.opts.mfsu.opts.implementor,
148
+ }));
106
149
  const exposes = opts.deps.reduce((memo, dep) => {
107
150
  memo[`./${dep.shortFile}`] = (0, path_1.join)(this.opts.mfsu.opts.tmpBase, dep.filePath);
108
151
  return memo;
@@ -0,0 +1,4 @@
1
+ import { Dep } from '../dep/dep';
2
+ export declare function getESBuildEntry(opts: {
3
+ deps: Dep[];
4
+ }): string;
@@ -0,0 +1,315 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getESBuildEntry = void 0;
4
+ const constants_1 = require("../constants");
5
+ function getESBuildEntry(opts) {
6
+ return `
7
+ (function() {
8
+ /******/ "use strict";
9
+ /******/ var __webpack_modules__ = ({});
10
+ /************************************************************************/
11
+ /******/ // The module cache
12
+ /******/ var __webpack_module_cache__ = {};
13
+ /******/
14
+ /******/ // The require function
15
+ /******/ function __webpack_require__(moduleId) {
16
+ /******/ // Check if module is in cache
17
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
18
+ /******/ if (cachedModule !== undefined) {
19
+ /******/ return cachedModule.exports;
20
+ /******/ }
21
+ /******/ // Create a new module (and put it into the cache)
22
+ /******/ var module = __webpack_module_cache__[moduleId] = {
23
+ /******/ id: moduleId,
24
+ /******/ loaded: false,
25
+ /******/ exports: {}
26
+ /******/ };
27
+ /******/
28
+ /******/ // Execute the module function
29
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
30
+ /******/
31
+ /******/ // Flag the module as loaded
32
+ /******/ module.loaded = true;
33
+ /******/
34
+ /******/ // Return the exports of the module
35
+ /******/ return module.exports;
36
+ /******/ }
37
+ /******/
38
+ /******/ // expose the modules object (__webpack_modules__)
39
+ /******/ __webpack_require__.m = __webpack_modules__;
40
+ /******/
41
+ /************************************************************************/
42
+ /******/ /* webpack/runtime/compat get default export */
43
+ /******/ !function() {
44
+ /******/ // getDefaultExport function for compatibility with non-harmony modules
45
+ /******/ __webpack_require__.n = function(module) {
46
+ /******/ var getter = module && module.__esModule ?
47
+ /******/ function() { return module['default']; } :
48
+ /******/ function() { return module; };
49
+ /******/ __webpack_require__.d(getter, { a: getter });
50
+ /******/ return getter;
51
+ /******/ };
52
+ /******/ }();
53
+ /******/
54
+ /******/ /* webpack/runtime/define property getters */
55
+ /******/ !function() {
56
+ /******/ // define getter functions for harmony exports
57
+ /******/ __webpack_require__.d = function(exports, definition) {
58
+ /******/ for(var key in definition) {
59
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
60
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
61
+ /******/ }
62
+ /******/ }
63
+ /******/ };
64
+ /******/ }();
65
+ /******/
66
+ /******/ /* webpack/runtime/ensure chunk */
67
+ /******/ !function() {
68
+ /******/ __webpack_require__.f = {};
69
+ /******/ // This file contains only the entry chunk.
70
+ /******/ // The chunk loading function for additional chunks
71
+ /******/ __webpack_require__.e = function(chunkId) {
72
+ /******/ return Promise.all(Object.keys(__webpack_require__.f).reduce(function(promises, key) {
73
+ /******/ __webpack_require__.f[key](chunkId, promises);
74
+ /******/ return promises;
75
+ /******/ }, []));
76
+ /******/ };
77
+ /******/ }();
78
+ /******/
79
+ /******/ /* webpack/runtime/get javascript chunk filename */
80
+ /******/ !function() {
81
+ /******/ // This function allow to reference async chunks
82
+ /******/ __webpack_require__.u = function(chunkId) {
83
+ /******/ // return url for filenames based on template
84
+ /******/ return "" + "mf-dep____vendor" + "." + "8b5e340b" + ".js";
85
+ /******/ };
86
+ /******/ }();
87
+ /******/
88
+ /******/ /* webpack/runtime/get mini-css chunk filename */
89
+ /******/ !function() {
90
+ /******/ // This function allow to reference all chunks
91
+ /******/ __webpack_require__.miniCssF = function(chunkId) {
92
+ /******/ // return url for filenames based on template
93
+ /******/ return undefined;
94
+ /******/ };
95
+ /******/ }();
96
+ /******/
97
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
98
+ /******/ !function() {
99
+ /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
100
+ /******/ }();
101
+ /******/
102
+ /******/ /* webpack/runtime/load script */
103
+ /******/ !function() {
104
+ /******/ var inProgress = {};
105
+ /******/ // data-webpack is not used as build has no uniqueName
106
+ /******/ // loadScript function to load a script via script tag
107
+ /******/ __webpack_require__.l = function(url, done, key, chunkId) {
108
+ /******/ if(inProgress[url]) { inProgress[url].push(done); return; }
109
+ /******/ var script, needAttach;
110
+ /******/ if(key !== undefined) {
111
+ /******/ var scripts = document.getElementsByTagName("script");
112
+ /******/ for(var i = 0; i < scripts.length; i++) {
113
+ /******/ var s = scripts[i];
114
+ /******/ if(s.getAttribute("src") == url) { script = s; break; }
115
+ /******/ }
116
+ /******/ }
117
+ /******/ if(!script) {
118
+ /******/ needAttach = true;
119
+ /******/ script = document.createElement('script');
120
+ /******/
121
+ /******/ script.charset = 'utf-8';
122
+ /******/ script.timeout = 120;
123
+ /******/ if (__webpack_require__.nc) {
124
+ /******/ script.setAttribute("nonce", __webpack_require__.nc);
125
+ /******/ }
126
+ /******/
127
+ /******/ script.src = url;
128
+ /******/ }
129
+ /******/ inProgress[url] = [done];
130
+ /******/ var onScriptComplete = function(prev, event) {
131
+ /******/ // avoid mem leaks in IE.
132
+ /******/ script.onerror = script.onload = null;
133
+ /******/ clearTimeout(timeout);
134
+ /******/ var doneFns = inProgress[url];
135
+ /******/ delete inProgress[url];
136
+ /******/ script.parentNode && script.parentNode.removeChild(script);
137
+ /******/ doneFns && doneFns.forEach(function(fn) { return fn(event); });
138
+ /******/ if(prev) return prev(event);
139
+ /******/ }
140
+ /******/ ;
141
+ /******/ var timeout = setTimeout(onScriptComplete.bind(null, undefined, { type: 'timeout', target: script }), 120000);
142
+ /******/ script.onerror = onScriptComplete.bind(null, script.onerror);
143
+ /******/ script.onload = onScriptComplete.bind(null, script.onload);
144
+ /******/ needAttach && document.head.appendChild(script);
145
+ /******/ };
146
+ /******/ }();
147
+ /******/
148
+ /******/ /* webpack/runtime/make namespace object */
149
+ /******/ !function() {
150
+ /******/ // define __esModule on exports
151
+ /******/ __webpack_require__.r = function(exports) {
152
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
153
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
154
+ /******/ }
155
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
156
+ /******/ };
157
+ /******/ }();
158
+ /******/
159
+ /******/ /* webpack/runtime/node module decorator */
160
+ /******/ !function() {
161
+ /******/ __webpack_require__.nmd = function(module) {
162
+ /******/ module.paths = [];
163
+ /******/ if (!module.children) module.children = [];
164
+ /******/ return module;
165
+ /******/ };
166
+ /******/ }();
167
+ /******/
168
+ /******/ /* webpack/runtime/publicPath */
169
+ /******/ !function() {
170
+ /******/ __webpack_require__.p = "/";
171
+ /******/ }();
172
+ /******/
173
+ /******/ /* webpack/runtime/jsonp chunk loading */
174
+ /******/ !function() {
175
+ /******/ // no baseURI
176
+ /******/
177
+ /******/ // object to store loaded and loading chunks
178
+ /******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
179
+ /******/ // [resolve, reject, Promise] = chunk loading, 0 = chunk loaded
180
+ /******/ var installedChunks = {
181
+ /******/ "mf-dep_mf": 0
182
+ /******/ };
183
+ /******/
184
+ /******/ __webpack_require__.f.j = function(chunkId, promises) {
185
+ /******/ // JSONP chunk loading for javascript
186
+ /******/ var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;
187
+ /******/ if(installedChunkData !== 0) { // 0 means "already installed".
188
+ /******/
189
+ /******/ // a Promise means "currently loading".
190
+ /******/ if(installedChunkData) {
191
+ /******/ promises.push(installedChunkData[2]);
192
+ /******/ } else {
193
+ /******/ if(true) { // all chunks have JS
194
+ /******/ // setup Promise in chunk cache
195
+ /******/ var promise = new Promise(function(resolve, reject) { installedChunkData = installedChunks[chunkId] = [resolve, reject]; });
196
+ /******/ promises.push(installedChunkData[2] = promise);
197
+ /******/
198
+ /******/ // start chunk loading
199
+ /******/ var url = __webpack_require__.p + __webpack_require__.u(chunkId);
200
+ /******/ // create error before stack unwound to get useful stacktrace later
201
+ /******/ var error = new Error();
202
+ /******/ var loadingEnded = function(event) {
203
+ /******/ if(__webpack_require__.o(installedChunks, chunkId)) {
204
+ /******/ installedChunkData = installedChunks[chunkId];
205
+ /******/ if(installedChunkData !== 0) installedChunks[chunkId] = undefined;
206
+ /******/ if(installedChunkData) {
207
+ /******/ var errorType = event && (event.type === 'load' ? 'missing' : event.type);
208
+ /******/ var realSrc = event && event.target && event.target.src;
209
+ /******/ error.message = 'Loading chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')';
210
+ /******/ error.name = 'ChunkLoadError';
211
+ /******/ error.type = errorType;
212
+ /******/ error.request = realSrc;
213
+ /******/ installedChunkData[1](error);
214
+ /******/ }
215
+ /******/ }
216
+ /******/ };
217
+ /******/ __webpack_require__.l(url, loadingEnded, "chunk-" + chunkId, chunkId);
218
+ /******/ } else installedChunks[chunkId] = 0;
219
+ /******/ }
220
+ /******/ }
221
+ /******/ };
222
+ /******/
223
+ /******/ // no prefetching
224
+ /******/
225
+ /******/ // no preloaded
226
+ /******/
227
+ /******/ // no HMR
228
+ /******/
229
+ /******/ // no HMR manifest
230
+ /******/
231
+ /******/ // no on chunks loaded
232
+ /******/
233
+ /******/ // install a JSONP callback for chunk loading
234
+ /******/ var webpackJsonpCallback = function(parentChunkLoadingFunction, data) {
235
+ /******/ var chunkIds = data[0];
236
+ /******/ var moreModules = data[1];
237
+ /******/ var runtime = data[2];
238
+ /******/ // add "moreModules" to the modules object,
239
+ /******/ // then flag all "chunkIds" as loaded and fire callback
240
+ /******/ var moduleId, chunkId, i = 0;
241
+ /******/ if(chunkIds.some(function(id) { return installedChunks[id] !== 0; })) {
242
+ /******/ for(moduleId in moreModules) {
243
+ /******/ if(__webpack_require__.o(moreModules, moduleId)) {
244
+ /******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
245
+ /******/ }
246
+ /******/ }
247
+ /******/ if(runtime) var result = runtime(__webpack_require__);
248
+ /******/ }
249
+ /******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
250
+ /******/ for(;i < chunkIds.length; i++) {
251
+ /******/ chunkId = chunkIds[i];
252
+ /******/ if(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) {
253
+ /******/ installedChunks[chunkId][0]();
254
+ /******/ }
255
+ /******/ installedChunks[chunkIds[i]] = 0;
256
+ /******/ }
257
+ /******/
258
+ /******/ }
259
+ /******/
260
+ /******/ var chunkLoadingGlobal = self["webpackChunk"] = self["webpackChunk"] || [];
261
+ /******/ chunkLoadingGlobal.forEach(webpackJsonpCallback.bind(null, 0));
262
+ /******/ chunkLoadingGlobal.push = webpackJsonpCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal));
263
+ /******/ }();
264
+ /******/
265
+ /************************************************************************/
266
+ var __webpack_exports__ = {};
267
+ (function() {
268
+ var exports = __webpack_exports__;
269
+ var moduleMap = {
270
+ ${opts.deps.map(getDepModuleStr).join(',\n')}
271
+ };
272
+ var get = function(module, getScope) {
273
+ __webpack_require__.R = getScope;
274
+ getScope = (
275
+ __webpack_require__.o(moduleMap, module)
276
+ ? moduleMap[module]()
277
+ : Promise.resolve().then(function() {
278
+ throw new Error('Module "' + module + '" does not exist in container.');
279
+ })
280
+ );
281
+ __webpack_require__.R = undefined;
282
+ return getScope;
283
+ };
284
+ var init = function(shareScope, initScope) {
285
+ if (!__webpack_require__.S) return;
286
+ var oldScope = __webpack_require__.S["default"];
287
+ var name = "default"
288
+ if(oldScope && oldScope !== shareScope) throw new Error("Container initialization failed as it has already been initialized with a different share scope");
289
+ __webpack_require__.S[name] = shareScope;
290
+ return __webpack_require__.I(name, initScope);
291
+ };
292
+ __webpack_require__.d(exports, {
293
+ get: function() { return get; },
294
+ init: function() { return init; }
295
+ });
296
+ self.mf = __webpack_exports__;
297
+ })();
298
+ })();
299
+ `;
300
+ }
301
+ exports.getESBuildEntry = getESBuildEntry;
302
+ function normalizeFile(file) {
303
+ return file.replace(/\//g, '_');
304
+ }
305
+ function getDepModuleStr(dep) {
306
+ return `
307
+ "./${dep.file}": function() {
308
+ return new Promise(resolve => {
309
+ import('./${constants_1.MF_VA_PREFIX}${normalizeFile(dep.file)}.js').then(module => {
310
+ resolve(() => module);
311
+ });
312
+ })
313
+ }
314
+ `.trim();
315
+ }
package/dist/mfsu.d.ts CHANGED
@@ -14,8 +14,8 @@ interface IOpts {
14
14
  mode?: Mode;
15
15
  tmpBase?: string;
16
16
  unMatchLibs?: string[];
17
- resolvers?: Function[];
18
17
  implementor: typeof webpack;
18
+ buildDepWithESBuild?: boolean;
19
19
  }
20
20
  export declare class MFSU {
21
21
  opts: IOpts;
package/dist/mfsu.js CHANGED
@@ -1,23 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -35,7 +16,6 @@ exports.MFSU = void 0;
35
16
  const utils_1 = require("@umijs/utils");
36
17
  const fs_1 = require("fs");
37
18
  const path_1 = require("path");
38
- const process = __importStar(require("process"));
39
19
  const mrmime_1 = require("../compiled/mrmime");
40
20
  const autoExport_1 = __importDefault(require("./babelPlugins/autoExport"));
41
21
  const awaitImport_1 = __importDefault(require("./babelPlugins/awaitImport/awaitImport"));
@@ -0,0 +1,10 @@
1
+ import type { Compiler } from 'webpack';
2
+ interface IOpts {
3
+ webpack: any;
4
+ }
5
+ export declare class StripSourceMapUrlPlugin {
6
+ opts: IOpts;
7
+ constructor(opts: IOpts);
8
+ apply(compiler: Compiler): void;
9
+ }
10
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StripSourceMapUrlPlugin = void 0;
4
+ class StripSourceMapUrlPlugin {
5
+ constructor(opts) {
6
+ this.opts = opts;
7
+ }
8
+ apply(compiler) {
9
+ compiler.hooks.compilation.tap('StripSourceMapUrlPlugin', (compilation) => {
10
+ compilation.hooks.processAssets.tap({
11
+ name: 'StripSourceMapUrlPlugin',
12
+ stage: this.opts.webpack.Compilation.PROCESS_ASSETS_STAGE_DERIVE,
13
+ }, (assets) => {
14
+ Object.keys(assets)
15
+ .filter((filename) => /\.js$/.test(filename))
16
+ .forEach((filename) => {
17
+ const asset = assets[filename];
18
+ const source = asset
19
+ .source()
20
+ .toString()
21
+ .replace(/# sourceMappingURL=(.+?\.map)/g, '# $1');
22
+ compilation.updateAsset(filename, new this.opts.webpack.sources.RawSource(source));
23
+ });
24
+ });
25
+ });
26
+ }
27
+ }
28
+ exports.StripSourceMapUrlPlugin = StripSourceMapUrlPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/mfsu",
3
- "version": "4.0.0-beta.3",
3
+ "version": "4.0.0-beta.7",
4
4
  "description": "@umijs/mfsu",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,11 +27,13 @@
27
27
  "access": "public"
28
28
  },
29
29
  "dependencies": {
30
- "@umijs/bundler-utils": "4.0.0-beta.3",
31
- "@umijs/utils": "4.0.0-beta.3"
30
+ "@umijs/bundler-esbuild": "4.0.0-beta.7",
31
+ "@umijs/bundler-utils": "4.0.0-beta.7",
32
+ "@umijs/utils": "4.0.0-beta.7"
32
33
  },
33
34
  "devDependencies": {
34
35
  "@types/express": "4.17.13",
36
+ "enhanced-resolve": "5.8.3",
35
37
  "mrmime": "1.0.0",
36
38
  "webpack": "5.61.0"
37
39
  },
@@ -1,3 +0,0 @@
1
- export declare function getFilePath({ path }: {
2
- path: string;
3
- }): string | null;
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFilePath = void 0;
4
- const utils_1 = require("@umijs/utils");
5
- const fs_1 = require("fs");
6
- const path_1 = require("path");
7
- // similar with resolve.extensions in webpack config
8
- const EXT_NAMES = ['.ts', '.tsx', '.jsx', '.mjs', '.js'];
9
- function getPathWithExt(path) {
10
- if ((0, fs_1.existsSync)(path) && (0, fs_1.statSync)(path).isFile()) {
11
- return path;
12
- }
13
- for (const extName of EXT_NAMES) {
14
- const newPath = `${path}${extName}`;
15
- if ((0, fs_1.existsSync)(newPath) && (0, fs_1.statSync)(newPath).isFile()) {
16
- return newPath;
17
- }
18
- }
19
- return null;
20
- }
21
- function getPathWithPkgJSON(path) {
22
- // TODO: 这里是否会有 symlink 问题?
23
- if ((0, fs_1.existsSync)(path) && (0, fs_1.statSync)(path).isDirectory()) {
24
- const pkgPath = (0, path_1.join)(path, 'package.json');
25
- if ((0, fs_1.existsSync)(pkgPath)) {
26
- const pkg = JSON.parse((0, fs_1.readFileSync)(pkgPath, 'utf-8'));
27
- // ref: https://webpack.js.org/configuration/resolve/#resolvemainfields
28
- // TODO: support browser object
29
- // ref: https://unpkg.alibaba-inc.com/browse/react-dom@17.0.2/package.json
30
- const indexTarget = (0, path_1.join)(path, 'index.js');
31
- return ((pkg.module &&
32
- (getPathWithExt((0, path_1.join)(path, pkg.module)) ||
33
- getPathWithIndexFile((0, path_1.join)(path, pkg.module)))) ||
34
- (pkg.main &&
35
- (getPathWithExt((0, path_1.join)(path, pkg.main)) ||
36
- getPathWithIndexFile((0, path_1.join)(path, pkg.main)))) ||
37
- getPathWithExt(indexTarget) ||
38
- getPathWithIndexFile(indexTarget));
39
- }
40
- }
41
- return null;
42
- }
43
- function getPathWithIndexFile(path) {
44
- if ((0, fs_1.existsSync)(path) && (0, fs_1.statSync)(path).isDirectory()) {
45
- for (const extName of EXT_NAMES) {
46
- const indexFilePath = (0, path_1.join)(path, `index${extName}`);
47
- if ((0, fs_1.existsSync)(indexFilePath) && (0, fs_1.statSync)(indexFilePath).isFile()) {
48
- return indexFilePath;
49
- }
50
- }
51
- }
52
- return null;
53
- }
54
- function getFilePath({ path }) {
55
- // 1. 文件存在
56
- // 2. 加后缀
57
- const pathWithExt = getPathWithExt(path);
58
- if (pathWithExt) {
59
- return (0, utils_1.winPath)(pathWithExt);
60
- }
61
- // 3. path + package.json
62
- const pathWithPkgJSON = getPathWithPkgJSON(path);
63
- if (pathWithPkgJSON) {
64
- return (0, utils_1.winPath)(pathWithPkgJSON);
65
- }
66
- // 4. path + index.js
67
- const pathWithIndexFile = getPathWithIndexFile(path);
68
- if (pathWithIndexFile) {
69
- return (0, utils_1.winPath)(pathWithIndexFile);
70
- }
71
- return null;
72
- }
73
- exports.getFilePath = getFilePath;