xhs-mp-compiler-cli 1.0.2 → 1.1.0-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.
- package/dist/bin/xhs-mp-cli-build.js +3 -3
- package/dist/bin/xhs-mp-cli-dev.js +9 -31
- package/dist/compiler.d.ts +76 -0
- package/dist/compiler.js +361 -0
- package/dist/compilerCP.js +175 -0
- package/dist/config/constant.config.d.ts +7 -0
- package/dist/config/constant.config.js +10 -0
- package/dist/dev-server/index.d.ts +2 -2
- package/dist/dev-server/index.js +7 -5
- package/dist/index.d.ts +1 -11
- package/dist/index.js +3 -112
- package/dist/packs/index.d.ts +14 -0
- package/dist/packs/index.js +31 -0
- package/dist/packs/mp-pack/index.d.ts +3 -0
- package/dist/packs/mp-pack/index.js +32 -0
- package/dist/packs/webpack/index.d.ts +3 -0
- package/dist/packs/webpack/index.js +92 -0
- package/dist/packs/webpack/webpack.d.ts +21 -0
- package/dist/packs/webpack/webpack.js +79 -0
- package/dist/{webpack-config/presets → presets}/babel.d.ts +3 -3
- package/dist/{webpack-config/presets → presets}/babel.js +13 -11
- package/dist/presets/common.d.ts +4 -0
- package/dist/presets/common.js +46 -0
- package/dist/presets/configs/minigame/assets/assetsEntryPlugin.d.ts +10 -0
- package/dist/presets/configs/minigame/assets/assetsEntryPlugin.js +46 -0
- package/dist/presets/configs/minigame/assets/index.d.ts +3 -0
- package/dist/presets/configs/minigame/assets/index.js +65 -0
- package/dist/presets/configs/minigame/service/index.d.ts +3 -0
- package/dist/presets/configs/minigame/service/index.js +34 -0
- package/dist/{webpack-config/presets/service/XhsResolveLimitPlugin.d.ts → presets/configs/minigame/service/resolveLimitPlugin.d.ts} +3 -3
- package/dist/presets/configs/minigame/service/resolveLimitPlugin.js +35 -0
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.d.ts +9 -0
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.js +69 -0
- package/dist/{webpack-config/presets/service/ServiceEntryPlugin.d.ts → presets/configs/minigame/service/serviceEntryPlugin.d.ts} +3 -1
- package/dist/presets/configs/minigame/service/serviceEntryPlugin.js +32 -0
- package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.d.ts +12 -0
- package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.js +132 -0
- package/dist/presets/configs/miniprogram/assets/index.d.ts +4 -0
- package/dist/presets/configs/miniprogram/assets/index.js +47 -0
- package/dist/presets/configs/miniprogram/render/component.d.ts +3 -0
- package/dist/presets/configs/miniprogram/render/component.js +47 -0
- package/dist/presets/configs/miniprogram/render/index.d.ts +5 -0
- package/dist/presets/configs/miniprogram/render/index.js +70 -0
- package/dist/presets/configs/miniprogram/render/render.d.ts +3 -0
- package/dist/presets/configs/miniprogram/render/render.js +49 -0
- package/dist/presets/configs/miniprogram/render/renderChunkPlugin.d.ts +8 -0
- package/dist/{webpack-config/presets/render/RenderChunkPlugin.js → presets/configs/miniprogram/render/renderChunkPlugin.js} +13 -8
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.d.ts +15 -0
- package/dist/{webpack-config/presets/render/SjsEntryPlugin.js → presets/configs/miniprogram/render/sjsEntryPlugin.js} +24 -21
- package/dist/presets/configs/miniprogram/service/index.d.ts +5 -0
- package/dist/presets/configs/miniprogram/service/index.js +72 -0
- package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.d.ts +8 -0
- package/dist/{webpack-config/presets/service/XhsResolveLimitPlugin.js → presets/configs/miniprogram/service/resolveLimitPlugin.js} +11 -10
- package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.d.ts +9 -0
- package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.js +65 -0
- package/dist/presets/index.d.ts +2 -0
- package/dist/presets/index.js +95 -0
- package/dist/presets/loaders/mg-entry-loader.js +27 -0
- package/dist/{webpack-config → presets}/loaders/mini-style-loader.js +13 -10
- package/dist/presets/loaders/mp-entry-loader.js +196 -0
- package/dist/{webpack-config → presets}/loaders/sjs-loader/index.js +0 -4
- package/dist/{webpack-config → presets}/loaders/wxss-loader.js +7 -6
- package/dist/presets/plugins/InjectorPlugin.d.ts +7 -0
- package/dist/presets/plugins/InjectorPlugin.js +14 -0
- package/dist/presets/prod.d.ts +4 -0
- package/dist/presets/prod.js +80 -0
- package/dist/types/index.d.ts +18 -6
- package/dist/utils/common.d.ts +2 -1
- package/dist/utils/common.js +7 -6
- package/dist/utils/const.d.ts +27 -0
- package/dist/utils/const.js +47 -0
- package/dist/{webpack-config/lib → utils}/css.js +6 -6
- package/dist/utils/getSuffixName.d.ts +3 -0
- package/dist/utils/getSuffixName.js +18 -0
- package/dist/{webpack-config/loaders/utils.d.ts → utils/loader-utils.d.ts} +2 -0
- package/dist/{webpack-config/loaders/utils.js → utils/loader-utils.js} +19 -1
- package/dist/utils/projectConfig.d.ts +1 -1
- package/dist/utils/projectConfig.js +2 -2
- package/dist/{webpack-config/lib → utils}/utils.js +2 -2
- package/package.json +10 -9
- package/dist/build/index.d.ts +0 -3
- package/dist/build/index.js +0 -22
- package/dist/globalData/SjsModule.d.ts +0 -32
- package/dist/globalData/SjsModule.js +0 -34
- package/dist/utils/combineExtJson.d.ts +0 -3
- package/dist/utils/combineExtJson.js +0 -74
- package/dist/utils/getCssSuffixName.d.ts +0 -1
- package/dist/utils/getCssSuffixName.js +0 -9
- package/dist/utils/getMlSuffixName.d.ts +0 -1
- package/dist/utils/getMlSuffixName.js +0 -6
- package/dist/utils/getPrefixName.d.ts +0 -1
- package/dist/utils/getPrefixName.js +0 -6
- package/dist/utils/transformAppJson.d.ts +0 -16
- package/dist/utils/transformAppJson.js +0 -199
- package/dist/utils/validateAppJson.d.ts +0 -4
- package/dist/utils/validateAppJson.js +0 -111
- package/dist/webpack-config/index.d.ts +0 -4
- package/dist/webpack-config/index.js +0 -41
- package/dist/webpack-config/lib/const.d.ts +0 -13
- package/dist/webpack-config/lib/const.js +0 -15
- package/dist/webpack-config/loaders/component-entry-loader.js +0 -31
- package/dist/webpack-config/loaders/component-entry-requirements-loader.js +0 -24
- package/dist/webpack-config/loaders/render-entry-loader.js +0 -50
- package/dist/webpack-config/loaders/service-entry-loader.d.ts +0 -1
- package/dist/webpack-config/loaders/service-entry-loader.js +0 -51
- package/dist/webpack-config/plugins/VueLoaderPlugin.d.ts +0 -19
- package/dist/webpack-config/plugins/VueLoaderPlugin.js +0 -205
- package/dist/webpack-config/plugins/XhsMpErrorTransformPlugin.d.ts +0 -8
- package/dist/webpack-config/plugins/XhsMpErrorTransformPlugin.js +0 -40
- package/dist/webpack-config/plugins/XhsMpJsonPlugin.d.ts +0 -36
- package/dist/webpack-config/plugins/XhsMpJsonPlugin.js +0 -71
- package/dist/webpack-config/presets/common.d.ts +0 -4
- package/dist/webpack-config/presets/common.js +0 -40
- package/dist/webpack-config/presets/mp/MpEntryPlugin.d.ts +0 -23
- package/dist/webpack-config/presets/mp/MpEntryPlugin.js +0 -87
- package/dist/webpack-config/presets/mp/index.d.ts +0 -4
- package/dist/webpack-config/presets/mp/index.js +0 -48
- package/dist/webpack-config/presets/prod.d.ts +0 -4
- package/dist/webpack-config/presets/prod.js +0 -83
- package/dist/webpack-config/presets/render/ComponentEntryPlugin.d.ts +0 -18
- package/dist/webpack-config/presets/render/ComponentEntryPlugin.js +0 -77
- package/dist/webpack-config/presets/render/RenderChunkPlugin.d.ts +0 -5
- package/dist/webpack-config/presets/render/RenderEntryPlugin.d.ts +0 -14
- package/dist/webpack-config/presets/render/RenderEntryPlugin.js +0 -42
- package/dist/webpack-config/presets/render/SjsEntryPlugin.d.ts +0 -31
- package/dist/webpack-config/presets/render/index.d.ts +0 -4
- package/dist/webpack-config/presets/render/index.js +0 -62
- package/dist/webpack-config/presets/service/ServiceEntryPlugin.js +0 -36
- package/dist/webpack-config/presets/service/XhsMpServiceChunkPlugin.d.ts +0 -6
- package/dist/webpack-config/presets/service/XhsMpServiceChunkPlugin.js +0 -46
- package/dist/webpack-config/presets/service/XhsV2AssetsPlugin.d.ts +0 -5
- package/dist/webpack-config/presets/service/XhsV2AssetsPlugin.js +0 -27
- package/dist/webpack-config/presets/service/index.d.ts +0 -4
- package/dist/webpack-config/presets/service/index.js +0 -39
- /package/dist/{webpack-config/loaders/component-entry-loader.d.ts → compilerCP.d.ts} +0 -0
- /package/dist/{webpack-config/loaders/component-entry-requirements-loader.d.ts → presets/loaders/mg-entry-loader.d.ts} +0 -0
- /package/dist/{webpack-config → presets}/loaders/mini-style-loader.d.ts +0 -0
- /package/dist/{webpack-config/loaders/render-entry-loader.d.ts → presets/loaders/mp-entry-loader.d.ts} +0 -0
- /package/dist/{webpack-config → presets}/loaders/sjs-loader/index.d.ts +0 -0
- /package/dist/{webpack-config → presets}/loaders/sjs-loader/scope.d.ts +0 -0
- /package/dist/{webpack-config → presets}/loaders/sjs-loader/scope.js +0 -0
- /package/dist/{webpack-config → presets}/loaders/sjs-loader/tranform.d.ts +0 -0
- /package/dist/{webpack-config → presets}/loaders/sjs-loader/tranform.js +0 -0
- /package/dist/{webpack-config → presets}/loaders/wxss-loader.d.ts +0 -0
- /package/dist/{webpack-config/lib → utils}/css.d.ts +0 -0
- /package/dist/{webpack-config/lib → utils}/postcssRpx2Vw.d.ts +0 -0
- /package/dist/{webpack-config/lib → utils}/postcssRpx2Vw.js +0 -0
- /package/dist/{webpack-config/lib → utils}/tagTransformMap.d.ts +0 -0
- /package/dist/{webpack-config/lib → utils}/tagTransformMap.js +0 -0
- /package/dist/{webpack-config/lib → utils}/utils.d.ts +0 -0
|
@@ -0,0 +1,95 @@
|
|
|
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
|
+
exports.createConfigs = void 0;
|
|
7
|
+
const xhs_mp_pack_1 = require("xhs-mp-pack");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const common_1 = __importDefault(require("./common"));
|
|
10
|
+
const babel_1 = __importDefault(require("./babel"));
|
|
11
|
+
const prod_1 = __importDefault(require("./prod"));
|
|
12
|
+
const assets_1 = require("./configs/miniprogram/assets");
|
|
13
|
+
const service_1 = require("./configs/miniprogram/service");
|
|
14
|
+
const render_1 = require("./configs/miniprogram/render");
|
|
15
|
+
const assets_2 = require("./configs/minigame/assets");
|
|
16
|
+
const service_2 = require("./configs/miniprogram/service");
|
|
17
|
+
/**
|
|
18
|
+
* 小程序编译配置
|
|
19
|
+
*/
|
|
20
|
+
const createMPConfigs = (options) => {
|
|
21
|
+
const { packSetting } = options;
|
|
22
|
+
const { env } = packSetting;
|
|
23
|
+
const assetsChain = new xhs_mp_pack_1.Config();
|
|
24
|
+
const serviceChain = new xhs_mp_pack_1.Config();
|
|
25
|
+
const renderChain = new xhs_mp_pack_1.Config();
|
|
26
|
+
const assetsPresets = [assets_1.presetAssets, common_1.default];
|
|
27
|
+
const servicePresets = [service_1.presetService, common_1.default, babel_1.default];
|
|
28
|
+
const renderPresets = [render_1.presetRender, common_1.default, babel_1.default];
|
|
29
|
+
if (env === xhs_mp_pack_1.ENV.production) {
|
|
30
|
+
assetsPresets.push(prod_1.default);
|
|
31
|
+
servicePresets.push(prod_1.default);
|
|
32
|
+
renderPresets.push(prod_1.default);
|
|
33
|
+
}
|
|
34
|
+
assetsPresets.forEach(preset => preset(assetsChain, Object.assign(Object.assign({}, options), { otherSetting: { noJs: true } })));
|
|
35
|
+
servicePresets.forEach(preset => preset(serviceChain, options));
|
|
36
|
+
renderPresets.forEach(preset => preset(renderChain, options));
|
|
37
|
+
const assetsConfig = assetsChain.toConfig();
|
|
38
|
+
const serviceConfig = serviceChain.toConfig();
|
|
39
|
+
const renderConfig = renderChain.toConfig();
|
|
40
|
+
assetsConfig.entry = (0, assets_1.getAssetsEntry)(options);
|
|
41
|
+
serviceConfig.entry = (0, service_1.getServiceEntry)(options);
|
|
42
|
+
renderConfig.entry = (0, render_1.getRenderEntry)(options);
|
|
43
|
+
let configs = [renderConfig, serviceConfig, assetsConfig];
|
|
44
|
+
configs = configs.map(options => {
|
|
45
|
+
var _a, _b, _c, _d;
|
|
46
|
+
// 查找ide根目录下的node_modules
|
|
47
|
+
(_b = (_a = options.resolve) === null || _a === void 0 ? void 0 : _a.modules) === null || _b === void 0 ? void 0 : _b.push(path_1.default.resolve(__dirname, '../../../../../'));
|
|
48
|
+
// cli的node_modules路径
|
|
49
|
+
(_d = (_c = options.resolve) === null || _c === void 0 ? void 0 : _c.modules) === null || _d === void 0 ? void 0 : _d.push(path_1.default.resolve(__dirname, '../../../../'));
|
|
50
|
+
return options;
|
|
51
|
+
});
|
|
52
|
+
return configs;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* 小游戏编译配置
|
|
56
|
+
*/
|
|
57
|
+
const createMGConfigs = (options) => {
|
|
58
|
+
const { packSetting } = options;
|
|
59
|
+
const { env } = packSetting;
|
|
60
|
+
const assetsChain = new xhs_mp_pack_1.Config();
|
|
61
|
+
const serviceChain = new xhs_mp_pack_1.Config();
|
|
62
|
+
const assetsPresets = [assets_2.presetAssets, common_1.default];
|
|
63
|
+
const servicePresets = [service_2.presetService, common_1.default, babel_1.default];
|
|
64
|
+
if (env === xhs_mp_pack_1.ENV.production) {
|
|
65
|
+
assetsPresets.push(prod_1.default);
|
|
66
|
+
servicePresets.push(prod_1.default);
|
|
67
|
+
}
|
|
68
|
+
assetsPresets.forEach(preset => preset(assetsChain, Object.assign(Object.assign({}, options), { otherSetting: { noJs: true } })));
|
|
69
|
+
servicePresets.forEach(preset => preset(serviceChain, options));
|
|
70
|
+
const assetsConfig = assetsChain.toConfig();
|
|
71
|
+
const serviceConfig = serviceChain.toConfig();
|
|
72
|
+
assetsConfig.entry = {};
|
|
73
|
+
serviceConfig.entry = {};
|
|
74
|
+
let configs = [serviceConfig, assetsConfig];
|
|
75
|
+
configs = configs.map(options => {
|
|
76
|
+
var _a, _b, _c, _d;
|
|
77
|
+
// 查找ide根目录下的node_modules
|
|
78
|
+
(_b = (_a = options.resolve) === null || _a === void 0 ? void 0 : _a.modules) === null || _b === void 0 ? void 0 : _b.push(path_1.default.resolve(__dirname, '../../../../../'));
|
|
79
|
+
// cli的node_modules路径
|
|
80
|
+
(_d = (_c = options.resolve) === null || _c === void 0 ? void 0 : _c.modules) === null || _d === void 0 ? void 0 : _d.push(path_1.default.resolve(__dirname, '../../../../'));
|
|
81
|
+
return options;
|
|
82
|
+
});
|
|
83
|
+
return configs;
|
|
84
|
+
};
|
|
85
|
+
// 获取编译配置
|
|
86
|
+
const createConfigs = (options) => {
|
|
87
|
+
const { project } = options;
|
|
88
|
+
if (project.appMode === 'miniprogram') {
|
|
89
|
+
return createMPConfigs(options);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
return createMGConfigs(options);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
exports.createConfigs = createConfigs;
|
|
@@ -0,0 +1,27 @@
|
|
|
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 = __importDefault(require("fs-extra"));
|
|
7
|
+
const common_1 = require("../../utils/common");
|
|
8
|
+
const xhs_mp_project_1 = require("xhs-mp-project");
|
|
9
|
+
function entryLoader() {
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
const { appJSON, projectPath } = this._compiler.project;
|
|
12
|
+
const { entry } = this.getOptions();
|
|
13
|
+
const addAppJs = () => {
|
|
14
|
+
const absolutePath = (0, common_1.unixJoin)(projectPath, entry);
|
|
15
|
+
if (fs_extra_1.default.existsSync(`${absolutePath}.js`)) {
|
|
16
|
+
return `require('${absolutePath}.js')`;
|
|
17
|
+
}
|
|
18
|
+
if (fs_extra_1.default.existsSync(`${absolutePath}.ts`)) {
|
|
19
|
+
return `require('${absolutePath}.ts')`;
|
|
20
|
+
}
|
|
21
|
+
throw new Error(`${absolutePath}.(js|ts) 不存在`);
|
|
22
|
+
};
|
|
23
|
+
return `
|
|
24
|
+
;globalThis['__MP_APP_JSON__'] = ${JSON.stringify(xhs_mp_project_1.utils.pureAppJSON(appJSON))};
|
|
25
|
+
${addAppJs()}`;
|
|
26
|
+
}
|
|
27
|
+
module.exports = entryLoader;
|
|
@@ -12,17 +12,17 @@ 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
|
|
15
|
+
const packs_1 = require("../../packs");
|
|
16
16
|
const cssnano_1 = __importDefault(require("cssnano"));
|
|
17
17
|
const common_1 = require("../../utils/common");
|
|
18
18
|
const CSS_MINIMIZER_OPTIONS = {
|
|
19
|
-
preset: ['default', { normalizeUrl: false, calc: false }]
|
|
19
|
+
preset: ['default', { normalizeUrl: false, calc: false }]
|
|
20
20
|
};
|
|
21
21
|
const minify = (source, name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
22
|
var _a, _b;
|
|
23
23
|
const postcssOptions = {
|
|
24
24
|
to: name,
|
|
25
|
-
from: name
|
|
25
|
+
from: name
|
|
26
26
|
};
|
|
27
27
|
try {
|
|
28
28
|
const result = yield cssnano_1.default.process(source, postcssOptions, CSS_MINIMIZER_OPTIONS);
|
|
@@ -33,7 +33,7 @@ const minify = (source, name) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
33
33
|
}
|
|
34
34
|
catch (error) {
|
|
35
35
|
return {
|
|
36
|
-
code: source
|
|
36
|
+
code: source
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
});
|
|
@@ -41,17 +41,19 @@ function miniStyleLoader(source) {
|
|
|
41
41
|
var _a;
|
|
42
42
|
const callback = this.async();
|
|
43
43
|
const { resourcePath } = this;
|
|
44
|
-
const {
|
|
45
|
-
const
|
|
44
|
+
// const {miniprogramDir, enableVDom, enableV1, enableV2, independent} = this.getOptions() as any
|
|
45
|
+
const { project, packSetting, independent } = this.getOptions();
|
|
46
|
+
const { miniprogramDir } = project;
|
|
47
|
+
const { enableVDom, enableV1, enableV2 } = packSetting;
|
|
48
|
+
const shortPath = (0, common_1.getShortPath)(miniprogramDir, resourcePath).replace(/\.wxss$/, '.css');
|
|
46
49
|
source = (_a = source === null || source === void 0 ? void 0 : source.trim) === null || _a === void 0 ? void 0 : _a.call(source);
|
|
47
50
|
function result(code) {
|
|
48
51
|
if (!code) {
|
|
49
52
|
return `export default void 0;`;
|
|
50
53
|
}
|
|
51
54
|
// 判断浏览器环境,注入css添加逻辑
|
|
52
|
-
return new
|
|
53
|
-
|
|
54
|
-
`export default ${JSON.stringify(shortPath)};`).source();
|
|
55
|
+
return new packs_1.RawSource(`globalThis.__XHS_IS_WEBVIEW && globalThis.__XHS_APPEND_CSS(${JSON.stringify(code)});` +
|
|
56
|
+
`export default ${JSON.stringify(shortPath)};`).source();
|
|
55
57
|
}
|
|
56
58
|
// 压缩css
|
|
57
59
|
minify(source, shortPath)
|
|
@@ -62,7 +64,8 @@ function miniStyleLoader(source) {
|
|
|
62
64
|
enableV2 && this.emitFile(`v2/${shortPath}`, code);
|
|
63
65
|
}
|
|
64
66
|
callback(null, result(code));
|
|
65
|
-
})
|
|
67
|
+
})
|
|
68
|
+
.catch(error => {
|
|
66
69
|
callback(error);
|
|
67
70
|
});
|
|
68
71
|
}
|
|
@@ -0,0 +1,196 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const fs_extra_1 = __importStar(require("fs-extra"));
|
|
27
|
+
const path_1 = __importStar(require("path"));
|
|
28
|
+
const xhs_mp_pack_1 = require("xhs-mp-pack");
|
|
29
|
+
const loader_utils_1 = require("../../utils/loader-utils");
|
|
30
|
+
const getSuffixName_1 = require("../../utils/getSuffixName");
|
|
31
|
+
function genComponentLoaderScript(project, context, opts) {
|
|
32
|
+
const { pkg, root, mode, compPath } = opts;
|
|
33
|
+
const { projectMiniprogramPath, jsonDependencies = [] } = project;
|
|
34
|
+
const componentsMap = project.getComponentsMap();
|
|
35
|
+
const entries = [];
|
|
36
|
+
for (const file of jsonDependencies) {
|
|
37
|
+
context.addDependency(file);
|
|
38
|
+
}
|
|
39
|
+
let name = 'XHS_COMPONENTS';
|
|
40
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG) {
|
|
41
|
+
name = `XHS_COMPONENTS_${root}`;
|
|
42
|
+
}
|
|
43
|
+
// v2
|
|
44
|
+
if (mode === 'v2') {
|
|
45
|
+
return `
|
|
46
|
+
;(globalThis['${name}'] || (globalThis['${name}'] = { default: {} }))
|
|
47
|
+
;globalThis['${name}'].default['${compPath}'] = () => require('${(0, loader_utils_1.formatPath)(path_1.default.join(projectMiniprogramPath, `${compPath}.${(0, getSuffixName_1.getMlSuffixName)()}`))}')
|
|
48
|
+
`;
|
|
49
|
+
}
|
|
50
|
+
// v1和v0
|
|
51
|
+
Object.keys(componentsMap).forEach(compPath => {
|
|
52
|
+
const push = () => entries.push(`;globalThis['${name}'].default['${compPath}'] = () => require('${(0, loader_utils_1.formatPath)(path_1.default.join(projectMiniprogramPath, `${compPath}.${(0, getSuffixName_1.getMlSuffixName)()}`))}')`);
|
|
53
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.FULL_PKG) {
|
|
54
|
+
push();
|
|
55
|
+
}
|
|
56
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.MAIN_PKG && project.isFileInMainPkg(compPath)) {
|
|
57
|
+
push();
|
|
58
|
+
}
|
|
59
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG && compPath.startsWith(`${root}/`)) {
|
|
60
|
+
push();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return `
|
|
64
|
+
;(globalThis['${name}'] || (globalThis['${name}'] = { default: {} }))
|
|
65
|
+
;${entries.join('\n ')}
|
|
66
|
+
`;
|
|
67
|
+
}
|
|
68
|
+
const genRenderLoaderScript = (project, context, opts) => {
|
|
69
|
+
const { projectMiniprogramPath, appJSON, jsonDependencies } = project;
|
|
70
|
+
const { pkg, mode } = opts;
|
|
71
|
+
const isFull = pkg === 'full';
|
|
72
|
+
for (const file of jsonDependencies) {
|
|
73
|
+
context.addDependency(file);
|
|
74
|
+
}
|
|
75
|
+
const appCssPath = (0, path_1.resolve)(projectMiniprogramPath, 'app.css');
|
|
76
|
+
const appCssExist = (0, fs_extra_1.existsSync)(appCssPath);
|
|
77
|
+
const resourcePath = (0, loader_utils_1.formatPath)(context.resourcePath);
|
|
78
|
+
const path = (0, loader_utils_1.formatPath)(resourcePath.replace(`${projectMiniprogramPath}/`, '').replace(`.${(0, getSuffixName_1.getMlSuffixName)()}`, ''));
|
|
79
|
+
const subPackage = (appJSON.subPackages || []).find(subPack => !!subPack.pages.find(page => page.path === path));
|
|
80
|
+
const enableLazyCodeLoading = mode === 'v2';
|
|
81
|
+
// 资源文件
|
|
82
|
+
const resources = (0, loader_utils_1.getResourceUris)({
|
|
83
|
+
appCssExist,
|
|
84
|
+
subPackage,
|
|
85
|
+
enableLazyCodeLoading
|
|
86
|
+
});
|
|
87
|
+
// 开启了按需注入,注入依赖组件
|
|
88
|
+
if (enableLazyCodeLoading) {
|
|
89
|
+
const isIndependent = (subPackage === null || subPackage === void 0 ? void 0 : subPackage.independent) || false;
|
|
90
|
+
const dependsTree = project.getPageDependComponentPaths(path, isIndependent);
|
|
91
|
+
const subPackagesPrefix = (appJSON.subPackages || []).map(sub => sub.root);
|
|
92
|
+
const depends = [];
|
|
93
|
+
for (let i = 0; i < dependsTree.length; i++) {
|
|
94
|
+
let uri = dependsTree[i];
|
|
95
|
+
const subRoot = subPackagesPrefix.find(subRoot => uri.startsWith(`${subRoot}/`));
|
|
96
|
+
if (subRoot) {
|
|
97
|
+
uri = `${subRoot}/${uri}`;
|
|
98
|
+
}
|
|
99
|
+
depends.push(uri);
|
|
100
|
+
}
|
|
101
|
+
return `
|
|
102
|
+
import Component from '${resourcePath}';
|
|
103
|
+
globalThis.__render.mount(Component, '${path}', ${JSON.stringify(resources)}, ${JSON.stringify(depends)})
|
|
104
|
+
`;
|
|
105
|
+
}
|
|
106
|
+
return `
|
|
107
|
+
import Component from '${resourcePath}';
|
|
108
|
+
globalThis.__render.mount(Component, '${path}', ${JSON.stringify(resources)})
|
|
109
|
+
`;
|
|
110
|
+
};
|
|
111
|
+
function genServiceLoderScript(project, context, opts) {
|
|
112
|
+
const { appJSON, legacyAppJSON, projectMiniprogramPath, jsonDependencies } = project;
|
|
113
|
+
const { pkg, root } = opts;
|
|
114
|
+
const modules = [];
|
|
115
|
+
let name = 'XHS_SERVICE';
|
|
116
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG) {
|
|
117
|
+
name = `XHS_SERVICE_${root}`;
|
|
118
|
+
}
|
|
119
|
+
for (const file of jsonDependencies) {
|
|
120
|
+
context.addDependency(file);
|
|
121
|
+
}
|
|
122
|
+
const addAppJs = () => {
|
|
123
|
+
if (fs_extra_1.default.existsSync(`${projectMiniprogramPath}/app.js`) ||
|
|
124
|
+
fs_extra_1.default.existsSync(`${projectMiniprogramPath}/app.ts`)) {
|
|
125
|
+
modules.unshift(`;globalThis['${name}'].default['app'] = require('${(0, loader_utils_1.formatPath)(`${projectMiniprogramPath}/app`)}')`);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.FULL_PKG) {
|
|
129
|
+
addAppJs();
|
|
130
|
+
for (const page of legacyAppJSON.pages) {
|
|
131
|
+
const resourcePath = (0, loader_utils_1.formatPath)(`${projectMiniprogramPath}/${page.path}`);
|
|
132
|
+
modules.push(`;globalThis['${name}'].default['${page.path}'] = () => require('${resourcePath}')`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.MAIN_PKG) {
|
|
137
|
+
addAppJs();
|
|
138
|
+
}
|
|
139
|
+
for (const page of legacyAppJSON.pages) {
|
|
140
|
+
const resourcePath = (0, loader_utils_1.formatPath)(`${projectMiniprogramPath}/${page.path}`);
|
|
141
|
+
const content = `;globalThis['${name}'].default['${page.path}'] = () => require('${resourcePath}')`;
|
|
142
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.MAIN_PKG) {
|
|
143
|
+
const subPackageRoots = appJSON.subPackages.map(pkg => pkg.root);
|
|
144
|
+
if (subPackageRoots.every(root => !page.path.startsWith(`${root}/`))) {
|
|
145
|
+
modules.push(content);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG) {
|
|
149
|
+
if (page.path.startsWith(`${root}/`)) {
|
|
150
|
+
modules.push(content);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
Object.keys(appJSON.componentsMap).forEach(compPath => {
|
|
156
|
+
const resourcePath = (0, loader_utils_1.formatPath)(`${projectMiniprogramPath}/${compPath}`);
|
|
157
|
+
const content = `;globalThis['${name}'].default['${compPath}'] = () => require('${resourcePath}')`;
|
|
158
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.FULL_PKG) {
|
|
159
|
+
modules.push(content);
|
|
160
|
+
}
|
|
161
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.MAIN_PKG) {
|
|
162
|
+
const subPackageRoots = appJSON.subPackages.map(pkg => pkg.root);
|
|
163
|
+
if (subPackageRoots.every(root => !compPath.startsWith(`${root}/`))) {
|
|
164
|
+
modules.push(content);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG) {
|
|
168
|
+
if (compPath.startsWith(`${root}/`)) {
|
|
169
|
+
modules.push(content);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
const runtimeJSON = pkg === xhs_mp_pack_1.CONSTANTS.FULL_PKG ? legacyAppJSON : appJSON;
|
|
174
|
+
return `;globalThis['__MP_APP_JSON__'] = ${JSON.stringify(runtimeJSON)};
|
|
175
|
+
;(globalThis['${name}'] || (globalThis['${name}'] = { default: {} }))
|
|
176
|
+
${modules.join('\n ')}
|
|
177
|
+
`;
|
|
178
|
+
}
|
|
179
|
+
function entryLoader() {
|
|
180
|
+
// @ts-ignore
|
|
181
|
+
const options = this.getOptions();
|
|
182
|
+
const { type } = options;
|
|
183
|
+
// @ts-ignore
|
|
184
|
+
const handelrs = {
|
|
185
|
+
render: genRenderLoaderScript,
|
|
186
|
+
component: genComponentLoaderScript,
|
|
187
|
+
service: genServiceLoderScript
|
|
188
|
+
};
|
|
189
|
+
const handler = handelrs[type];
|
|
190
|
+
if (!handler) {
|
|
191
|
+
throw new Error(`not found loader handler of ${type}`);
|
|
192
|
+
}
|
|
193
|
+
// @ts-ignore
|
|
194
|
+
return handler(this._compiler.project, this, options);
|
|
195
|
+
}
|
|
196
|
+
module.exports = entryLoader;
|
|
@@ -28,7 +28,6 @@ function sjsCompiler(code, onRequire) {
|
|
|
28
28
|
errors.push({ message, span: Object.assign({}, span) });
|
|
29
29
|
}
|
|
30
30
|
function handlePattern(pattern) {
|
|
31
|
-
// console.log(pattern.type, pattern)
|
|
32
31
|
switch (pattern.type) {
|
|
33
32
|
case "RestElement":
|
|
34
33
|
// function f(...a) {}
|
|
@@ -604,6 +603,3 @@ function sjsCompiler(code, onRequire) {
|
|
|
604
603
|
};
|
|
605
604
|
}
|
|
606
605
|
exports.default = sjsCompiler;
|
|
607
|
-
// console.time('sjs',111)
|
|
608
|
-
// const data = sjsCompiler(code, (s) => s)
|
|
609
|
-
// console.timeEnd('sjs')
|
|
@@ -16,8 +16,8 @@ const postcss_1 = __importDefault(require("postcss"));
|
|
|
16
16
|
const postcss_import_1 = __importDefault(require("postcss-import"));
|
|
17
17
|
const postcss_prefix_selector_1 = __importDefault(require("postcss-prefix-selector"));
|
|
18
18
|
const CssSyntaxError_1 = __importDefault(require("css-loader/dist/CssSyntaxError"));
|
|
19
|
-
const tagTransformMap_1 = __importDefault(require("
|
|
20
|
-
const
|
|
19
|
+
const tagTransformMap_1 = __importDefault(require("../../utils/tagTransformMap"));
|
|
20
|
+
const getSuffixName_1 = require("../../utils/getSuffixName");
|
|
21
21
|
const common_1 = require("../../utils/common");
|
|
22
22
|
const tags = Object.keys(tagTransformMap_1.default).join('|');
|
|
23
23
|
const labelStr = `(^|\\s)(${tags}|page|audio|live-player|map|cover-view|cover-image|video)`;
|
|
@@ -26,17 +26,18 @@ function wxssLoader(source) {
|
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
27
|
var _a, _b, _c, _d, _e;
|
|
28
28
|
const done = this.async();
|
|
29
|
-
|
|
30
|
-
const { appJSON = {}, miniprogramDir = '' } =
|
|
31
|
-
const shortPath = (0, common_1.getShortPath)(miniprogramDir, this.resourcePath).replace(new RegExp(`\\.${(0,
|
|
29
|
+
const { project } = this._compiler;
|
|
30
|
+
const { appJSON = {}, miniprogramDir = '' } = project || {};
|
|
31
|
+
const shortPath = (0, common_1.getShortPath)(miniprogramDir, this.resourcePath).replace(new RegExp(`\\.${(0, getSuffixName_1.getCssSuffixName)()}$`), '');
|
|
32
32
|
const index = (_c = (_b = (_a = appJSON === null || appJSON === void 0 ? void 0 : appJSON.componentsMap) === null || _a === void 0 ? void 0 : _a[shortPath]) === null || _b === void 0 ? void 0 : _b.index) !== null && _c !== void 0 ? _c : null;
|
|
33
33
|
const styleIsolation = (_e = (_d = appJSON === null || appJSON === void 0 ? void 0 : appJSON.componentsMap) === null || _d === void 0 ? void 0 : _d[shortPath]) === null || _e === void 0 ? void 0 : _e.styleIsolation;
|
|
34
34
|
const selectorIndex = styleIsolation === 'shared' ? 0 : index || 0;
|
|
35
35
|
// js / json 的配置会影响样式
|
|
36
|
-
const extReg = new RegExp(`${(0,
|
|
36
|
+
const extReg = new RegExp(`${(0, getSuffixName_1.getCssSuffixName)()}$`);
|
|
37
37
|
this.addDependency(this.resourcePath.replace(extReg, 'js'));
|
|
38
38
|
this.addDependency(this.resourcePath.replace(extReg, 'json'));
|
|
39
39
|
(0, postcss_1.default)()
|
|
40
|
+
// @ts-ignore
|
|
40
41
|
.use((0, postcss_import_1.default)({ root: miniprogramDir }))
|
|
41
42
|
.use((0, postcss_prefix_selector_1.default)({
|
|
42
43
|
prefix: 'xhs',
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InjectorPlugin = void 0;
|
|
4
|
+
class InjectorPlugin {
|
|
5
|
+
constructor(options) {
|
|
6
|
+
this.options = options;
|
|
7
|
+
}
|
|
8
|
+
apply(compiler) {
|
|
9
|
+
const { project, packSetting } = this.options;
|
|
10
|
+
compiler.project = project;
|
|
11
|
+
compiler.packSetting = packSetting;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.InjectorPlugin = InjectorPlugin;
|
|
@@ -0,0 +1,80 @@
|
|
|
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 const_1 = __importDefault(require("../utils/const"));
|
|
7
|
+
// import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
|
|
8
|
+
const getProdConfig = (chain, options) => {
|
|
9
|
+
const { project, packSetting, otherSetting = {} } = options;
|
|
10
|
+
const { compressJs } = packSetting;
|
|
11
|
+
chain.mode('production');
|
|
12
|
+
if (!otherSetting.noJs) {
|
|
13
|
+
// 生产环境使用 babel-loader
|
|
14
|
+
if (project.appMode === 'miniprogram') {
|
|
15
|
+
chain.module
|
|
16
|
+
.rule('js')
|
|
17
|
+
.use('js-loader')
|
|
18
|
+
.loader(require.resolve('babel-loader'))
|
|
19
|
+
.options({
|
|
20
|
+
configFile: false,
|
|
21
|
+
babelrc: false,
|
|
22
|
+
sourceType: 'unambiguous',
|
|
23
|
+
presets: [
|
|
24
|
+
[
|
|
25
|
+
require.resolve('@babel/preset-env'),
|
|
26
|
+
{
|
|
27
|
+
useBuiltIns: false,
|
|
28
|
+
corejs: {
|
|
29
|
+
version: 3,
|
|
30
|
+
proposals: true
|
|
31
|
+
},
|
|
32
|
+
shippedProposals: true,
|
|
33
|
+
targets: const_1.default.PROD_BROWSERSLIST
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
],
|
|
37
|
+
plugins: [[require.resolve('@babel/plugin-transform-runtime'), { corejs: false }]]
|
|
38
|
+
});
|
|
39
|
+
chain.module
|
|
40
|
+
.rule('ts')
|
|
41
|
+
.use('ts-loader')
|
|
42
|
+
.loader(require.resolve('babel-loader'))
|
|
43
|
+
.options({
|
|
44
|
+
sourceType: 'unambiguous',
|
|
45
|
+
presets: [
|
|
46
|
+
[
|
|
47
|
+
require.resolve('@babel/preset-typescript'),
|
|
48
|
+
{
|
|
49
|
+
allExtensions: true,
|
|
50
|
+
isTSX: true
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
[
|
|
54
|
+
require.resolve('@babel/preset-env'),
|
|
55
|
+
{
|
|
56
|
+
useBuiltIns: false,
|
|
57
|
+
corejs: {
|
|
58
|
+
version: 3,
|
|
59
|
+
proposals: true
|
|
60
|
+
},
|
|
61
|
+
shippedProposals: true,
|
|
62
|
+
targets: const_1.default.PROD_BROWSERSLIST
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
],
|
|
66
|
+
plugins: [[require.resolve('@babel/plugin-transform-runtime'), { corejs: false }]]
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
chain.optimization.minimizer('js').use(require.resolve('terser-webpack-plugin'), [
|
|
70
|
+
{
|
|
71
|
+
terserOptions: {
|
|
72
|
+
safari10: true,
|
|
73
|
+
compress: { drop_console: false }
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
]);
|
|
77
|
+
}
|
|
78
|
+
chain.optimization.minimize(!!compressJs);
|
|
79
|
+
};
|
|
80
|
+
exports.default = getProdConfig;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { MPPackSetting } from "xhs-mp-pack";
|
|
2
|
+
import type { Project } from "xhs-mp-project";
|
|
1
3
|
export declare enum ENV {
|
|
2
4
|
development = 0,
|
|
3
5
|
production = 1
|
|
@@ -44,16 +46,17 @@ export interface AppJSON {
|
|
|
44
46
|
[key: string]: string | boolean;
|
|
45
47
|
};
|
|
46
48
|
}
|
|
47
|
-
export interface
|
|
49
|
+
export interface ICompilerConfig {
|
|
48
50
|
/**
|
|
49
51
|
* 小程序入口目录
|
|
50
52
|
*/
|
|
51
|
-
|
|
53
|
+
projectPath: string;
|
|
52
54
|
miniprogramDir: string;
|
|
53
55
|
/**
|
|
54
56
|
* 构建产物目录
|
|
55
57
|
*/
|
|
56
58
|
distDir?: string;
|
|
59
|
+
action: "dev" | "build";
|
|
57
60
|
watch?: boolean;
|
|
58
61
|
env: ENV;
|
|
59
62
|
tsConfigPath?: string;
|
|
@@ -82,12 +85,17 @@ export interface CliConfig {
|
|
|
82
85
|
enableV2?: boolean;
|
|
83
86
|
enableVDom?: boolean;
|
|
84
87
|
}
|
|
85
|
-
type CliPick = '
|
|
86
|
-
export interface IStart extends Pick<
|
|
88
|
+
type CliPick = 'projectPath' | 'distDir' | 'watch' | 'tsConfigPath' | 'extJsonPath' | 'cacheDirectory' | 'compressJs' | 'enableSourcemap' | 'enableV1' | 'enableV2' | 'enableVDom';
|
|
89
|
+
export interface IStart extends Pick<ICompilerConfig, CliPick> {
|
|
90
|
+
packMode?: 'webpack' | 'mp-pack';
|
|
87
91
|
/**
|
|
88
92
|
* 调用的能力,dev 还是 build
|
|
89
93
|
*/
|
|
90
94
|
action: 'dev' | 'build';
|
|
95
|
+
/**
|
|
96
|
+
* 是否启动dev-server
|
|
97
|
+
*/
|
|
98
|
+
enableDevServer?: boolean;
|
|
91
99
|
/**
|
|
92
100
|
* 每次构建完毕的回调函数
|
|
93
101
|
*/
|
|
@@ -100,7 +108,11 @@ export interface IStart extends Pick<CliConfig, CliPick> {
|
|
|
100
108
|
/**
|
|
101
109
|
* 服务端口
|
|
102
110
|
*/
|
|
103
|
-
|
|
111
|
+
devServerPort?: number;
|
|
104
112
|
}
|
|
105
|
-
export type
|
|
113
|
+
export type IPresetOptions = {
|
|
114
|
+
project: Project;
|
|
115
|
+
packSetting: MPPackSetting;
|
|
116
|
+
otherSetting?: any;
|
|
117
|
+
};
|
|
106
118
|
export {};
|
package/dist/utils/common.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export declare const getTsConfigPath: (
|
|
1
|
+
export declare const getTsConfigPath: (projectPath: string) => string | undefined;
|
|
2
2
|
export declare const isString: (val: unknown) => val is string;
|
|
3
3
|
export declare const toUnixPath: (pathStr?: string) => string;
|
|
4
4
|
export declare const unixJoin: (...paths: string[]) => string;
|
|
5
5
|
export declare const unixResolve: (...paths: string[]) => string;
|
|
6
6
|
export declare const getShortPath: (miniprogramDir: string, rootContext: string) => string;
|
|
7
7
|
export declare const md5: (str: string) => string;
|
|
8
|
+
export declare const DEFAULT_ENTRY = "game";
|
package/dist/utils/common.js
CHANGED
|
@@ -3,14 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.md5 = exports.getShortPath = exports.unixResolve = exports.unixJoin = exports.toUnixPath = exports.isString = exports.getTsConfigPath = void 0;
|
|
6
|
+
exports.DEFAULT_ENTRY = exports.md5 = exports.getShortPath = exports.unixResolve = exports.unixJoin = exports.toUnixPath = exports.isString = exports.getTsConfigPath = void 0;
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const crypto_1 = __importDefault(require("crypto"));
|
|
10
|
-
const
|
|
11
|
-
const getTsConfigPath = (
|
|
12
|
-
if (fs_extra_1.default.existsSync(`${
|
|
13
|
-
return `${
|
|
10
|
+
const getSuffixName_1 = require("./getSuffixName");
|
|
11
|
+
const getTsConfigPath = (projectPath) => {
|
|
12
|
+
if (fs_extra_1.default.existsSync(`${projectPath}/tsconfig.json`)) {
|
|
13
|
+
return `${projectPath}/tsconfig.json`;
|
|
14
14
|
}
|
|
15
15
|
return undefined;
|
|
16
16
|
};
|
|
@@ -24,7 +24,7 @@ exports.unixJoin = unixJoin;
|
|
|
24
24
|
const unixResolve = (...paths) => (0, exports.toUnixPath)(path_1.default.resolve(...paths));
|
|
25
25
|
exports.unixResolve = unixResolve;
|
|
26
26
|
const getShortPath = (miniprogramDir, rootContext) => {
|
|
27
|
-
const suffix = (0,
|
|
27
|
+
const suffix = (0, getSuffixName_1.getMlSuffixName)();
|
|
28
28
|
miniprogramDir = (0, exports.toUnixPath)(miniprogramDir);
|
|
29
29
|
miniprogramDir = miniprogramDir.endsWith('/') ? miniprogramDir : `${miniprogramDir}/`;
|
|
30
30
|
const reg = new RegExp(`.${suffix}$`, 'g');
|
|
@@ -33,3 +33,4 @@ const getShortPath = (miniprogramDir, rootContext) => {
|
|
|
33
33
|
exports.getShortPath = getShortPath;
|
|
34
34
|
const md5 = (str) => crypto_1.default.createHash('md5').update(str).digest('hex');
|
|
35
35
|
exports.md5 = md5;
|
|
36
|
+
exports.DEFAULT_ENTRY = "game";
|