@tarojs/webpack5-prebundle 3.8.0-canary.0 → 4.0.0-alpha.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.
- package/LICENSE +11 -4
- package/dist/index.d.ts +4 -1
- package/dist/index.js +11 -8
- package/dist/index.js.map +1 -1
- package/dist/mini.js +13 -13
- package/dist/mini.js.map +1 -1
- package/dist/prebundle/bundle.d.ts +17 -4
- package/dist/prebundle/bundle.js +34 -41
- package/dist/prebundle/bundle.js.map +1 -1
- package/dist/prebundle/index.d.ts +5 -1
- package/dist/prebundle/index.js +31 -23
- package/dist/prebundle/index.js.map +1 -1
- package/dist/prebundle/scanImports.d.ts +2 -1
- package/dist/prebundle/scanImports.js +20 -23
- package/dist/prebundle/scanImports.js.map +1 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +9 -14
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/path.js.map +1 -1
- package/dist/utils/webpack.js +2 -2
- package/dist/utils/webpack.js.map +1 -1
- package/dist/web.js +15 -9
- package/dist/web.js.map +1 -1
- package/dist/webpack/TaroContainerEntryModule.d.ts +1 -0
- package/dist/webpack/TaroContainerEntryModule.js.map +1 -1
- package/dist/webpack/TaroContainerPlugin.d.ts +1 -0
- package/dist/webpack/TaroContainerPlugin.js.map +1 -1
- package/dist/webpack/TaroContainerReferencePlugin.d.ts +2 -0
- package/dist/webpack/TaroContainerReferencePlugin.js +3 -3
- package/dist/webpack/TaroContainerReferencePlugin.js.map +1 -1
- package/dist/webpack/TaroModuleFederationPlugin.d.ts +2 -0
- package/dist/webpack/TaroModuleFederationPlugin.js.map +1 -1
- package/dist/webpack/TaroRemoteRuntimeModule.js.map +1 -1
- package/package.json +18 -20
package/LICENSE
CHANGED
|
@@ -154,7 +154,14 @@ See `/LICENSE` for details of the license.
|
|
|
154
154
|
|
|
155
155
|
==================
|
|
156
156
|
|
|
157
|
-
MIT (
|
|
158
|
-
The following files embed [
|
|
159
|
-
`/packages/taro-components
|
|
160
|
-
See `/LICENSE` for details of the license.
|
|
157
|
+
MIT (weui):
|
|
158
|
+
The following files embed [weui](https://github.com/Tencent/weui) MIT:
|
|
159
|
+
`/packages/taro-components/src/components/*.scss`
|
|
160
|
+
See `/LICENSE.txt` for details of the license.
|
|
161
|
+
|
|
162
|
+
==================
|
|
163
|
+
|
|
164
|
+
Apache-2.0 (intersection-observer):
|
|
165
|
+
The following files embed [intersection-observer](https://github.com/GoogleChromeLabs/intersection-observer) Apache-2.0:
|
|
166
|
+
`/packages/taro-api/src/polyfill/intersection-observer.ts`
|
|
167
|
+
See `/LICENSE.txt` for details of the license.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { PLATFORM_TYPE } from '@tarojs/shared';
|
|
2
|
-
import webpackDevServer from 'webpack-dev-server';
|
|
3
2
|
import { IPrebundle } from './prebundle';
|
|
4
3
|
import { type IWebPrebundleConfig } from './web';
|
|
5
4
|
import type { Compiler, EntryObject } from 'webpack';
|
|
6
5
|
import type Chain from 'webpack-chain';
|
|
6
|
+
import type webpackDevServer from 'webpack-dev-server';
|
|
7
7
|
import type { IMiniPrebundleConfig } from './mini';
|
|
8
8
|
export * from './prebundle';
|
|
9
9
|
export interface IPrebundleParam {
|
|
@@ -21,6 +21,9 @@ export interface IPrebundleParam {
|
|
|
21
21
|
publicPath?: string;
|
|
22
22
|
runtimePath?: string | string[];
|
|
23
23
|
isBuildPlugin?: boolean;
|
|
24
|
+
alias?: Record<string, any>;
|
|
25
|
+
defineConstants?: Record<string, any>;
|
|
26
|
+
modifyAppConfig?: (appConfig: any) => Promise<any>;
|
|
24
27
|
}
|
|
25
28
|
export default class TaroPrebundle {
|
|
26
29
|
protected params: IPrebundleParam;
|
package/dist/index.js
CHANGED
|
@@ -38,8 +38,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
39
39
|
};
|
|
40
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
41
42
|
const shared_1 = require("@tarojs/shared");
|
|
42
|
-
const path_1 = __importDefault(require("path"));
|
|
43
43
|
const web_1 = require("./web");
|
|
44
44
|
__exportStar(require("./prebundle"), exports);
|
|
45
45
|
class TaroPrebundle {
|
|
@@ -55,7 +55,7 @@ class TaroPrebundle {
|
|
|
55
55
|
var _a, _b;
|
|
56
56
|
const platformType = this.platformType;
|
|
57
57
|
const env = this.env;
|
|
58
|
-
const { appPath = process.cwd(), chain, chunkDirectory = 'chunk', devServer = (_a = chain.devServer) === null || _a === void 0 ? void 0 : _a.entries(), enableSourceMap = false, entryFileName = 'app', entry = this.entry, isWatch = false, publicPath = chain.output.get('publicPath') || '/', runtimePath, sourceRoot = 'src', isBuildPlugin } = this.params;
|
|
58
|
+
const { appPath = process.cwd(), chain, chunkDirectory = 'chunk', devServer = (_a = chain.devServer) === null || _a === void 0 ? void 0 : _a.entries(), enableSourceMap = false, entryFileName = 'app', entry = this.entry, isWatch = false, publicPath = chain.output.get('publicPath') || '/', runtimePath, sourceRoot = 'src', isBuildPlugin, alias, defineConstants, modifyAppConfig, } = this.params;
|
|
59
59
|
let chunkFilename = (_b = chain.output.get('chunkFilename')) !== null && _b !== void 0 ? _b : `${chunkDirectory}/[name].js`;
|
|
60
60
|
chunkFilename = chunkFilename.replace(/\[([a-z]*hash)[^[\]\s]*\]/ig, '_$1_');
|
|
61
61
|
chain.output.set('chunkFilename', chunkFilename);
|
|
@@ -73,7 +73,10 @@ class TaroPrebundle {
|
|
|
73
73
|
publicPath,
|
|
74
74
|
runtimePath,
|
|
75
75
|
sourceRoot,
|
|
76
|
-
isBuildPlugin
|
|
76
|
+
isBuildPlugin,
|
|
77
|
+
alias,
|
|
78
|
+
defineConstants,
|
|
79
|
+
modifyAppConfig,
|
|
77
80
|
};
|
|
78
81
|
}
|
|
79
82
|
get entry() {
|
|
@@ -83,8 +86,8 @@ class TaroPrebundle {
|
|
|
83
86
|
return entry;
|
|
84
87
|
}, {});
|
|
85
88
|
}
|
|
86
|
-
run(
|
|
87
|
-
return __awaiter(this,
|
|
89
|
+
run() {
|
|
90
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
88
91
|
this.options = options;
|
|
89
92
|
if (!options.enable)
|
|
90
93
|
return;
|
|
@@ -119,9 +122,9 @@ class TaroPrebundle {
|
|
|
119
122
|
else {
|
|
120
123
|
resource = item.import[0];
|
|
121
124
|
}
|
|
122
|
-
const { dir, name } =
|
|
123
|
-
const filePath =
|
|
124
|
-
const bootPath =
|
|
125
|
+
const { dir, name } = node_path_1.default.parse(resource);
|
|
126
|
+
const filePath = node_path_1.default.join(dir, name).replace(/\.config/, '');
|
|
127
|
+
const bootPath = node_path_1.default.relative(this.config.appPath, `${filePath}.boot.js`);
|
|
125
128
|
web_1.VirtualModule.writeModule(bootPath, '/** bootstrap application code */');
|
|
126
129
|
});
|
|
127
130
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA+D;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA4B;AAE5B,2CAA+D;AAG/D,+BAA+D;AAO/D,8CAA2B;AAwB3B,MAAqB,aAAa;IAQhC,YAAuB,MAAuB;QAAvB,WAAM,GAAN,MAAM,CAAiB;QAC5C,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,IAAI,EAAE,aAAa,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;QAE5E,MAAM,QAAQ,GAAG,MAAM,CAAC,YAAY,IAA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,IAAI,EAAE,EAAE;oBACzC,IAAI,QAAQ,GAAG,EAAE,CAAA;oBACjB,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;wBACxB,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;oBACpB,CAAC;yBAAM,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;wBACpC,QAAQ,GAAG,IAAI,CAAA;oBACjB,CAAC;yBAAM,IAAI,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;wBAC3C,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAA;oBACxB,CAAC;yBAAM,CAAC;wBACN,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;oBAC3B,CAAC;oBACD,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,mBAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;oBAC1C,MAAM,QAAQ,GAAG,mBAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;oBAC7D,MAAM,QAAQ,GAAG,mBAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,QAAQ,UAAU,CAAC,CAAA;oBAC1E,mBAAa,CAAC,WAAW,CAAC,QAAQ,EAAE,mCAAmC,CAAC,CAAA;gBAC1E,CAAC,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;KAAA;CACF;AA/GD,gCA+GC"}
|
package/dist/mini.js
CHANGED
|
@@ -37,9 +37,9 @@ exports.MiniPrebundle = void 0;
|
|
|
37
37
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
38
38
|
* SOFTWARE.
|
|
39
39
|
*/
|
|
40
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
41
|
+
const node_perf_hooks_1 = require("node:perf_hooks");
|
|
40
42
|
const helper_1 = require("@tarojs/helper");
|
|
41
|
-
const path_1 = __importDefault(require("path"));
|
|
42
|
-
const perf_hooks_1 = require("perf_hooks");
|
|
43
43
|
const webpack_1 = require("webpack");
|
|
44
44
|
const prebundle_1 = __importDefault(require("./prebundle"));
|
|
45
45
|
const bundle_1 = require("./prebundle/bundle");
|
|
@@ -52,7 +52,7 @@ class MiniPrebundle extends prebundle_1.default {
|
|
|
52
52
|
}
|
|
53
53
|
bundle() {
|
|
54
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
const PREBUNDLE_START =
|
|
55
|
+
const PREBUNDLE_START = node_perf_hooks_1.performance.now();
|
|
56
56
|
this.metadata.bundleHash = yield (0, utils_1.getBundleHash)(this.appPath, this.deps, this.chain, this.cacheDir);
|
|
57
57
|
if (this.preMetadata.bundleHash !== this.metadata.bundleHash) {
|
|
58
58
|
this.isUseCache = false;
|
|
@@ -79,7 +79,7 @@ class MiniPrebundle extends prebundle_1.default {
|
|
|
79
79
|
return depOutput.exports.includes('TaroRootElement');
|
|
80
80
|
});
|
|
81
81
|
if (dep) {
|
|
82
|
-
this.metadata.taroRuntimeBundlePath =
|
|
82
|
+
this.metadata.taroRuntimeBundlePath = node_path_1.default.join(this.appPath, dep.path);
|
|
83
83
|
}
|
|
84
84
|
return true;
|
|
85
85
|
}
|
|
@@ -90,15 +90,15 @@ class MiniPrebundle extends prebundle_1.default {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
else {
|
|
93
|
-
this.metadata.taroRuntimeBundlePath =
|
|
93
|
+
this.metadata.taroRuntimeBundlePath = node_path_1.default.join(this.appPath, this.preMetadata.taroRuntimeBundlePath);
|
|
94
94
|
}
|
|
95
95
|
this.measure('Prebundle duration', PREBUNDLE_START);
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
buildLib() {
|
|
99
|
-
var _a;
|
|
100
99
|
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
|
|
100
|
+
var _a;
|
|
101
|
+
const BUILD_LIB_START = node_perf_hooks_1.performance.now();
|
|
102
102
|
const exposes = {};
|
|
103
103
|
const devtool = this.config.enableSourceMap && 'hidden-source-map';
|
|
104
104
|
const mainBuildOutput = this.chain.output.entries();
|
|
@@ -141,19 +141,19 @@ class MiniPrebundle extends prebundle_1.default {
|
|
|
141
141
|
helper_1.fs.existsSync(this.remoteCacheDir) && helper_1.fs.emptyDirSync(this.remoteCacheDir);
|
|
142
142
|
for (const id of this.deps.keys()) {
|
|
143
143
|
const flatId = (0, utils_1.flattenId)(id);
|
|
144
|
-
exposes[`./${id}`] =
|
|
144
|
+
exposes[`./${id}`] = node_path_1.default.join(this.prebundleCacheDir, `${flatId}.js`);
|
|
145
145
|
}
|
|
146
146
|
this.metadata.runtimeRequirements = new Set();
|
|
147
147
|
const compiler = this.getRemoteWebpackCompiler({
|
|
148
148
|
cache: {
|
|
149
149
|
type: 'filesystem',
|
|
150
|
-
cacheDirectory:
|
|
150
|
+
cacheDirectory: node_path_1.default.join(this.cacheDir, 'webpack-cache'),
|
|
151
151
|
buildDependencies: {
|
|
152
152
|
config: Object.values(exposes)
|
|
153
153
|
}
|
|
154
154
|
},
|
|
155
155
|
devtool,
|
|
156
|
-
entry:
|
|
156
|
+
entry: node_path_1.default.resolve(__dirname, './webpack/index.js'),
|
|
157
157
|
mode: this.mode,
|
|
158
158
|
output,
|
|
159
159
|
plugins: [
|
|
@@ -185,7 +185,7 @@ class MiniPrebundle extends prebundle_1.default {
|
|
|
185
185
|
const remoteAssets = ((_a = assets === null || assets === void 0 ? void 0 : assets.filter(item => this.config.isBuildPlugin
|
|
186
186
|
? item.name !== 'plugin/runtime.js'
|
|
187
187
|
: item.name !== 'runtime.js')) === null || _a === void 0 ? void 0 : _a.map(item => ({
|
|
188
|
-
name:
|
|
188
|
+
name: node_path_1.default.join('prebundle', item.name)
|
|
189
189
|
}))) || [];
|
|
190
190
|
resolve(remoteAssets);
|
|
191
191
|
});
|
|
@@ -196,7 +196,7 @@ class MiniPrebundle extends prebundle_1.default {
|
|
|
196
196
|
this.metadata.runtimeRequirements = new Set(this.preMetadata.runtimeRequirements);
|
|
197
197
|
this.metadata.remoteAssets = this.preMetadata.remoteAssets;
|
|
198
198
|
}
|
|
199
|
-
helper_1.fs.copy(this.remoteCacheDir,
|
|
199
|
+
helper_1.fs.copy(this.remoteCacheDir, node_path_1.default.join(this.getIsBuildPluginPath(mainBuildOutput.path, this.config.isBuildPlugin), 'prebundle'));
|
|
200
200
|
this.measure(`Build remote ${constant_1.MF_NAME} duration`, BUILD_LIB_START);
|
|
201
201
|
});
|
|
202
202
|
}
|
|
@@ -212,7 +212,7 @@ class MiniPrebundle extends prebundle_1.default {
|
|
|
212
212
|
* TODO:
|
|
213
213
|
* - 目前只处理了 Page entry,例如原生小程序组件 js entry 等并没有处理
|
|
214
214
|
*/
|
|
215
|
-
const entries = this.getEntries(this.entryPath);
|
|
215
|
+
const entries = yield this.getEntries(this.entryPath);
|
|
216
216
|
// plugin-platform 等插件的 runtime 文件入口
|
|
217
217
|
const runtimePath = typeof this.config.runtimePath === 'string' ? [this.config.runtimePath] : this.config.runtimePath || [];
|
|
218
218
|
const { include = [], exclude = [] } = this.option;
|
package/dist/mini.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mini.js","sourceRoot":"","sources":["../src/mini.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,qDAAqD;AACrD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,
|
|
1
|
+
{"version":3,"file":"mini.js","sourceRoot":"","sources":["../src/mini.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,qDAAqD;AACrD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,0DAA4B;AAC5B,qDAA6C;AAE7C,2CAAmC;AACnC,qCAAuC;AAEvC,4DAA6D;AAC7D,+CAA2C;AAC3C,mCAIgB;AAChB,+CAA0C;AAC1C,sGAA6E;AAS7E,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G,EAAE,EAAE,GAAG,IAAI,CAAC,MAAM,CAAA;YAClD,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,CACxC,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CACvD,EAAE,OAAO,CAAC,CAAA;YAEX,4CAA4C;YAC5C,MAAM,IAAI,CAAC,MAAM,EAAE,CAAA;YAEnB,qDAAqD;YACrD,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAA;YAErB,mCAAmC;YACnC,IAAI,CAAC,OAAO,EAAE,CAAA;YAEd,MAAM,OAAM,GAAG,WAAE,CAAA;QACnB,CAAC;KAAA;CACF;AApMD,sCAoMC"}
|
|
@@ -13,11 +13,24 @@ interface BundleConfig {
|
|
|
13
13
|
prebundleOutputDir: string;
|
|
14
14
|
customEsbuildConfig?: Record<string, any>;
|
|
15
15
|
customSwcConfig?: swc.Config;
|
|
16
|
+
mainFields?: string[];
|
|
16
17
|
}
|
|
17
|
-
export declare function bundle({ appPath, deps, chain, prebundleOutputDir, customEsbuildConfig, customSwcConfig }: BundleConfig): Promise<esbuild.BuildResult
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
export declare function bundle({ appPath, deps, chain, prebundleOutputDir, customEsbuildConfig, customSwcConfig, mainFields }: BundleConfig): Promise<esbuild.BuildResult<{
|
|
19
|
+
absWorkingDir: string;
|
|
20
|
+
bundle: true;
|
|
21
|
+
write: false;
|
|
22
|
+
entryPoints: string[];
|
|
23
|
+
mainFields: string[];
|
|
24
|
+
format: "esm";
|
|
25
|
+
loader: any;
|
|
26
|
+
define: any;
|
|
27
|
+
splitting: true;
|
|
28
|
+
metafile: true;
|
|
29
|
+
ignoreAnnotations: true;
|
|
30
|
+
outdir: string;
|
|
31
|
+
plugins: any[];
|
|
32
|
+
}>>;
|
|
33
|
+
export declare function getSwcPlugin({ appPath, flatIdExports, }: {
|
|
21
34
|
appPath: string;
|
|
22
35
|
flatIdExports: Map<string, ExportsData>;
|
|
23
36
|
}, config?: swc.Config): esbuild.Plugin;
|
package/dist/prebundle/bundle.js
CHANGED
|
@@ -13,10 +13,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.getSwcPlugin = exports.bundle = void 0;
|
|
16
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
16
17
|
const helper_1 = require("@tarojs/helper");
|
|
17
18
|
const es_module_lexer_1 = require("es-module-lexer");
|
|
18
19
|
const lodash_1 = require("lodash");
|
|
19
|
-
const path_1 = __importDefault(require("path"));
|
|
20
20
|
const utils_1 = require("../utils");
|
|
21
21
|
const constant_1 = require("../utils/constant");
|
|
22
22
|
// esbuild generates nested directory output with lowest common ancestor base
|
|
@@ -25,8 +25,8 @@ const constant_1 = require("../utils/constant");
|
|
|
25
25
|
// 1. flatten all ids to eliminate slash
|
|
26
26
|
// 2. in the plugin, read the entry ourselves as virtual files to retain the
|
|
27
27
|
// path.
|
|
28
|
-
function bundle(
|
|
29
|
-
return __awaiter(this,
|
|
28
|
+
function bundle(_a) {
|
|
29
|
+
return __awaiter(this, arguments, void 0, function* ({ appPath, deps, chain, prebundleOutputDir, customEsbuildConfig = {}, customSwcConfig = {}, mainFields = [...helper_1.defaultMainFields] }) {
|
|
30
30
|
yield es_module_lexer_1.init;
|
|
31
31
|
const flattenDeps = new Map();
|
|
32
32
|
const flatIdExports = new Map();
|
|
@@ -46,10 +46,8 @@ function bundle({ appPath, deps, chain, prebundleOutputDir, customEsbuildConfig
|
|
|
46
46
|
}
|
|
47
47
|
flatIdExports.set(flatId, exportsData);
|
|
48
48
|
}
|
|
49
|
-
helper_1.fs.existsSync(prebundleOutputDir)
|
|
50
|
-
|
|
51
|
-
: helper_1.fs.ensureDirSync(prebundleOutputDir);
|
|
52
|
-
return helper_1.esbuild.build(Object.assign(Object.assign({}, customEsbuildConfig), { absWorkingDir: appPath, bundle: true, write: false, entryPoints: Array.from(flattenDeps.keys()), mainFields: ['main:h5', 'browser', 'module', 'jsnext:main', 'main'], format: 'esm', loader: (0, lodash_1.defaults)(customEsbuildConfig.loader, helper_1.defaultEsbuildLoader), define: Object.assign(Object.assign({}, (0, utils_1.getDefines)(chain)), {
|
|
49
|
+
helper_1.fs.existsSync(prebundleOutputDir) ? helper_1.fs.emptyDirSync(prebundleOutputDir) : helper_1.fs.ensureDirSync(prebundleOutputDir);
|
|
50
|
+
return helper_1.esbuild.build(Object.assign(Object.assign({}, customEsbuildConfig), { absWorkingDir: appPath, bundle: true, write: false, entryPoints: Array.from(flattenDeps.keys()), mainFields, format: 'esm', loader: (0, lodash_1.defaults)(customEsbuildConfig.loader, helper_1.defaultEsbuildLoader), define: Object.assign(Object.assign({}, (0, utils_1.getDefines)(chain)), {
|
|
53
51
|
// AMD 被 esbuild 转 ESM 后,是套着 ESM 外皮的 AMD 语法模块。
|
|
54
52
|
// Webpack HarmonyDetectionParserPlugin 会阻止 AMDDefineDependencyParserPlugin 对这些模块的处理。
|
|
55
53
|
// 导致这些模块报错(如 lodash)。目前的办法是把 define 置为 false,不支持 AMD 导出。
|
|
@@ -57,39 +55,39 @@ function bundle({ appPath, deps, chain, prebundleOutputDir, customEsbuildConfig
|
|
|
57
55
|
getEntryPlugin({
|
|
58
56
|
flattenDeps,
|
|
59
57
|
flatIdExports,
|
|
60
|
-
prebundleOutputDir
|
|
58
|
+
prebundleOutputDir,
|
|
61
59
|
}),
|
|
62
|
-
...customEsbuildConfig.plugins || [],
|
|
63
|
-
getSwcPlugin({ appPath, flatIdExports }, customSwcConfig)
|
|
60
|
+
...(customEsbuildConfig.plugins || []),
|
|
61
|
+
getSwcPlugin({ appPath, flatIdExports }, customSwcConfig),
|
|
64
62
|
] }));
|
|
65
63
|
});
|
|
66
64
|
}
|
|
67
65
|
exports.bundle = bundle;
|
|
68
|
-
function getEntryPlugin({ flattenDeps, flatIdExports, prebundleOutputDir }) {
|
|
66
|
+
function getEntryPlugin({ flattenDeps, flatIdExports, prebundleOutputDir, }) {
|
|
69
67
|
const resolve = (0, utils_1.getResolve)();
|
|
70
68
|
return {
|
|
71
69
|
name: 'entry',
|
|
72
70
|
setup(build) {
|
|
73
71
|
// assets
|
|
74
|
-
build.onResolve({ filter: constant_1.assetsRE }, (
|
|
75
|
-
const filePath = yield resolve(
|
|
76
|
-
const fileExt =
|
|
77
|
-
const fileBasename =
|
|
72
|
+
build.onResolve({ filter: constant_1.assetsRE }, (_a) => __awaiter(this, [_a], void 0, function* ({ path: id, importer }) {
|
|
73
|
+
const filePath = yield resolve(node_path_1.default.dirname(importer), id);
|
|
74
|
+
const fileExt = node_path_1.default.extname(filePath);
|
|
75
|
+
const fileBasename = node_path_1.default.basename(filePath, fileExt);
|
|
78
76
|
const fileContent = yield helper_1.fs.readFile(filePath);
|
|
79
|
-
const outputFile =
|
|
77
|
+
const outputFile = node_path_1.default.join(prebundleOutputDir, `${fileBasename}-${(0, helper_1.getHash)(filePath)}${fileExt}`);
|
|
80
78
|
yield helper_1.fs.writeFile(outputFile, fileContent);
|
|
81
|
-
return (0, helper_1.externalEsbuildModule)({ path: `./${
|
|
79
|
+
return (0, helper_1.externalEsbuildModule)({ path: `./${node_path_1.default.relative(prebundleOutputDir, outputFile)}` });
|
|
82
80
|
}));
|
|
83
|
-
build.onResolve({ filter: constant_1.moduleRE }, (
|
|
81
|
+
build.onResolve({ filter: constant_1.moduleRE }, (_b) => __awaiter(this, [_b], void 0, function* ({ path: id, importer }) {
|
|
84
82
|
// entry
|
|
85
83
|
if (!importer && flattenDeps.has(id)) {
|
|
86
84
|
return {
|
|
87
85
|
path: id,
|
|
88
|
-
namespace: 'entry'
|
|
86
|
+
namespace: 'entry',
|
|
89
87
|
};
|
|
90
88
|
}
|
|
91
89
|
try {
|
|
92
|
-
const resolvedPath = yield resolve(
|
|
90
|
+
const resolvedPath = yield resolve(node_path_1.default.dirname(importer), id);
|
|
93
91
|
if (typeof resolvedPath === 'string' && !constant_1.assetsRE.test(resolvedPath)) {
|
|
94
92
|
return { path: resolvedPath };
|
|
95
93
|
}
|
|
@@ -101,10 +99,10 @@ function getEntryPlugin({ flattenDeps, flatIdExports, prebundleOutputDir }) {
|
|
|
101
99
|
return (0, helper_1.externalEsbuildModule)({ path: id });
|
|
102
100
|
}
|
|
103
101
|
}));
|
|
104
|
-
build.onLoad({ filter: constant_1.moduleRE, namespace: 'entry' }, (
|
|
105
|
-
var
|
|
102
|
+
build.onLoad({ filter: constant_1.moduleRE, namespace: 'entry' }, (_c) => __awaiter(this, [_c], void 0, function* ({ path: id }) {
|
|
103
|
+
var _d;
|
|
106
104
|
let js = '';
|
|
107
|
-
const filePath = (
|
|
105
|
+
const filePath = (_d = flattenDeps.get(id)) === null || _d === void 0 ? void 0 : _d.replace(/\\/g, '\\\\');
|
|
108
106
|
const exportsData = flatIdExports.get(id);
|
|
109
107
|
const [importsList, exportsList] = exportsData;
|
|
110
108
|
const hasReExports = exportsData.hasReExports;
|
|
@@ -119,9 +117,7 @@ function getEntryPlugin({ flattenDeps, flatIdExports, prebundleOutputDir }) {
|
|
|
119
117
|
// export default
|
|
120
118
|
js += `import d from "${filePath}";export default d;`;
|
|
121
119
|
}
|
|
122
|
-
if (hasReExports ||
|
|
123
|
-
exportsList.length > 1 ||
|
|
124
|
-
exportsList[0] !== 'default') {
|
|
120
|
+
if (hasReExports || exportsList.length > 1 || exportsList[0] !== 'default') {
|
|
125
121
|
// export * from 'xx'
|
|
126
122
|
// export const xx
|
|
127
123
|
js += `export * from "${filePath}";`;
|
|
@@ -134,19 +130,19 @@ function getEntryPlugin({ flattenDeps, flatIdExports, prebundleOutputDir }) {
|
|
|
134
130
|
return {
|
|
135
131
|
loader: 'js',
|
|
136
132
|
resolveDir: process.cwd(),
|
|
137
|
-
contents: js
|
|
133
|
+
contents: js,
|
|
138
134
|
};
|
|
139
135
|
}));
|
|
140
|
-
}
|
|
136
|
+
},
|
|
141
137
|
};
|
|
142
138
|
}
|
|
143
|
-
function getSwcPlugin({ appPath, flatIdExports }, config) {
|
|
139
|
+
function getSwcPlugin({ appPath, flatIdExports, }, config) {
|
|
144
140
|
return {
|
|
145
141
|
name: 'swc-plugin',
|
|
146
142
|
setup(build) {
|
|
147
|
-
build.onEnd((
|
|
148
|
-
var
|
|
149
|
-
yield Promise.all(outputFiles.map((
|
|
143
|
+
build.onEnd((_a) => __awaiter(this, [_a], void 0, function* ({ outputFiles = [], metafile = {} }) {
|
|
144
|
+
var _b, _c;
|
|
145
|
+
yield Promise.all(outputFiles.map((_d) => __awaiter(this, [_d], void 0, function* ({ path, text }) {
|
|
150
146
|
if (!helper_1.REG_SCRIPTS.test(path))
|
|
151
147
|
return;
|
|
152
148
|
const { code } = helper_1.swc.transformSync(text, (0, lodash_1.defaults)(config, { jsc: { target: 'es2015' } }));
|
|
@@ -159,18 +155,15 @@ function getSwcPlugin({ appPath, flatIdExports }, config) {
|
|
|
159
155
|
const metaOutput = metafile.outputs;
|
|
160
156
|
for (const outputName in metaOutput) {
|
|
161
157
|
const output = metaOutput[outputName];
|
|
162
|
-
if (!((
|
|
158
|
+
if (!((_b = output.entryPoint) === null || _b === void 0 ? void 0 : _b.startsWith('entry:')))
|
|
163
159
|
continue;
|
|
164
160
|
const entry = output.entryPoint.replace(/^entry:/, '');
|
|
165
161
|
if (!flatIdExports.has(entry))
|
|
166
162
|
continue;
|
|
167
|
-
if (((
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const destPath = path_1.default.join(appPath, outputName.replace(/(\.js)$/, '.core$1'));
|
|
172
|
-
processAll.push(helper_1.fs.move(srcPath, destPath)
|
|
173
|
-
.then(() => helper_1.fs.writeFile(srcPath, `var m = require('./${path_1.default.basename(destPath)}');
|
|
163
|
+
if (((_c = flatIdExports.get(entry)) === null || _c === void 0 ? void 0 : _c.needInterop) && output.exports.length === 1 && output.exports[0] === 'default') {
|
|
164
|
+
const srcPath = node_path_1.default.join(appPath, outputName);
|
|
165
|
+
const destPath = node_path_1.default.join(appPath, outputName.replace(/(\.js)$/, '.core$1'));
|
|
166
|
+
processAll.push(helper_1.fs.move(srcPath, destPath).then(() => helper_1.fs.writeFile(srcPath, `var m = require('./${node_path_1.default.basename(destPath)}');
|
|
174
167
|
module.exports = m.default;
|
|
175
168
|
exports.default = module.exports;
|
|
176
169
|
`)));
|
|
@@ -178,7 +171,7 @@ function getSwcPlugin({ appPath, flatIdExports }, config) {
|
|
|
178
171
|
}
|
|
179
172
|
yield Promise.all(processAll);
|
|
180
173
|
}));
|
|
181
|
-
}
|
|
174
|
+
},
|
|
182
175
|
};
|
|
183
176
|
}
|
|
184
177
|
exports.getSwcPlugin = getSwcPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.js","sourceRoot":"","sources":["../../src/prebundle/bundle.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"bundle.js","sourceRoot":"","sources":["../../src/prebundle/bundle.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0DAA4B;AAE5B,2CASuB;AACvB,qDAA6C;AAC7C,mCAAiC;AAEjC,oCAA4D;AAC5D,gDAAsD;AAiBtD,6EAA6E;AAC7E,yEAAyE;AACzE,kCAAkC;AAClC,wCAAwC;AACxC,4EAA4E;AAC5E,WAAW;AACX,SAAsB,MAAM;yDAAC,EAC3B,OAAO,EACP,IAAI,EACJ,KAAK,EACL,kBAAkB,EAClB,mBAAmB,GAAG,EAAE,EACxB,eAAe,GAAG,EAAE,EACpB,UAAU,GAAG,CAAC,GAAG,0BAAiB,CAAC,EACtB;QACb,MAAM,sBAAI,CAAA;QAEV,MAAM,WAAW,GAAkB,IAAI,GAAG,EAAE,CAAA;QAC5C,MAAM,aAAa,GAAG,IAAI,GAAG,EAAuB,CAAA;QAEpD,KAAK,MAAM,CAAC,EA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C,0CAAE,WAAW,KAAI,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC;wBAC5G,MAAM,OAAO,GAAG,mBAAI,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;wBAC9C,MAAM,QAAQ,GAAG,mBAAI,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAA;wBAE7E,UAAU,CAAC,IAAI,CACb,WAAE,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CACnC,WAAE,CAAC,SAAS,CACV,OAAO,EACP,sBAAsB,mBAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;;;mBAG5C,CACF,CACF,CACF,CAAA;oBACH,CAAC;gBACH,CAAC;gBAED,MAAM,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;YAC/B,CAAC,CAAA,CAAC,CAAA;QACJ,CAAC;KACF,CAAA;AACH,CAAC;AA1DD,oCA0DC"}
|
|
@@ -19,6 +19,9 @@ export interface IPrebundleConfig {
|
|
|
19
19
|
platformType: PLATFORM_TYPE;
|
|
20
20
|
sourceRoot: string;
|
|
21
21
|
isBuildPlugin?: boolean;
|
|
22
|
+
alias?: Record<string, any>;
|
|
23
|
+
defineConstants?: Record<string, any>;
|
|
24
|
+
modifyAppConfig?: (appConfig: any) => Promise<any>;
|
|
22
25
|
}
|
|
23
26
|
type TMode = 'production' | 'development' | 'none';
|
|
24
27
|
export default class BasePrebundle<T extends IPrebundleConfig = IPrebundleConfig> {
|
|
@@ -33,6 +36,7 @@ export default class BasePrebundle<T extends IPrebundleConfig = IPrebundleConfig
|
|
|
33
36
|
env: string;
|
|
34
37
|
mode: TMode;
|
|
35
38
|
platformType: PLATFORM_TYPE;
|
|
39
|
+
mainFields: string[];
|
|
36
40
|
prebundleCacheDir: string;
|
|
37
41
|
remoteCacheDir: string;
|
|
38
42
|
metadataPath: string;
|
|
@@ -48,7 +52,7 @@ export default class BasePrebundle<T extends IPrebundleConfig = IPrebundleConfig
|
|
|
48
52
|
get entryPath(): string;
|
|
49
53
|
parseEntries(entry?: EntryObject): string[];
|
|
50
54
|
/** 找出所有 webpack entry */
|
|
51
|
-
getEntries(appJsPath: string): string[]
|
|
55
|
+
getEntries(appJsPath: string): Promise<string[]>;
|
|
52
56
|
setDeps(entries: string[], include?: string[], exclude?: string[]): Promise<void>;
|
|
53
57
|
bundle(): any;
|
|
54
58
|
handleBundleError(errors?: esbuild.Message[]): any;
|
package/dist/prebundle/index.js
CHANGED
|
@@ -12,9 +12,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
16
|
+
const node_perf_hooks_1 = require("node:perf_hooks");
|
|
15
17
|
const helper_1 = require("@tarojs/helper");
|
|
16
|
-
const path_1 = __importDefault(require("path"));
|
|
17
|
-
const perf_hooks_1 = require("perf_hooks");
|
|
18
18
|
const webpack_1 = __importDefault(require("webpack"));
|
|
19
19
|
const utils_1 = require("../utils");
|
|
20
20
|
const constant_1 = require("../utils/constant");
|
|
@@ -39,13 +39,14 @@ class BasePrebundle {
|
|
|
39
39
|
this.customSwcConfig = swc;
|
|
40
40
|
this.env = env;
|
|
41
41
|
this.platformType = platformType;
|
|
42
|
-
this.mode = ['production', 'development', 'none'].find(e => e === env)
|
|
43
|
-
|
|
44
|
-
this.prebundleCacheDir =
|
|
45
|
-
this.remoteCacheDir =
|
|
46
|
-
this.metadataPath =
|
|
42
|
+
this.mode = ['production', 'development', 'none'].find(e => e === env) ||
|
|
43
|
+
(!isWatch || process.env.NODE_ENV === 'production' ? 'production' : 'development');
|
|
44
|
+
this.prebundleCacheDir = node_path_1.default.resolve(cacheDir, './prebundle');
|
|
45
|
+
this.remoteCacheDir = node_path_1.default.resolve(cacheDir, './remote');
|
|
46
|
+
this.metadataPath = node_path_1.default.join(cacheDir, 'metadata.json');
|
|
47
47
|
this.metadata = {};
|
|
48
48
|
this.preMetadata = {};
|
|
49
|
+
this.mainFields = [...helper_1.defaultMainFields];
|
|
49
50
|
this.measure = (0, utils_1.getMeasure)(this.option.timings);
|
|
50
51
|
try {
|
|
51
52
|
if (force !== true) {
|
|
@@ -100,21 +101,26 @@ class BasePrebundle {
|
|
|
100
101
|
}
|
|
101
102
|
/** 找出所有 webpack entry */
|
|
102
103
|
getEntries(appJsPath) {
|
|
103
|
-
const { appPath, sourceRoot } = this.config;
|
|
104
|
-
const entries = this.parseEntries(this.config.entry);
|
|
105
|
-
const appConfigPath = (0, helper_1.resolveMainFilePath)(`${appJsPath.replace(path_1.default.extname(appJsPath), '')}.config`);
|
|
106
|
-
if (helper_1.fs.existsSync(appConfigPath)) {
|
|
107
|
-
const appConfig = (0, helper_1.readConfig)(appConfigPath);
|
|
108
|
-
appConfig.pages.forEach((page) => {
|
|
109
|
-
const pageJsPath = (0, helper_1.resolveMainFilePath)(path_1.default.join(appPath, sourceRoot, page));
|
|
110
|
-
entries.push(pageJsPath);
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
return entries;
|
|
114
|
-
}
|
|
115
|
-
setDeps(entries, include = [], exclude = []) {
|
|
116
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
-
const
|
|
105
|
+
const { appPath, sourceRoot } = this.config;
|
|
106
|
+
const entries = this.parseEntries(this.config.entry);
|
|
107
|
+
const appConfigPath = (0, helper_1.resolveMainFilePath)(`${appJsPath.replace(node_path_1.default.extname(appJsPath), '')}.config`);
|
|
108
|
+
if (helper_1.fs.existsSync(appConfigPath)) {
|
|
109
|
+
const appConfig = (0, helper_1.readConfig)(appConfigPath, this.config);
|
|
110
|
+
if (typeof this.config.modifyAppConfig === 'function') {
|
|
111
|
+
yield this.config.modifyAppConfig(appConfig);
|
|
112
|
+
}
|
|
113
|
+
appConfig.pages.forEach((page) => {
|
|
114
|
+
const pageJsPath = (0, helper_1.resolveMainFilePath)(node_path_1.default.join(appPath, sourceRoot, page));
|
|
115
|
+
entries.push(pageJsPath);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return entries;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
setDeps(entries_1) {
|
|
122
|
+
return __awaiter(this, arguments, void 0, function* (entries, include = [], exclude = []) {
|
|
123
|
+
const SCAN_START = node_perf_hooks_1.performance.now();
|
|
118
124
|
yield (0, scanImports_1.scanImports)({
|
|
119
125
|
appPath: this.appPath,
|
|
120
126
|
chain: this.chain,
|
|
@@ -122,6 +128,7 @@ class BasePrebundle {
|
|
|
122
128
|
entries,
|
|
123
129
|
include,
|
|
124
130
|
exclude,
|
|
131
|
+
mainFields: this.mainFields,
|
|
125
132
|
}, this.deps);
|
|
126
133
|
this.deps.size &&
|
|
127
134
|
console.log(helper_1.chalk.cyan('Prebundle dependencies: \n', ...Array.from(this.deps.keys()).sort(utils_1.sortDeps).map(dep => ` ${dep}\n`)));
|
|
@@ -130,7 +137,7 @@ class BasePrebundle {
|
|
|
130
137
|
}
|
|
131
138
|
bundle() {
|
|
132
139
|
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
-
const PREBUNDLE_START =
|
|
140
|
+
const PREBUNDLE_START = node_perf_hooks_1.performance.now();
|
|
134
141
|
this.metadata.bundleHash = yield (0, utils_1.getBundleHash)(this.appPath, this.deps, this.chain, this.cacheDir);
|
|
135
142
|
if (this.preMetadata.bundleHash !== this.metadata.bundleHash) {
|
|
136
143
|
this.isUseCache = false;
|
|
@@ -142,6 +149,7 @@ class BasePrebundle {
|
|
|
142
149
|
prebundleOutputDir: this.prebundleCacheDir,
|
|
143
150
|
customEsbuildConfig: this.customEsbuildConfig,
|
|
144
151
|
customSwcConfig: this.customSwcConfig,
|
|
152
|
+
mainFields: this.mainFields,
|
|
145
153
|
});
|
|
146
154
|
}
|
|
147
155
|
catch (result) {
|
|
@@ -197,7 +205,7 @@ class BasePrebundle {
|
|
|
197
205
|
const skipPlugins = ['MiniSplitChunksPlugin', 'TaroMiniPlugin', 'TaroH5Plugin', 'ProvidePlugin', 'CopyPlugin', 'HtmlWebpackPlugin'];
|
|
198
206
|
delete inherit.devServer;
|
|
199
207
|
(_a = inherit.optimization) === null || _a === void 0 ? true : delete _a.splitChunks;
|
|
200
|
-
inherit.plugins = (_b = inherit.plugins) === null || _b === void 0 ? void 0 : _b.filter(p => { var _a; return !skipPlugins.includes((_a = p === null || p === void 0 ? void 0 : p.constructor) === null || _a === void 0 ? void 0 : _a.name); });
|
|
208
|
+
inherit.plugins = (_b = inherit.plugins) === null || _b === void 0 ? void 0 : _b.filter(p => { var _a; return !skipPlugins.includes(((_a = p === null || p === void 0 ? void 0 : p.constructor) === null || _a === void 0 ? void 0 : _a.name) || ''); });
|
|
201
209
|
if ((_c = inherit.module) === null || _c === void 0 ? void 0 : _c.rules) {
|
|
202
210
|
inherit.module.rules = inherit.module.rules.filter((rule) => { var _a; return ((_a = rule.test) === null || _a === void 0 ? void 0 : _a.toString()) !== helper_1.REG_SCRIPTS.toString(); });
|
|
203
211
|
}
|