xhs-mp-compiler-cli 1.0.2-beta.0 → 1.0.2
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/bin/xhs-mp-cli-build.d.ts +2 -0
- package/dist/bin/xhs-mp-cli-build.js +40 -0
- package/dist/bin/xhs-mp-cli-dev.d.ts +2 -0
- package/dist/bin/xhs-mp-cli-dev.js +81 -0
- package/dist/bin/xhs-mp-cli.d.ts +2 -0
- package/dist/bin/xhs-mp-cli.js +16 -0
- package/dist/build/index.d.ts +3 -0
- package/dist/build/index.js +22 -0
- package/dist/dev-server/index.d.ts +3 -0
- package/dist/dev-server/index.js +62 -0
- package/dist/dev-server/lib/ensurePort.d.ts +2 -0
- package/dist/dev-server/lib/ensurePort.js +32 -0
- package/dist/dev-server/lib/openBrowser.d.ts +2 -0
- package/dist/dev-server/lib/openBrowser.js +23 -0
- package/dist/dev-server/lib/openChrome.applescript +78 -0
- package/dist/globalData/SjsModule.d.ts +32 -0
- package/dist/globalData/SjsModule.js +34 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +114 -0
- package/dist/types/index.d.ts +106 -0
- package/dist/types/index.js +13 -0
- package/dist/utils/asyncWebpack.d.ts +3 -0
- package/dist/utils/asyncWebpack.js +38 -0
- package/dist/utils/combineExtJson.d.ts +3 -0
- package/dist/utils/combineExtJson.js +74 -0
- package/dist/utils/common.d.ts +7 -0
- package/dist/utils/common.js +35 -0
- package/dist/utils/depenedHelper.d.ts +31 -0
- package/dist/utils/depenedHelper.js +89 -0
- package/dist/utils/getCssSuffixName.d.ts +1 -0
- package/dist/utils/getCssSuffixName.js +9 -0
- package/dist/utils/getMlSuffixName.d.ts +1 -0
- package/dist/utils/getMlSuffixName.js +6 -0
- package/dist/utils/getPrefixName.d.ts +1 -0
- package/dist/utils/getPrefixName.js +6 -0
- package/dist/utils/projectConfig.d.ts +1 -0
- package/dist/utils/projectConfig.js +20 -0
- package/dist/utils/transformAppJson.d.ts +16 -0
- package/dist/utils/transformAppJson.js +199 -0
- package/dist/utils/validateAppJson.d.ts +4 -0
- package/dist/utils/validateAppJson.js +111 -0
- package/dist/webpack-config/index.d.ts +4 -0
- package/dist/webpack-config/index.js +41 -0
- package/dist/webpack-config/lib/const.d.ts +13 -0
- package/dist/webpack-config/lib/const.js +15 -0
- package/dist/webpack-config/lib/css.d.ts +2 -0
- package/dist/webpack-config/lib/css.js +41 -0
- package/dist/webpack-config/lib/postcssRpx2Vw.d.ts +12 -0
- package/dist/webpack-config/lib/postcssRpx2Vw.js +35 -0
- package/dist/webpack-config/lib/tagTransformMap.d.ts +35 -0
- package/dist/webpack-config/lib/tagTransformMap.js +38 -0
- package/dist/webpack-config/lib/utils.d.ts +5 -0
- package/dist/webpack-config/lib/utils.js +37 -0
- package/dist/webpack-config/loaders/component-entry-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/component-entry-loader.js +31 -0
- package/dist/webpack-config/loaders/component-entry-requirements-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/component-entry-requirements-loader.js +24 -0
- package/dist/webpack-config/loaders/mini-style-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/mini-style-loader.js +69 -0
- package/dist/webpack-config/loaders/render-entry-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/render-entry-loader.js +50 -0
- package/dist/webpack-config/loaders/service-entry-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/service-entry-loader.js +51 -0
- package/dist/webpack-config/loaders/sjs-loader/index.d.ts +12 -0
- package/dist/webpack-config/loaders/sjs-loader/index.js +609 -0
- package/dist/webpack-config/loaders/sjs-loader/scope.d.ts +36 -0
- package/dist/webpack-config/loaders/sjs-loader/scope.js +122 -0
- package/dist/webpack-config/loaders/sjs-loader/tranform.d.ts +2 -0
- package/dist/webpack-config/loaders/sjs-loader/tranform.js +31 -0
- package/dist/webpack-config/loaders/utils.d.ts +13 -0
- package/dist/webpack-config/loaders/utils.js +41 -0
- package/dist/webpack-config/loaders/wxss-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/wxss-loader.js +76 -0
- package/dist/webpack-config/plugins/VueLoaderPlugin.d.ts +19 -0
- package/dist/webpack-config/plugins/VueLoaderPlugin.js +205 -0
- package/dist/webpack-config/plugins/XhsMpErrorTransformPlugin.d.ts +8 -0
- package/dist/webpack-config/plugins/XhsMpErrorTransformPlugin.js +40 -0
- package/dist/webpack-config/plugins/XhsMpJsonPlugin.d.ts +36 -0
- package/dist/webpack-config/plugins/XhsMpJsonPlugin.js +71 -0
- package/dist/webpack-config/presets/babel.d.ts +8 -0
- package/dist/webpack-config/presets/babel.js +57 -0
- package/dist/webpack-config/presets/common.d.ts +4 -0
- package/dist/webpack-config/presets/common.js +40 -0
- package/dist/webpack-config/presets/mp/MpEntryPlugin.d.ts +23 -0
- package/dist/webpack-config/presets/mp/MpEntryPlugin.js +87 -0
- package/dist/webpack-config/presets/mp/index.d.ts +4 -0
- package/dist/webpack-config/presets/mp/index.js +48 -0
- package/dist/webpack-config/presets/prod.d.ts +4 -0
- package/dist/webpack-config/presets/prod.js +83 -0
- package/dist/webpack-config/presets/render/ComponentEntryPlugin.d.ts +18 -0
- package/dist/webpack-config/presets/render/ComponentEntryPlugin.js +77 -0
- package/dist/webpack-config/presets/render/RenderChunkPlugin.d.ts +5 -0
- package/dist/webpack-config/presets/render/RenderChunkPlugin.js +50 -0
- package/dist/webpack-config/presets/render/RenderEntryPlugin.d.ts +14 -0
- package/dist/webpack-config/presets/render/RenderEntryPlugin.js +42 -0
- package/dist/webpack-config/presets/render/SjsEntryPlugin.d.ts +31 -0
- package/dist/webpack-config/presets/render/SjsEntryPlugin.js +160 -0
- package/dist/webpack-config/presets/render/index.d.ts +4 -0
- package/dist/webpack-config/presets/render/index.js +62 -0
- package/dist/webpack-config/presets/service/ServiceEntryPlugin.d.ts +8 -0
- package/dist/webpack-config/presets/service/ServiceEntryPlugin.js +36 -0
- package/dist/webpack-config/presets/service/XhsMpServiceChunkPlugin.d.ts +6 -0
- package/dist/webpack-config/presets/service/XhsMpServiceChunkPlugin.js +46 -0
- package/dist/webpack-config/presets/service/XhsResolveLimitPlugin.d.ts +8 -0
- package/dist/webpack-config/presets/service/XhsResolveLimitPlugin.js +65 -0
- package/dist/webpack-config/presets/service/XhsV2AssetsPlugin.d.ts +5 -0
- package/dist/webpack-config/presets/service/XhsV2AssetsPlugin.js +27 -0
- package/dist/webpack-config/presets/service/index.d.ts +4 -0
- package/dist/webpack-config/presets/service/index.js +39 -0
- package/package.json +2 -2
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const getMlSuffixName_1 = __importDefault(require("../../utils/getMlSuffixName"));
|
|
8
|
+
const common_1 = require("../../utils/common");
|
|
9
|
+
function entryLoader() {
|
|
10
|
+
const { miniprogramDir, jsonDependencies } = this._compiler.xhsData;
|
|
11
|
+
const { compPath } = this.getOptions();
|
|
12
|
+
const { pkg, root } = this.getOptions();
|
|
13
|
+
for (const file of jsonDependencies) {
|
|
14
|
+
this.addDependency(file);
|
|
15
|
+
}
|
|
16
|
+
let name = 'XHS_COMPONENTS';
|
|
17
|
+
if (pkg === 'sub') {
|
|
18
|
+
name = `XHS_COMPONENTS_${root}`;
|
|
19
|
+
}
|
|
20
|
+
return `
|
|
21
|
+
;(globalThis['${name}'] || (globalThis['${name}'] = { default: {} })).default['${compPath}'] = () => require('${(0, common_1.unixJoin)(miniprogramDir, `${compPath}.${(0, getMlSuffixName_1.default)()}`)}')
|
|
22
|
+
`;
|
|
23
|
+
}
|
|
24
|
+
module.exports = entryLoader;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
const webpack_sources_1 = require("webpack-sources");
|
|
16
|
+
const cssnano_1 = __importDefault(require("cssnano"));
|
|
17
|
+
const common_1 = require("../../utils/common");
|
|
18
|
+
const CSS_MINIMIZER_OPTIONS = {
|
|
19
|
+
preset: ['default', { normalizeUrl: false, calc: false }],
|
|
20
|
+
};
|
|
21
|
+
const minify = (source, name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
const postcssOptions = {
|
|
24
|
+
to: name,
|
|
25
|
+
from: name,
|
|
26
|
+
};
|
|
27
|
+
try {
|
|
28
|
+
const result = yield cssnano_1.default.process(source, postcssOptions, CSS_MINIMIZER_OPTIONS);
|
|
29
|
+
return {
|
|
30
|
+
code: result.css,
|
|
31
|
+
warnings: (_b = (_a = result.warnings()) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, i => i.toString())
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
return {
|
|
36
|
+
code: source,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
function miniStyleLoader(source) {
|
|
41
|
+
var _a;
|
|
42
|
+
const callback = this.async();
|
|
43
|
+
const { resourcePath } = this;
|
|
44
|
+
const { miniprogramDir, enableVDom, enableV1, enableV2, independent } = this.getOptions();
|
|
45
|
+
const shortPath = (0, common_1.getShortPath)(miniprogramDir, resourcePath).replace(/\.wxss$/, ".css");
|
|
46
|
+
source = (_a = source === null || source === void 0 ? void 0 : source.trim) === null || _a === void 0 ? void 0 : _a.call(source);
|
|
47
|
+
function result(code) {
|
|
48
|
+
if (!code) {
|
|
49
|
+
return `export default void 0;`;
|
|
50
|
+
}
|
|
51
|
+
// 判断浏览器环境,注入css添加逻辑
|
|
52
|
+
return new webpack_sources_1.RawSource(`globalThis.__XHS_IS_WEBVIEW && globalThis.__XHS_APPEND_CSS(${JSON.stringify(code)});`
|
|
53
|
+
+
|
|
54
|
+
`export default ${JSON.stringify(shortPath)};`).source();
|
|
55
|
+
}
|
|
56
|
+
// 压缩css
|
|
57
|
+
minify(source, shortPath)
|
|
58
|
+
.then(({ code, warnings }) => {
|
|
59
|
+
// vdom架构下emit出一份css文件
|
|
60
|
+
if ((independent || enableVDom) && code) {
|
|
61
|
+
enableV1 && this.emitFile(`v1/${shortPath}`, code);
|
|
62
|
+
enableV2 && this.emitFile(`v2/${shortPath}`, code);
|
|
63
|
+
}
|
|
64
|
+
callback(null, result(code));
|
|
65
|
+
}).catch(error => {
|
|
66
|
+
callback(error);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
module.exports = miniStyleLoader;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_extra_1 = require("fs-extra");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
const getMlSuffixName_1 = __importDefault(require("../../utils/getMlSuffixName"));
|
|
9
|
+
const depenedHelper_1 = require("../../utils/depenedHelper");
|
|
10
|
+
const common_1 = require("../../utils/common");
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
function entryLoader() {
|
|
13
|
+
const { miniprogramDir, appJSON, jsonDependencies } = this._compiler.xhsData;
|
|
14
|
+
const { mode, path } = this.getOptions();
|
|
15
|
+
for (const file of jsonDependencies) {
|
|
16
|
+
this.addDependency(file);
|
|
17
|
+
}
|
|
18
|
+
const appCssPath = (0, common_1.unixResolve)(miniprogramDir, 'app.css');
|
|
19
|
+
const appCssExist = (0, fs_extra_1.existsSync)(appCssPath);
|
|
20
|
+
const absolutePath = (0, common_1.unixResolve)(miniprogramDir, `${path}.${(0, getMlSuffixName_1.default)()}`);
|
|
21
|
+
const subPackage = (appJSON.subPackages || []).find(subPack => !!subPack.pages.find(page => page.path === path));
|
|
22
|
+
const enableLazyCodeLoading = mode === 'v2';
|
|
23
|
+
// 资源文件
|
|
24
|
+
const resources = (0, utils_1.getResourceUris)({ appCssExist, subPackage, enableLazyCodeLoading });
|
|
25
|
+
// 开启了按需注入,注入依赖组件
|
|
26
|
+
if (enableLazyCodeLoading) {
|
|
27
|
+
const isIndependent = (subPackage === null || subPackage === void 0 ? void 0 : subPackage.independent) || false;
|
|
28
|
+
const enableSubPackage = (0, depenedHelper_1.shouldEnableSubPackage)(appJSON);
|
|
29
|
+
const dependsTree = (0, depenedHelper_1.getPageDependComponentPaths)(path, appJSON, isIndependent, enableSubPackage);
|
|
30
|
+
const subPackagesPrefix = (appJSON.subPackages || []).map(sub => sub.root);
|
|
31
|
+
const depends = [];
|
|
32
|
+
for (let i = 0; i < dependsTree.length; i++) {
|
|
33
|
+
let uri = dependsTree[i];
|
|
34
|
+
const subRoot = subPackagesPrefix.find(subRoot => uri.startsWith(`${subRoot}/`));
|
|
35
|
+
if (subRoot) {
|
|
36
|
+
uri = `${subRoot}/${uri}`;
|
|
37
|
+
}
|
|
38
|
+
depends.push(uri);
|
|
39
|
+
}
|
|
40
|
+
return `
|
|
41
|
+
import Component from '${absolutePath}';
|
|
42
|
+
globalThis.__render.mount(Component, '${path}', ${JSON.stringify(resources)}, ${JSON.stringify(depends)})
|
|
43
|
+
`;
|
|
44
|
+
}
|
|
45
|
+
return `
|
|
46
|
+
import Component from '${absolutePath}';
|
|
47
|
+
globalThis.__render.mount(Component, '${path}', ${JSON.stringify(resources)})
|
|
48
|
+
`;
|
|
49
|
+
}
|
|
50
|
+
module.exports = entryLoader;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
const fs_extra_1 = require("fs-extra");
|
|
5
|
+
const common_1 = require("../../utils/common");
|
|
6
|
+
function entryLoader() {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
const { appJSON, miniprogramDir, jsonDependencies } = this._compiler.xhsData;
|
|
9
|
+
const { pkg, root } = this.getOptions();
|
|
10
|
+
const entries = [];
|
|
11
|
+
for (const file of jsonDependencies) {
|
|
12
|
+
this.addDependency(file);
|
|
13
|
+
}
|
|
14
|
+
const addAppJs = () => {
|
|
15
|
+
if ((0, fs_extra_1.existsSync)(`${miniprogramDir}/app.js`) || (0, fs_extra_1.existsSync)(`${miniprogramDir}/app.ts`)) {
|
|
16
|
+
entries.unshift(`'app': require('${(0, common_1.toUnixPath)(`${miniprogramDir}/app`)}')`);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const addServiceJS = (shortPath) => {
|
|
20
|
+
const assetName = (0, common_1.toUnixPath)(shortPath);
|
|
21
|
+
const requirePath = (0, common_1.unixJoin)(miniprogramDir, shortPath);
|
|
22
|
+
entries.push(`'${assetName}': () => require('${requirePath}')`);
|
|
23
|
+
};
|
|
24
|
+
const components = Object.keys(appJSON.componentsMap);
|
|
25
|
+
if (pkg === 'main') {
|
|
26
|
+
// 主包 app.js
|
|
27
|
+
addAppJs();
|
|
28
|
+
// 主包页面逻辑层
|
|
29
|
+
appJSON.pages.forEach(page => addServiceJS(page.path));
|
|
30
|
+
// 主包组件逻辑层
|
|
31
|
+
const subPackageRoots = appJSON.subPackages.map(pkg => pkg.root);
|
|
32
|
+
components
|
|
33
|
+
.filter(compPath => subPackageRoots.every(subRoot => !compPath.startsWith(`${subRoot}/`)))
|
|
34
|
+
.forEach(compPath => addServiceJS(compPath));
|
|
35
|
+
}
|
|
36
|
+
if (pkg === 'sub') {
|
|
37
|
+
// 分包页面逻辑层
|
|
38
|
+
(_b = (_a = appJSON.subPackages
|
|
39
|
+
.find(pkg => pkg.root === root)) === null || _a === void 0 ? void 0 : _a.pages) === null || _b === void 0 ? void 0 : _b.forEach(page => addServiceJS(page.path));
|
|
40
|
+
// 分包组件逻辑层
|
|
41
|
+
components
|
|
42
|
+
.filter(compPath => compPath.startsWith(`${root}/`))
|
|
43
|
+
.forEach(compPath => addServiceJS(compPath));
|
|
44
|
+
}
|
|
45
|
+
return `;globalThis['__MP_APP_JSON__'] = ${JSON.stringify(appJSON)};
|
|
46
|
+
|
|
47
|
+
export default {
|
|
48
|
+
${entries.join(',\n ')}
|
|
49
|
+
}`;
|
|
50
|
+
}
|
|
51
|
+
module.exports = entryLoader;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Span } from '@swc/core';
|
|
2
|
+
export declare const SJS_HELPER = "_sjs$";
|
|
3
|
+
declare function sjsCompiler(code: any, onRequire: (s: string) => string): {
|
|
4
|
+
code: string;
|
|
5
|
+
map: string | undefined;
|
|
6
|
+
legacyCode: string;
|
|
7
|
+
errors: {
|
|
8
|
+
message: string;
|
|
9
|
+
span: Span;
|
|
10
|
+
}[];
|
|
11
|
+
};
|
|
12
|
+
export default sjsCompiler;
|