@tarojs/webpack5-prebundle 3.5.0-beta.3

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.
Files changed (53) hide show
  1. package/README.md +3 -0
  2. package/dist/h5.d.ts +17 -0
  3. package/dist/h5.js +182 -0
  4. package/dist/h5.js.map +1 -0
  5. package/dist/index.d.ts +27 -0
  6. package/dist/index.js +79 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/mini.d.ts +9 -0
  9. package/dist/mini.js +241 -0
  10. package/dist/mini.js.map +1 -0
  11. package/dist/prebundle/bundle.d.ts +25 -0
  12. package/dist/prebundle/bundle.js +223 -0
  13. package/dist/prebundle/bundle.js.map +1 -0
  14. package/dist/prebundle/index.d.ts +45 -0
  15. package/dist/prebundle/index.js +131 -0
  16. package/dist/prebundle/index.js.map +1 -0
  17. package/dist/prebundle/scanImports.d.ts +10 -0
  18. package/dist/prebundle/scanImports.js +192 -0
  19. package/dist/prebundle/scanImports.js.map +1 -0
  20. package/dist/utils/constant.d.ts +13 -0
  21. package/dist/utils/constant.js +65 -0
  22. package/dist/utils/constant.js.map +1 -0
  23. package/dist/utils/index.d.ts +33 -0
  24. package/dist/utils/index.js +175 -0
  25. package/dist/utils/index.js.map +1 -0
  26. package/dist/utils/path.d.ts +2 -0
  27. package/dist/utils/path.js +8 -0
  28. package/dist/utils/path.js.map +1 -0
  29. package/dist/utils/webpack.d.ts +10 -0
  30. package/dist/utils/webpack.js +39 -0
  31. package/dist/utils/webpack.js.map +1 -0
  32. package/dist/webpack/TaroContainerEntryModule.d.ts +12 -0
  33. package/dist/webpack/TaroContainerEntryModule.js +78 -0
  34. package/dist/webpack/TaroContainerEntryModule.js.map +1 -0
  35. package/dist/webpack/TaroContainerEntryModuleFactory.d.ts +6 -0
  36. package/dist/webpack/TaroContainerEntryModuleFactory.js +17 -0
  37. package/dist/webpack/TaroContainerEntryModuleFactory.js.map +1 -0
  38. package/dist/webpack/TaroContainerPlugin.d.ts +25 -0
  39. package/dist/webpack/TaroContainerPlugin.js +77 -0
  40. package/dist/webpack/TaroContainerPlugin.js.map +1 -0
  41. package/dist/webpack/TaroContainerReferencePlugin.d.ts +26 -0
  42. package/dist/webpack/TaroContainerReferencePlugin.js +187 -0
  43. package/dist/webpack/TaroContainerReferencePlugin.js.map +1 -0
  44. package/dist/webpack/TaroModuleFederationPlugin.d.ts +21 -0
  45. package/dist/webpack/TaroModuleFederationPlugin.js +75 -0
  46. package/dist/webpack/TaroModuleFederationPlugin.js.map +1 -0
  47. package/dist/webpack/TaroRemoteRuntimeModule.d.ts +14 -0
  48. package/dist/webpack/TaroRemoteRuntimeModule.js +117 -0
  49. package/dist/webpack/TaroRemoteRuntimeModule.js.map +1 -0
  50. package/dist/webpack/index.d.ts +0 -0
  51. package/dist/webpack/index.js +1 -0
  52. package/dist/webpack/index.js.map +1 -0
  53. package/package.json +48 -0
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # `@tarojs/webpack5-prebundle`
2
+
3
+ Taro webpack5 依赖预加载特性封装
package/dist/h5.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import webpackDevServer from 'webpack-dev-server';
2
+ import VirtualModulesPlugin from 'webpack-virtual-modules';
3
+ import BasePrebundle, { IPrebundleConfig } from './prebundle';
4
+ export declare const VirtualModule: VirtualModulesPlugin;
5
+ export interface IH5PrebundleConfig extends IPrebundleConfig {
6
+ devServer?: webpackDevServer.Configuration;
7
+ publicPath?: string;
8
+ }
9
+ export declare class H5Prebundle extends BasePrebundle<IH5PrebundleConfig> {
10
+ buildLib(): Promise<void>;
11
+ /**
12
+ * TODO:
13
+ * - [ ] 开发环境依赖更新触发 ws 热加载心跳
14
+ * - [ ] 回归 react、vue 热更新状态
15
+ */
16
+ run(): Promise<void>;
17
+ }
package/dist/h5.js ADDED
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.H5Prebundle = exports.VirtualModule = void 0;
16
+ // Inspired by [vite](https://github.com/vitejs/vite)
17
+ /** @license
18
+ * MIT License
19
+ *
20
+ * Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
21
+ *
22
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
23
+ * of this software and associated documentation files (the "Software"), to deal
24
+ * in the Software without restriction, including without limitation the rights
25
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26
+ * copies of the Software, and to permit persons to whom the Software is
27
+ * furnished to do so, subject to the following conditions:
28
+ *
29
+ * The above copyright notice and this permission notice shall be included in all
30
+ * copies or substantial portions of the Software.
31
+ *
32
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38
+ * SOFTWARE.
39
+ */
40
+ const fs_extra_1 = __importDefault(require("fs-extra"));
41
+ const path_1 = __importDefault(require("path"));
42
+ const perf_hooks_1 = require("perf_hooks");
43
+ const webpack_1 = __importDefault(require("webpack"));
44
+ const webpack_virtual_modules_1 = __importDefault(require("webpack-virtual-modules"));
45
+ const prebundle_1 = __importDefault(require("./prebundle"));
46
+ const utils_1 = require("./utils");
47
+ const constant_1 = require("./utils/constant");
48
+ const TaroModuleFederationPlugin_1 = __importDefault(require("./webpack/TaroModuleFederationPlugin"));
49
+ exports.VirtualModule = new webpack_virtual_modules_1.default();
50
+ class H5Prebundle extends prebundle_1.default {
51
+ buildLib() {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ const BUILD_LIB_START = perf_hooks_1.performance.now();
54
+ const exposes = {};
55
+ const { chunkDirectory = 'chunk' } = this.config;
56
+ const mode = process.env.NODE_ENV === 'production' ? 'production' : 'development';
57
+ const devtool = this.config.enableSourceMap && 'hidden-source-map';
58
+ const mainBuildOutput = this.chain.output.entries();
59
+ const publicPath = this.config.publicPath ? (0, utils_1.addLeadingSlash)((0, utils_1.addTrailingSlash)(this.config.publicPath)) : '/';
60
+ const output = {
61
+ chunkFilename: `${chunkDirectory}/[name].js`,
62
+ chunkLoadingGlobal: mainBuildOutput.chunkLoadingGlobal,
63
+ globalObject: mainBuildOutput.globalObject,
64
+ path: this.remoteCacheDir,
65
+ publicPath
66
+ };
67
+ this.metadata.mfHash = (0, utils_1.getMfHash)({
68
+ bundleHash: this.metadata.bundleHash,
69
+ mode,
70
+ devtool,
71
+ output
72
+ });
73
+ if (this.preMetadata.mfHash !== this.metadata.mfHash) {
74
+ this.isUseCache = false;
75
+ fs_extra_1.default.existsSync(this.remoteCacheDir) && fs_extra_1.default.emptyDirSync(this.remoteCacheDir);
76
+ for (const id of this.deps.keys()) {
77
+ const flatId = (0, utils_1.flattenId)(id);
78
+ exposes[`./${id}`] = path_1.default.join(this.prebundleCacheDir, `${flatId}.js`);
79
+ }
80
+ this.metadata.runtimeRequirements = new Set();
81
+ const compiler = (0, webpack_1.default)({
82
+ cache: {
83
+ type: 'filesystem',
84
+ cacheDirectory: path_1.default.join(this.cacheDir, 'webpack-cache'),
85
+ buildDependencies: {
86
+ config: Object.values(exposes)
87
+ }
88
+ },
89
+ devtool,
90
+ entry: path_1.default.resolve(__dirname, './webpack/index.js'),
91
+ mode,
92
+ module: {
93
+ // TODO 同步普通打包文件配置
94
+ rules: [
95
+ {
96
+ test: constant_1.assetsRE,
97
+ type: 'asset/resource',
98
+ generator: {
99
+ filename: 'static/[hash][ext][query]'
100
+ }
101
+ }
102
+ ]
103
+ },
104
+ output,
105
+ plugins: [
106
+ new TaroModuleFederationPlugin_1.default({
107
+ name: constant_1.MF_NAME,
108
+ filename: 'remoteEntry.js',
109
+ runtime: 'runtime',
110
+ exposes
111
+ }, {
112
+ deps: this.deps,
113
+ env: this.env,
114
+ remoteAssets: this.metadata.remoteAssets,
115
+ runtimeRequirements: this.metadata.runtimeRequirements
116
+ })
117
+ ]
118
+ });
119
+ this.metadata.remoteAssets = yield new Promise((resolve, reject) => {
120
+ compiler.run((error, stats) => {
121
+ compiler.close(err => {
122
+ var _a;
123
+ if (error || err)
124
+ return reject(error || err);
125
+ const { assets = [], errors = [] } = stats.toJson();
126
+ if (errors[0])
127
+ return reject(errors[0]);
128
+ const remoteAssets = ((_a = assets === null || assets === void 0 ? void 0 : assets.filter(item => item.name !== 'runtime.js')) === null || _a === void 0 ? void 0 : _a.map(item => ({
129
+ name: path_1.default.join('prebundle', item.name)
130
+ }))) || [];
131
+ resolve(remoteAssets);
132
+ });
133
+ });
134
+ });
135
+ }
136
+ else {
137
+ this.metadata.runtimeRequirements = new Set(this.preMetadata.runtimeRequirements);
138
+ this.metadata.remoteAssets = this.preMetadata.remoteAssets;
139
+ }
140
+ fs_extra_1.default.copy(this.remoteCacheDir, mainBuildOutput.path);
141
+ this.measure(`Build remote ${constant_1.MF_NAME} duration`, BUILD_LIB_START);
142
+ });
143
+ }
144
+ /**
145
+ * TODO:
146
+ * - [ ] 开发环境依赖更新触发 ws 热加载心跳
147
+ * - [ ] 回归 react、vue 热更新状态
148
+ */
149
+ run() {
150
+ const _super = Object.create(null, {
151
+ run: { get: () => super.run }
152
+ });
153
+ return __awaiter(this, void 0, void 0, function* () {
154
+ /** Note: 新增 web 虚拟入口,用于同步加载 webpack 动态依赖 */
155
+ this.addPlugin('VirtualModule', exports.VirtualModule);
156
+ this.isUseCache = true;
157
+ (0, utils_1.createResolve)(this.appPath, this.chain.toConfig().resolve);
158
+ /** 扫描出所有的 node_modules 依赖 */
159
+ const entries = this.getEntries(this.entryPath);
160
+ const { include = [], exclude = [] } = this.option;
161
+ yield this.setDeps(entries, ['@tarojs/taro', '@tarojs/runtime', '@tarojs/router'].concat(include), exclude);
162
+ /** 使用 esbuild 对 node_modules 依赖进行 bundle */
163
+ yield this.bundle();
164
+ /** 把依赖的 bundle 产物打包成 Webpack Module Federation 格式 */
165
+ yield this.buildLib();
166
+ /** 项目 Host 配置 Module Federation */
167
+ this.setHost();
168
+ /** node_modules 已预编译,不需要二次加载 (TODO: 修复 esbuild 加载 css 问题后,也应当移除对应规则对依赖的加载) */
169
+ const script = this.chain.module.rule('script');
170
+ script.exclude.add(/node_modules/);
171
+ // Proxy
172
+ // this.chain.devServer.merge({
173
+ // static: {
174
+ // directory: path.join(appPath, 'node_modules/.taro/h5/remote')
175
+ // }
176
+ // })
177
+ yield _super.run.call(this);
178
+ });
179
+ }
180
+ }
181
+ exports.H5Prebundle = H5Prebundle;
182
+ //# sourceMappingURL=h5.js.map
package/dist/h5.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"h5.js","sourceRoot":"","sources":["../src/h5.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,qDAAqD;AACrD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wDAAyB;AACzB,gDAAuB;AACvB,2CAAwC;AACxC,sDAAwC;AAExC,sFAA0D;AAE1D,4DAA6D;AAC7D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;YAC/B,cAAc;YACd,oEAAoE;YACpE,MAAM;YACN,KAAK;YAEL,MAAM,OAAM,GAAG,WAAE,CAAA;QACnB,CAAC;KAAA;CACF;AAnJD,kCAmJC"}
@@ -0,0 +1,27 @@
1
+ import { EntryObject } from 'webpack';
2
+ import Chain from 'webpack-chain';
3
+ import webpackDevServer from 'webpack-dev-server';
4
+ import { IH5PrebundleConfig } from './h5';
5
+ import { IMiniPrebundleConfig } from './mini';
6
+ import { IPrebundle } from './prebundle';
7
+ export * from './prebundle';
8
+ export interface IPrebundleParam {
9
+ env?: string;
10
+ appPath: string;
11
+ sourceRoot: string;
12
+ chain: Chain;
13
+ entry: EntryObject;
14
+ chunkDirectory?: string;
15
+ enableSourceMap?: boolean;
16
+ entryFileName?: string;
17
+ devServer?: webpackDevServer.Configuration;
18
+ publicPath?: string;
19
+ runtimePath?: string | string[];
20
+ }
21
+ export default class TaroPrebundle {
22
+ protected params: IPrebundleParam;
23
+ env: string;
24
+ constructor(params: IPrebundleParam);
25
+ get config(): IH5PrebundleConfig | IMiniPrebundleConfig;
26
+ run(options: IPrebundle): Promise<void>;
27
+ }
package/dist/index.js ADDED
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
+ };
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
28
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ __exportStar(require("./prebundle"), exports);
39
+ class TaroPrebundle {
40
+ constructor(params) {
41
+ this.params = params;
42
+ const { env = process.env.TARO_ENV || 'h5' } = params;
43
+ this.env = env;
44
+ }
45
+ get config() {
46
+ const env = this.env;
47
+ const { appPath, chain, chunkDirectory = 'chunk', devServer, enableSourceMap = false, entryFileName = 'app', entry = {}, publicPath, runtimePath, sourceRoot } = this.params;
48
+ return {
49
+ appPath,
50
+ chain,
51
+ chunkDirectory,
52
+ devServer,
53
+ enableSourceMap,
54
+ entryFileName,
55
+ entry,
56
+ env,
57
+ publicPath,
58
+ runtimePath,
59
+ sourceRoot
60
+ };
61
+ }
62
+ run(options) {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ if (!options.enable)
65
+ return;
66
+ let prebundleRunner;
67
+ switch (this.env) {
68
+ case 'h5':
69
+ prebundleRunner = new (yield Promise.resolve().then(() => __importStar(require('./h5')))).H5Prebundle(this.config, options);
70
+ break;
71
+ default:
72
+ prebundleRunner = new (yield Promise.resolve().then(() => __importStar(require('./mini')))).MiniPrebundle(this.config, options);
73
+ }
74
+ return prebundleRunner.run();
75
+ });
76
+ }
77
+ }
78
+ exports.default = TaroPrebundle;
79
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,8CAA2B;AAkB3B,MAAqB,aAAa;IAGhC,YAAuB,MAAuB;QAAvB,WAAM,GAAN,MAAM,CAAiB;QAC5C,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,IAAI,EAAE,GAAG,MAAM,CAAA;QACrD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED,IAAI,MAAM;QACR,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAA;QACpB,MAAM,EACJ,OAAO,EACP,KAAK,EACL,cAAc,GAAG,OAAO,EACxB,SAAS,EACT,eAAe,GAAG,KAAK,EACvB,aAAa,GAAG,KAAK,EACrB,KAAK,GAAG,EAAE,EACV,UAAU,EACV,WAAW,EACX,UAAU,EACX,GAAG,IAAI,CAAC,MAAM,CAAA;QAEf,OAAO;YACL,OAAO;YACP,KAAK;YACL,cAAc;YACd,SAAS;YACT,eAAe;YACf,aAAa;YACb,KAAK;YACL,GAAG;YACH,UAAU;YACV,WAAW;YACX,UAAU;SACX,CAAA;IACH,CAAC;IAEK,GAAG,CAAE,OAAmB;;YAC5B,IAAI,CAAC,OAAO,CAAC,MAAM;gBAAE,OAAM;YAE3B,IAAI,eAA8B,CAAA;YAElC,QAAQ,IAAI,CAAC,GAAG,EAAE;gBAChB,KAAK,IAAI;oBACP,eAAe,GAAG,IAAI,CAAC,wDAAa,MAAM,GAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;oBAC9E,MAAK;gBACP;oBACE,eAAe,GAAG,IAAI,CAAC,wDAAa,QAAQ,GAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;aACrF;YAED,OAAO,eAAe,CAAC,GAAG,EAAE,CAAA;QAC9B,CAAC;KAAA;CACF;AArDD,gCAqDC"}
package/dist/mini.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import BasePrebundle, { IPrebundleConfig } from './prebundle';
2
+ export interface IMiniPrebundleConfig extends IPrebundleConfig {
3
+ runtimePath?: string | string[];
4
+ }
5
+ export declare class MiniPrebundle extends BasePrebundle<IMiniPrebundleConfig> {
6
+ bundle(): Promise<void>;
7
+ buildLib(): Promise<void>;
8
+ run(): Promise<void>;
9
+ }
package/dist/mini.js ADDED
@@ -0,0 +1,241 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.MiniPrebundle = void 0;
39
+ // Inspired by [vite](https://github.com/vitejs/vite)
40
+ /** @license
41
+ * MIT License
42
+ *
43
+ * Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
44
+ *
45
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
46
+ * of this software and associated documentation files (the "Software"), to deal
47
+ * in the Software without restriction, including without limitation the rights
48
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
49
+ * copies of the Software, and to permit persons to whom the Software is
50
+ * furnished to do so, subject to the following conditions:
51
+ *
52
+ * The above copyright notice and this permission notice shall be included in all
53
+ * copies or substantial portions of the Software.
54
+ *
55
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
56
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
57
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
58
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
59
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
60
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
61
+ * SOFTWARE.
62
+ */
63
+ const fs_extra_1 = __importDefault(require("fs-extra"));
64
+ const path_1 = __importDefault(require("path"));
65
+ const perf_hooks_1 = require("perf_hooks");
66
+ const webpack_1 = __importStar(require("webpack"));
67
+ const prebundle_1 = __importDefault(require("./prebundle"));
68
+ const bundle_1 = require("./prebundle/bundle");
69
+ const utils_1 = require("./utils");
70
+ const constant_1 = require("./utils/constant");
71
+ const TaroModuleFederationPlugin_1 = __importDefault(require("./webpack/TaroModuleFederationPlugin"));
72
+ class MiniPrebundle extends prebundle_1.default {
73
+ bundle() {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ const PREBUNDLE_START = perf_hooks_1.performance.now();
76
+ this.metadata.bundleHash = yield (0, utils_1.getBundleHash)(this.appPath, this.deps, this.chain, this.cacheDir);
77
+ if (this.preMetadata.bundleHash !== this.metadata.bundleHash) {
78
+ this.isUseCache = false;
79
+ const { metafile } = yield (0, bundle_1.bundle)({
80
+ appPath: this.appPath,
81
+ deps: this.deps,
82
+ chain: this.chain,
83
+ prebundleOutputDir: this.prebundleCacheDir,
84
+ customEsbuildConfig: this.customEsbuildConfig,
85
+ customSwcConfig: this.customSwcConfig
86
+ });
87
+ // 找出 @tarojs/runtime 被 split 切分的 chunk,作为后续 ProvidePlugin 的提供者。
88
+ // 原因是 @tarojs/runtime 里使用了一些如 raf、caf 等全局变量,又因为 esbuild 把
89
+ // @tarojs/runtime split 成 entry 和依赖 chunk 两部分。如果我们把 entry 作为
90
+ // ProvidePlugin 的提供者,依赖 chunk 会被注入 raf、caf,导致循环依赖的问题。所以
91
+ // 这种情况下只能把依赖 chunk 作为 ProvidePlugin 的提供者。
92
+ metafile && Object.keys(metafile.outputs).some(key => {
93
+ const output = metafile.outputs[key];
94
+ if (output.entryPoint === 'entry:@tarojs_runtime') {
95
+ const dep = output.imports.find(dep => {
96
+ const depPath = dep.path;
97
+ const depOutput = metafile.outputs[depPath];
98
+ return depOutput.exports.includes('TaroRootElement');
99
+ });
100
+ if (dep) {
101
+ this.metadata.taroRuntimeBundlePath = path_1.default.join(this.appPath, dep.path);
102
+ }
103
+ return true;
104
+ }
105
+ });
106
+ }
107
+ else {
108
+ this.metadata.taroRuntimeBundlePath = path_1.default.join(this.appPath, this.preMetadata.taroRuntimeBundlePath);
109
+ }
110
+ this.measure('Prebundle duration', PREBUNDLE_START);
111
+ });
112
+ }
113
+ buildLib() {
114
+ var _a;
115
+ return __awaiter(this, void 0, void 0, function* () {
116
+ const BUILD_LIB_START = perf_hooks_1.performance.now();
117
+ const exposes = {};
118
+ const mode = process.env.NODE_ENV === 'production' ? 'production' : 'development';
119
+ const devtool = this.config.enableSourceMap && 'hidden-source-map';
120
+ const mainBuildOutput = this.chain.output.entries();
121
+ const taroRuntimeBundlePath = this.metadata.taroRuntimeBundlePath || exposes['./@tarojs/runtime'];
122
+ const output = {
123
+ path: this.remoteCacheDir,
124
+ chunkLoadingGlobal: mainBuildOutput.chunkLoadingGlobal,
125
+ globalObject: mainBuildOutput.globalObject
126
+ };
127
+ const provideObject = {
128
+ window: [taroRuntimeBundlePath, 'window$1'],
129
+ document: [taroRuntimeBundlePath, 'document$1'],
130
+ navigator: [taroRuntimeBundlePath, 'navigator'],
131
+ requestAnimationFrame: [taroRuntimeBundlePath, 'raf'],
132
+ cancelAnimationFrame: [taroRuntimeBundlePath, 'caf'],
133
+ Element: [taroRuntimeBundlePath, 'TaroElement'],
134
+ SVGElement: [taroRuntimeBundlePath, 'SVGElement'],
135
+ MutationObserver: [taroRuntimeBundlePath, 'MutationObserver']
136
+ };
137
+ const customWebpackConfig = this.option.webpack;
138
+ if ((_a = customWebpackConfig === null || customWebpackConfig === void 0 ? void 0 : customWebpackConfig.provide) === null || _a === void 0 ? void 0 : _a.length) {
139
+ customWebpackConfig.provide.forEach(cb => {
140
+ cb(provideObject, taroRuntimeBundlePath);
141
+ });
142
+ }
143
+ this.metadata.mfHash = (0, utils_1.getMfHash)({
144
+ bundleHash: this.metadata.bundleHash,
145
+ mode,
146
+ devtool,
147
+ output,
148
+ taroRuntimeBundlePath
149
+ });
150
+ if (this.preMetadata.mfHash !== this.metadata.mfHash) {
151
+ this.isUseCache = false;
152
+ fs_extra_1.default.existsSync(this.remoteCacheDir) && fs_extra_1.default.emptyDirSync(this.remoteCacheDir);
153
+ for (const id of this.deps.keys()) {
154
+ const flatId = (0, utils_1.flattenId)(id);
155
+ exposes[`./${id}`] = path_1.default.join(this.prebundleCacheDir, `${flatId}.js`);
156
+ }
157
+ this.metadata.runtimeRequirements = new Set();
158
+ const compiler = (0, webpack_1.default)({
159
+ cache: {
160
+ type: 'filesystem',
161
+ cacheDirectory: path_1.default.join(this.cacheDir, 'webpack-cache'),
162
+ buildDependencies: {
163
+ config: Object.values(exposes)
164
+ }
165
+ },
166
+ devtool,
167
+ entry: path_1.default.resolve(__dirname, './webpack/index.js'),
168
+ mode,
169
+ output,
170
+ plugins: [
171
+ new TaroModuleFederationPlugin_1.default({
172
+ name: constant_1.MF_NAME,
173
+ filename: 'remoteEntry.js',
174
+ runtime: 'runtime',
175
+ exposes
176
+ }, {
177
+ deps: this.deps,
178
+ env: this.env,
179
+ remoteAssets: this.metadata.remoteAssets,
180
+ runtimeRequirements: this.metadata.runtimeRequirements
181
+ }),
182
+ new webpack_1.ProvidePlugin(provideObject)
183
+ ]
184
+ });
185
+ this.metadata.remoteAssets = yield new Promise((resolve, reject) => {
186
+ compiler.run((error, stats) => {
187
+ compiler.close(err => {
188
+ var _a;
189
+ if (error || err)
190
+ return reject(error || err);
191
+ const { assets = [], errors = [] } = stats.toJson();
192
+ if (errors[0])
193
+ return reject(errors[0]);
194
+ const remoteAssets = ((_a = assets === null || assets === void 0 ? void 0 : assets.filter(item => item.name !== 'runtime.js')) === null || _a === void 0 ? void 0 : _a.map(item => ({
195
+ name: path_1.default.join('prebundle', item.name)
196
+ }))) || [];
197
+ resolve(remoteAssets);
198
+ });
199
+ });
200
+ });
201
+ }
202
+ else {
203
+ this.metadata.runtimeRequirements = new Set(this.preMetadata.runtimeRequirements);
204
+ this.metadata.remoteAssets = this.preMetadata.remoteAssets;
205
+ }
206
+ fs_extra_1.default.copy(this.remoteCacheDir, path_1.default.join(mainBuildOutput.path, 'prebundle'));
207
+ this.measure(`Build remote ${constant_1.MF_NAME} duration`, BUILD_LIB_START);
208
+ });
209
+ }
210
+ run() {
211
+ const _super = Object.create(null, {
212
+ run: { get: () => super.run }
213
+ });
214
+ return __awaiter(this, void 0, void 0, function* () {
215
+ this.isUseCache = true;
216
+ (0, utils_1.createResolve)(this.appPath, this.chain.toConfig().resolve);
217
+ /** 扫描出所有的 node_modules 依赖 */
218
+ /**
219
+ * 找出所有 webpack entry
220
+ * TODO:
221
+ * - 目前只处理了 Page entry,例如原生小程序组件 js entry 等并没有处理
222
+ */
223
+ const entries = this.getEntries(this.entryPath);
224
+ // plugin-platform 等插件的 runtime 文件入口
225
+ const runtimePath = typeof this.config.runtimePath === 'string' ? [this.config.runtimePath] : this.config.runtimePath || [];
226
+ const { include = [], exclude = [] } = this.option;
227
+ yield this.setDeps(entries, ['@tarojs/taro', '@tarojs/runtime'].concat(...runtimePath.map(item => item.replace(/^post:/, '')), include), [
228
+ '@tarojs/components' // 小程序编译 Host 时需要扫描 @tarojs/components 的 useExports,因此不能被 external
229
+ ].concat(exclude));
230
+ /** 使用 esbuild 对 node_modules 依赖进行 bundle */
231
+ yield this.bundle();
232
+ /** 把依赖的 bundle 产物打包成 Webpack Module Federation 格式 */
233
+ yield this.buildLib();
234
+ /** 项目 Host 配置 Module Federation */
235
+ this.setHost();
236
+ yield _super.run.call(this);
237
+ });
238
+ }
239
+ }
240
+ exports.MiniPrebundle = MiniPrebundle;
241
+ //# sourceMappingURL=mini.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mini.js","sourceRoot":"","sources":["../src/mini.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAqD;AACrD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,w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{ parse } from 'es-module-lexer';
3
+ import esbuild, { Plugin } from 'esbuild';
4
+ import Chain from 'webpack-chain';
5
+ import { CollectedDeps } from '../utils/constant';
6
+ declare type ExportsData = ReturnType<typeof parse> & {
7
+ hasReExports?: boolean;
8
+ needInterop?: boolean;
9
+ };
10
+ interface BundleConfig {
11
+ appPath: string;
12
+ deps: CollectedDeps;
13
+ chain: Chain;
14
+ prebundleOutputDir: string;
15
+ customEsbuildConfig?: Record<string, any>;
16
+ customSwcConfig?: swc.Config;
17
+ }
18
+ export declare function bundle({ appPath, deps, chain, prebundleOutputDir, customEsbuildConfig, customSwcConfig }: BundleConfig): Promise<esbuild.BuildResult & {
19
+ outputFiles: esbuild.OutputFile[];
20
+ }>;
21
+ export declare function getSwcPlugin({ appPath, flatIdExports }: {
22
+ appPath: string;
23
+ flatIdExports: Map<string, ExportsData>;
24
+ }, config?: swc.Config): Plugin;
25
+ export {};