xhs-mp-compiler-cli 2.0.6 → 2.0.7-beta.0
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.
|
@@ -51,9 +51,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
51
51
|
console.log(`资源编译:${data.resource}`);
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
|
-
projectPacker.watch({
|
|
55
|
-
scene: 'watch',
|
|
56
|
-
}, (err, stats) => {
|
|
54
|
+
projectPacker.watch({}, (err, stats) => {
|
|
57
55
|
console.log(stats.toString({ warnings: true, errors: true, all: false }));
|
|
58
56
|
});
|
|
59
57
|
});
|
package/dist/compiler.js
CHANGED
|
@@ -222,7 +222,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
222
222
|
// }
|
|
223
223
|
this.pending = true;
|
|
224
224
|
this.emit('buildStart');
|
|
225
|
-
yield this.call('runTask', Object.assign({
|
|
225
|
+
yield this.call('runTask', Object.assign({ action: 'dev' }, opts));
|
|
226
226
|
this.watching = true;
|
|
227
227
|
this.emit('buildSuccess');
|
|
228
228
|
}
|
|
@@ -311,7 +311,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
311
311
|
};
|
|
312
312
|
try {
|
|
313
313
|
this.emit('buildStart');
|
|
314
|
-
yield this.call('runTask', Object.assign({
|
|
314
|
+
yield this.call('runTask', Object.assign({ action: 'dev' }, opts));
|
|
315
315
|
this.watching = true;
|
|
316
316
|
(_c = this.pendingTask.resolve) === null || _c === void 0 ? void 0 : _c.forEach(fn => fn());
|
|
317
317
|
this.emit('buildSuccess');
|
|
@@ -335,7 +335,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
335
335
|
}
|
|
336
336
|
try {
|
|
337
337
|
this.emit('buildStart');
|
|
338
|
-
yield this.call('runTask', Object.assign({ action: 'dev'
|
|
338
|
+
yield this.call('runTask', Object.assign({ action: 'dev' }, opts));
|
|
339
339
|
this.emit('buildSuccess');
|
|
340
340
|
}
|
|
341
341
|
catch (error) {
|
package/dist/compilerImpl.js
CHANGED
|
@@ -94,9 +94,7 @@ const handlers = {
|
|
|
94
94
|
console.log('[compiler] create compiler');
|
|
95
95
|
createProjectPacker(data);
|
|
96
96
|
sendBuildInfoMessage('run-watch', '执行编译');
|
|
97
|
-
const { err, stats } = (yield projectPacker.watch({
|
|
98
|
-
scene: data.scene
|
|
99
|
-
}, (err, stats) => {
|
|
97
|
+
const { err, stats } = (yield projectPacker.watch({}, (err, stats) => {
|
|
100
98
|
var _a;
|
|
101
99
|
console.log('[compiler] file change...', err, stats);
|
|
102
100
|
// 修改文件时构建
|
|
@@ -59,9 +59,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
59
59
|
this.watcher.close(() => { });
|
|
60
60
|
this.watcher = null;
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
this.hadWatch = false;
|
|
64
|
-
}
|
|
62
|
+
this.hadWatch = false;
|
|
65
63
|
this.watcher = this.compiler.watch(Object.assign(Object.assign({}, watchOptions), config), (err, stats) => {
|
|
66
64
|
if (!this.hadWatch) {
|
|
67
65
|
this.hadWatch = true;
|
|
@@ -113,12 +113,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
113
113
|
`;
|
|
114
114
|
};
|
|
115
115
|
function genServiceLoderScript(project, context, opts) {
|
|
116
|
+
var _a;
|
|
116
117
|
const { appJSON, projectMiniprogramPath, jsonDependencies } = project;
|
|
117
118
|
const { pkg, root } = opts;
|
|
118
119
|
const modules = [];
|
|
119
|
-
let
|
|
120
|
+
let moduleName = 'XHS_SERVICE';
|
|
120
121
|
if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG) {
|
|
121
|
-
|
|
122
|
+
moduleName = `XHS_SERVICE_${root}`;
|
|
122
123
|
}
|
|
123
124
|
for (const file of jsonDependencies) {
|
|
124
125
|
context.addDependency(file);
|
|
@@ -126,20 +127,22 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
126
127
|
const addAppJs = () => {
|
|
127
128
|
if (fs_extra_1.default.existsSync(`${projectMiniprogramPath}/app.js`) ||
|
|
128
129
|
fs_extra_1.default.existsSync(`${projectMiniprogramPath}/app.ts`)) {
|
|
129
|
-
|
|
130
|
-
|
|
130
|
+
const loadAppJs = 'loadAppJs';
|
|
131
|
+
modules.unshift(`;const ${loadAppJs} = () => require('${(0, xhs_mp_compiler_utils_1.toUnixPath)(`${projectMiniprogramPath}/app`)}')`, `;globalThis['${moduleName}'].default['app'] = globalThis.xhsLazyAppJs ? ${loadAppJs} : ${loadAppJs}()`);
|
|
131
132
|
}
|
|
132
133
|
};
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const
|
|
134
|
+
// 添加 page 或者 component 的 js 资源
|
|
135
|
+
const addJSResource = (shortPath) => {
|
|
136
|
+
const resourcePath = (0, xhs_mp_compiler_utils_1.toUnixPath)(`${projectMiniprogramPath}/${shortPath}`);
|
|
137
|
+
const content = `;globalThis['${moduleName}'].default['${shortPath}'] = () => require('${resourcePath}')`;
|
|
136
138
|
modules.push(content);
|
|
137
139
|
};
|
|
138
140
|
// 主包
|
|
139
141
|
if (pkg === xhs_mp_pack_1.CONSTANTS.MAIN_PKG) {
|
|
140
142
|
addAppJs();
|
|
141
143
|
for (const page of appJSON.pages) {
|
|
142
|
-
|
|
144
|
+
// 注意 经过转换后的 page 全部处理为 { path: string } 对象格式
|
|
145
|
+
addJSResource(page.path);
|
|
143
146
|
}
|
|
144
147
|
}
|
|
145
148
|
// 分包
|
|
@@ -147,30 +150,35 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
147
150
|
for (const subPackage of appJSON.subPackages) {
|
|
148
151
|
if (subPackage.root === root) {
|
|
149
152
|
for (const page of subPackage.pages) {
|
|
150
|
-
|
|
153
|
+
addJSResource(page.path);
|
|
151
154
|
}
|
|
152
155
|
}
|
|
153
156
|
}
|
|
154
157
|
}
|
|
155
158
|
Object.keys(appJSON.componentsMap).forEach(compPath => {
|
|
156
|
-
const resourcePath = (0, xhs_mp_compiler_utils_1.toUnixPath)(`${projectMiniprogramPath}/${compPath}`);
|
|
157
|
-
const content = `;globalThis['${name}'].default['${compPath}'] = () => require('${resourcePath}')`;
|
|
158
159
|
if (pkg === xhs_mp_pack_1.CONSTANTS.MAIN_PKG) {
|
|
159
160
|
const subPackageRoots = appJSON.subPackages.map(pkg => pkg.root);
|
|
160
161
|
if (subPackageRoots.every(root => !compPath.startsWith(`${root}/`))) {
|
|
161
|
-
|
|
162
|
+
addJSResource(compPath);
|
|
162
163
|
}
|
|
163
164
|
}
|
|
164
165
|
if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG) {
|
|
165
166
|
if (compPath.startsWith(`${root}/`)) {
|
|
166
|
-
|
|
167
|
+
addJSResource(compPath);
|
|
167
168
|
}
|
|
168
169
|
}
|
|
169
170
|
});
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
171
|
+
let injectAppJson = '';
|
|
172
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.MAIN_PKG ||
|
|
173
|
+
(pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG && ((_a = appJSON.subPackages.find(sub => sub.root === root)) === null || _a === void 0 ? void 0 : _a.independent))) {
|
|
174
|
+
// 非独立分包加载必须依赖主包先加载,因此没必要进行__MP_APP_JSON__重复注入
|
|
175
|
+
injectAppJson = `;globalThis['__MP_APP_JSON__'] = ${JSON.stringify(appJSON)}`;
|
|
176
|
+
}
|
|
177
|
+
return [
|
|
178
|
+
injectAppJson,
|
|
179
|
+
`;(globalThis['${moduleName}'] || (globalThis['${moduleName}'] = { default: {} }))`,
|
|
180
|
+
...modules
|
|
181
|
+
].filter(Boolean).join('\n');
|
|
174
182
|
}
|
|
175
183
|
function genSketchLoaderScript(project, context, opts) {
|
|
176
184
|
const { projectMiniprogramPath } = project;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xhs-mp-compiler-cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7-beta.0",
|
|
4
4
|
"description": "xhs mp command tool.",
|
|
5
5
|
"preferGlobal": true,
|
|
6
6
|
"category": "esm",
|
|
@@ -88,18 +88,18 @@
|
|
|
88
88
|
"webpack-chain": "^6.5.1",
|
|
89
89
|
"webpack-sources": "^3.2.2",
|
|
90
90
|
"xhs-mp-workerpool": "^9.1.3",
|
|
91
|
-
"xhs-mp-ml-loader": "2.0.
|
|
92
|
-
"xhs-mp-compiler-utils": "2.0.
|
|
93
|
-
"xhs-mp-pack": "2.0.
|
|
94
|
-
"xhs-mp-project": "2.0.
|
|
95
|
-
"xhs-mp-shared": "2.0.
|
|
96
|
-
"xhs-mp-shared-fs": "2.0.
|
|
97
|
-
"xhs-mp-sjs-loader": "2.0.
|
|
98
|
-
"xhs-mp-sketch-loader": "2.0.
|
|
91
|
+
"xhs-mp-ml-loader": "2.0.7-beta.0",
|
|
92
|
+
"xhs-mp-compiler-utils": "2.0.7-beta.0",
|
|
93
|
+
"xhs-mp-pack": "2.0.7-beta.0",
|
|
94
|
+
"xhs-mp-project": "2.0.7-beta.0",
|
|
95
|
+
"xhs-mp-shared": "2.0.7-beta.0",
|
|
96
|
+
"xhs-mp-shared-fs": "2.0.7-beta.0",
|
|
97
|
+
"xhs-mp-sjs-loader": "2.0.7-beta.0",
|
|
98
|
+
"xhs-mp-sketch-loader": "2.0.7-beta.0",
|
|
99
99
|
"yauzl": "^2.10.0"
|
|
100
100
|
},
|
|
101
101
|
"peerDependencies": {
|
|
102
|
-
"xhs-mp-ml-parser": "2.0.
|
|
102
|
+
"xhs-mp-ml-parser": "2.0.7-beta.0"
|
|
103
103
|
},
|
|
104
104
|
"devDependencies": {
|
|
105
105
|
"@types/babel__generator": "7.6.3",
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"typescript": "5.1.6",
|
|
124
124
|
"vue3-jest": "27.0.0-alpha.2",
|
|
125
125
|
"webpack-dev-server": "4.0.0-beta.3",
|
|
126
|
-
"xhs-mp-ml-parser": "2.0.
|
|
126
|
+
"xhs-mp-ml-parser": "2.0.7-beta.0"
|
|
127
127
|
},
|
|
128
128
|
"scripts": {
|
|
129
129
|
"version": "formula changelog && git add .",
|