xhs-mp-compiler-cli 1.0.1-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/README.md +1 -0
- package/dist/bin/xhs-mp-cli-build.d.ts +2 -0
- package/dist/bin/xhs-mp-cli-build.js +42 -0
- package/dist/bin/xhs-mp-cli-dev.d.ts +2 -0
- package/dist/bin/xhs-mp-cli-dev.js +84 -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 +118 -0
- package/dist/types/index.d.ts +110 -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 +13 -0
- package/dist/webpack-config/lib/postcssRpx2Vw.js +40 -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/ml-loader/index.d.ts +3 -0
- package/dist/webpack-config/loaders/ml-loader/index.js +66 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/generator.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/generator.js +107 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/index.d.ts +6 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/index.js +64 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/injectScript.d.ts +11 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/injectScript.js +41 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/injectTemplate.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/injectTemplate.js +18 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/parser.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/parser.js +21 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformer.d.ts +7 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformer.js +185 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBindAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBindAttribute.js +73 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBlockTag.d.ts +13 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBlockTag.js +42 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleCatchAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleCatchAttribute.js +30 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleClassAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleClassAttribute.js +17 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleDataAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleDataAttribute.js +23 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleHiddenAttribute.d.ts +13 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleHiddenAttribute.js +25 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleImportTag.d.ts +4 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleImportTag.js +30 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleIncludeTag.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleIncludeTag.js +30 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleLoopAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleLoopAttribute.js +89 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleMLAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleMLAttribute.js +33 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleModelAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleModelAttribute.js +61 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleOtherAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleOtherAttribute.js +35 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSjsEvent.d.ts +11 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSjsEvent.js +72 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSlotAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSlotAttribute.js +74 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSpaceAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSpaceAttribute.js +12 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleStyleAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleStyleAttribute.js +16 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/utils.d.ts +10 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/utils.js +80 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/utils.d.ts +7 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/utils.js +41 -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/frame.d.ts +1 -0
- package/dist/webpack-config/loaders/sjs-loader/frame.js +51 -0
- package/dist/webpack-config/loaders/sjs-loader/index.d.ts +1 -0
- package/dist/webpack-config/loaders/sjs-loader/index.js +93 -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 +85 -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 +9 -0
- package/dist/webpack-config/presets/render/RenderChunkPlugin.js +65 -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 +124 -0
- package/dist/webpack-config/presets/render/index.d.ts +4 -0
- package/dist/webpack-config/presets/render/index.js +99 -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 +38 -0
- package/package.json +124 -0
|
@@ -0,0 +1,74 @@
|
|
|
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 clone_1 = __importDefault(require("clone"));
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
const utils_2 = require("../utils");
|
|
9
|
+
/**
|
|
10
|
+
* 默认不合法
|
|
11
|
+
* 若祖先节点先出现自定义组件,合法
|
|
12
|
+
* 若祖先节点先出现 XhsVueTemplate,不合法
|
|
13
|
+
*/
|
|
14
|
+
const isValidSlot = node => {
|
|
15
|
+
let parent = node.parent;
|
|
16
|
+
let firstMet = '';
|
|
17
|
+
while (parent === null || parent === void 0 ? void 0 : parent.name) {
|
|
18
|
+
const parentTagName = parent.name;
|
|
19
|
+
if (parentTagName === 'XhsVueTemplate') {
|
|
20
|
+
firstMet = 'XhsVueTemplate';
|
|
21
|
+
}
|
|
22
|
+
else if ((0, utils_2.isCustomComponent)(parentTagName)) {
|
|
23
|
+
firstMet = 'customElement';
|
|
24
|
+
}
|
|
25
|
+
if (firstMet === 'customElement') {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
if (firstMet === 'XhsVueTemplate') {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
parent = parent.parent;
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
};
|
|
35
|
+
const handleSlotAttribute = (node) => {
|
|
36
|
+
if (!isValidSlot(node)) {
|
|
37
|
+
delete node.attribs.slot;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const value = node.attribs.slot;
|
|
41
|
+
const dynamicValue = (0, utils_1.matchMustache)(value);
|
|
42
|
+
delete node.attribs.slot;
|
|
43
|
+
let vSlotAttr = `v-slot:${value}`;
|
|
44
|
+
if (dynamicValue === null || dynamicValue === void 0 ? void 0 : dynamicValue.length) {
|
|
45
|
+
vSlotAttr = `v-slot:[${(0, utils_1.injectContext2Exp)(value, node, 2)}]`.replace(/\s/g, '');
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 若父元素已经是 template 标签,则把 v-slot 转移到父级元素
|
|
49
|
+
* https://eslint.vuejs.org/rules/valid-v-slot.html
|
|
50
|
+
*/
|
|
51
|
+
if (node.parent.name === 'template') {
|
|
52
|
+
node.parent.attribs[vSlotAttr] = '';
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const attribs = { [vSlotAttr]: '' };
|
|
56
|
+
const children = node.cloneNode ? node.cloneNode(true) : (0, clone_1.default)(node);
|
|
57
|
+
(0, utils_1.addContextToNode)({
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
nodes: children,
|
|
60
|
+
loopContext: node.loopContext,
|
|
61
|
+
underTemplate: node.underTemplate,
|
|
62
|
+
});
|
|
63
|
+
node.name = 'template';
|
|
64
|
+
for (const [key, val] of Object.entries(node.attribs)) {
|
|
65
|
+
if (/:if|:elif|:else/.test(key)) {
|
|
66
|
+
attribs[key] = val;
|
|
67
|
+
delete children.attribs[key];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
node.attribs = attribs;
|
|
71
|
+
node.children = [children];
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
exports.default = handleSlotAttribute;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const validSpaces = ['ensp', 'emsp', 'nbsp'];
|
|
4
|
+
const handleSpaceAttribute = (value, node) => {
|
|
5
|
+
if (node.name === 'xhs-vue-text' && validSpaces.includes(value)) {
|
|
6
|
+
node.children.forEach((it) => {
|
|
7
|
+
if (it.type === 'text')
|
|
8
|
+
it.data = it.data.replace(/ /g, `&${value};`);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
exports.default = handleSpaceAttribute;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const xhs_mp_compiler_utils_1 = require("xhs-mp-compiler-utils");
|
|
4
|
+
const postcssRpx2Vw_1 = require("../../../../lib/postcssRpx2Vw");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const handleStyleAttribute = (value, node) => {
|
|
7
|
+
var _a;
|
|
8
|
+
if ((_a = (0, utils_1.matchMustache)(value)) === null || _a === void 0 ? void 0 : _a.length) {
|
|
9
|
+
node.attribs[':style'] = `${xhs_mp_compiler_utils_1.COMPILE_CALL_RUNTIME}('${xhs_mp_compiler_utils_1.CompileCallRuntimeMethodsNames.Rpx2vw}', ${(0, utils_1.injectContext2Exp)(value, node, 1)})`;
|
|
10
|
+
delete node.attribs.style;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
node.attribs.style = value.replace(/([\d.]+)rpx/g, (m, $1) => (0, postcssRpx2Vw_1.calcRpx2Vw)($1));
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
exports.default = handleStyleAttribute;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const matchMustache: (value: string) => never[] | RegExpMatchArray | null;
|
|
2
|
+
export declare function injectModelHandler(isComponent: boolean, property: string, changeEvent?: any): string;
|
|
3
|
+
export declare function addContextToNode({ nodes, loopContext, underTemplate }: {
|
|
4
|
+
nodes: any;
|
|
5
|
+
loopContext?: string[];
|
|
6
|
+
underTemplate?: boolean;
|
|
7
|
+
useSjs?: boolean;
|
|
8
|
+
}): void;
|
|
9
|
+
declare const injectContext2Exp: (exp: string, node: any, type: number) => string | undefined;
|
|
10
|
+
export { matchMustache, injectContext2Exp };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.injectContext2Exp = exports.matchMustache = exports.addContextToNode = exports.injectModelHandler = void 0;
|
|
4
|
+
/* eslint-disable consistent-return */
|
|
5
|
+
const xhs_mp_compiler_utils_1 = require("xhs-mp-compiler-utils");
|
|
6
|
+
const matchMustache = (value) => {
|
|
7
|
+
if (!value)
|
|
8
|
+
return [];
|
|
9
|
+
return `${value}`.match(/{{(.*?)}}/g);
|
|
10
|
+
};
|
|
11
|
+
exports.matchMustache = matchMustache;
|
|
12
|
+
function injectModelHandler(isComponent, property, changeEvent) {
|
|
13
|
+
return `${xhs_mp_compiler_utils_1.CompileCallRuntimeMethodsNames.RunModuleUpdater}(${isComponent}, ${property}, ${changeEvent !== null && changeEvent !== void 0 ? changeEvent : changeEvent})`;
|
|
14
|
+
}
|
|
15
|
+
exports.injectModelHandler = injectModelHandler;
|
|
16
|
+
function addContextToNode({ nodes, loopContext, underTemplate }) {
|
|
17
|
+
nodes = Array.isArray(nodes) ? nodes : [nodes];
|
|
18
|
+
for (const node of nodes) {
|
|
19
|
+
if (loopContext) {
|
|
20
|
+
node.loopContext = node.loopContext ? [...new Set([...node.loopContext, ...loopContext])] : [...new Set(loopContext)];
|
|
21
|
+
}
|
|
22
|
+
if (underTemplate !== undefined) {
|
|
23
|
+
node.underTemplate = underTemplate;
|
|
24
|
+
}
|
|
25
|
+
if (node.children) {
|
|
26
|
+
addContextToNode({ nodes: node.children, loopContext, underTemplate });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.addContextToNode = addContextToNode;
|
|
31
|
+
const injectContext2Exp = (exp, node, type) => {
|
|
32
|
+
const { ExecExpWithContext } = xhs_mp_compiler_utils_1.CompileCallRuntimeMethodsNames;
|
|
33
|
+
let { loopContext = [], underTemplate } = node;
|
|
34
|
+
// v-for 不添加自己的 loop context
|
|
35
|
+
if (type === 7) {
|
|
36
|
+
loopContext = node.parent.loopContext || [];
|
|
37
|
+
}
|
|
38
|
+
const loopContextStr = loopContext.join(', ');
|
|
39
|
+
const templateContextStr = '...data';
|
|
40
|
+
let context = '{}';
|
|
41
|
+
if (loopContext.length && underTemplate) {
|
|
42
|
+
// 对齐微信表现,两者都存在时 loopContext 在后
|
|
43
|
+
context = `{${templateContextStr}, ${loopContextStr}}, ${underTemplate}`;
|
|
44
|
+
}
|
|
45
|
+
else if (loopContext.length && !underTemplate) {
|
|
46
|
+
context = `{${loopContextStr}}`;
|
|
47
|
+
}
|
|
48
|
+
else if (!loopContext.length && underTemplate) {
|
|
49
|
+
context = `{${templateContextStr}}, ${underTemplate}`;
|
|
50
|
+
}
|
|
51
|
+
// 模板字符串包裹的 字符串、表达式 的混合:`foo ${bar} ${visible ? 'show' : 'hide'}`
|
|
52
|
+
// :class="`${runExp(`text`, {...{}, ...runExp(`{text: 'not', visible: false}`)}, '__class__')}`"
|
|
53
|
+
if (type === 1) {
|
|
54
|
+
return `\`${exp.replace(/{{/g, `\${${xhs_mp_compiler_utils_1.COMPILE_CALL_RUNTIME}('${ExecExpWithContext}', \``).replace(/}}/g, `\`, ${context})}`)}\``;
|
|
55
|
+
}
|
|
56
|
+
// 没有模板字符串包裹的:v-if="runExp(`exp`, {item})"
|
|
57
|
+
if (type === 2 || type === 7) {
|
|
58
|
+
return exp.replace(/{{/g, `${xhs_mp_compiler_utils_1.COMPILE_CALL_RUNTIME}('${ExecExpWithContext}', \``).replace(/}}/g, `\`, ${context})`);
|
|
59
|
+
}
|
|
60
|
+
// data-xxx="{{exp}}"
|
|
61
|
+
// :data-xxx="JSON.stringify(`${$__t('x0', `exp`, {})}`)"
|
|
62
|
+
if (type === 3) {
|
|
63
|
+
return `\`${exp.replace(/{{/g, `\${JSON.stringify(${xhs_mp_compiler_utils_1.COMPILE_CALL_RUNTIME}('${ExecExpWithContext}', \``).replace(/}}/g, `\`, ${context}))}`)}\``;
|
|
64
|
+
}
|
|
65
|
+
// text 节点:{{text}} visible => {{$__e(`text`, {...{}, ...$__e(`{text: 'not', visible: true, style}`)})}} visible
|
|
66
|
+
if (type === 4) {
|
|
67
|
+
return exp.replace(/{{(.*?)}}/g, `{{${xhs_mp_compiler_utils_1.COMPILE_CALL_RUNTIME}('${ExecExpWithContext}', \`$1\`, ${context})}}`);
|
|
68
|
+
}
|
|
69
|
+
// data-xxx="abc/{{exp}}"
|
|
70
|
+
// :data-xxx="JSON.stringify(`abc/${$__t('x0', `exp`, {})}`)"
|
|
71
|
+
if (type === 5) {
|
|
72
|
+
return `JSON.stringify(\`${exp.replace(/{{/g, `\${${xhs_mp_compiler_utils_1.COMPILE_CALL_RUNTIME}('${ExecExpWithContext}', \``).replace(/}}/g, `\`, ${context})}`)}\`)`;
|
|
73
|
+
}
|
|
74
|
+
// <template is="xxx" data="{{...item}}" />
|
|
75
|
+
// <template is="xxx" :data="$__t('x0', `{...item}`, {context}})" />
|
|
76
|
+
if (type === 6) {
|
|
77
|
+
return exp.replace(/{{(.*?)}}/g, `${xhs_mp_compiler_utils_1.COMPILE_CALL_RUNTIME}('${ExecExpWithContext}', \`{$1}\`, ${context})`);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
exports.injectContext2Exp = injectContext2Exp;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare const isTemplateDefineNode: (node: any) => any;
|
|
2
|
+
declare const isImportNode: (node: any) => any;
|
|
3
|
+
declare const sortNodes: (nodes: any) => any;
|
|
4
|
+
declare const formatPathToVar: (pathStr: string) => string;
|
|
5
|
+
declare const notifyImport: (type: any) => void;
|
|
6
|
+
declare const isCustomComponent: (tagName: string) => boolean;
|
|
7
|
+
export { isTemplateDefineNode, isImportNode, sortNodes, formatPathToVar, notifyImport, isCustomComponent };
|
|
@@ -0,0 +1,41 @@
|
|
|
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.isCustomComponent = exports.notifyImport = exports.formatPathToVar = exports.sortNodes = exports.isImportNode = exports.isTemplateDefineNode = void 0;
|
|
7
|
+
const tagTransformMap_1 = __importDefault(require("../../../lib/tagTransformMap"));
|
|
8
|
+
const common_1 = require("../../../../utils/common");
|
|
9
|
+
const knownTags = Object.values(tagTransformMap_1.default);
|
|
10
|
+
const isTemplateDefineNode = node => node.name === 'template' && node.attribs.name;
|
|
11
|
+
exports.isTemplateDefineNode = isTemplateDefineNode;
|
|
12
|
+
const isSjsTag = node => ['sjs', 'wxs'].includes(node.name) && node.attribs.name;
|
|
13
|
+
const isImportNode = node => node.name === 'import' && node.attribs.src;
|
|
14
|
+
exports.isImportNode = isImportNode;
|
|
15
|
+
// 将 template name sjs 标签提升
|
|
16
|
+
const sortNodes = nodes => nodes.sort(node => (isTemplateDefineNode(node) || isSjsTag(node) ? -1 : 1));
|
|
17
|
+
exports.sortNodes = sortNodes;
|
|
18
|
+
const pathToVarCache = {};
|
|
19
|
+
// 将路径转换为变量
|
|
20
|
+
const formatPathToVar = (pathStr) => {
|
|
21
|
+
if (!pathToVarCache[pathStr]) {
|
|
22
|
+
pathToVarCache[pathStr] = `C${(0, common_1.md5)(pathStr)}`;
|
|
23
|
+
}
|
|
24
|
+
return pathToVarCache[pathStr];
|
|
25
|
+
};
|
|
26
|
+
exports.formatPathToVar = formatPathToVar;
|
|
27
|
+
let importNotified = false;
|
|
28
|
+
const notifyImport = type => {
|
|
29
|
+
if (!importNotified) {
|
|
30
|
+
// process.send?.(
|
|
31
|
+
// JSON.stringify({
|
|
32
|
+
// message: `检测到代码中使用了 ${type} 标签,基础库从 3.16.4 开始支持,发布小程序时请务必设置最低支持的基础库版本`,
|
|
33
|
+
// method: 'cliNotify',
|
|
34
|
+
// }),
|
|
35
|
+
// )
|
|
36
|
+
}
|
|
37
|
+
importNotified = true;
|
|
38
|
+
};
|
|
39
|
+
exports.notifyImport = notifyImport;
|
|
40
|
+
const isCustomComponent = (tagName) => !knownTags.includes(tagName);
|
|
41
|
+
exports.isCustomComponent = isCustomComponent;
|
|
@@ -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 @@
|
|
|
1
|
+
export declare function generateCodeFrame(source: any, start?: number, end?: any): any;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateCodeFrame = void 0;
|
|
4
|
+
const range = 1;
|
|
5
|
+
function generateCodeFrame(source, start = 0, end = source.length) {
|
|
6
|
+
const lines = source.split(/\r?\n/);
|
|
7
|
+
let count = 0;
|
|
8
|
+
const res = [];
|
|
9
|
+
for (let i = 0; i < lines.length; i++) {
|
|
10
|
+
count += lines[i].length + 1;
|
|
11
|
+
if (count >= start) {
|
|
12
|
+
for (let j = i - range; j <= i + range || end > count; j++) {
|
|
13
|
+
if (j < 0 || j >= lines.length)
|
|
14
|
+
continue;
|
|
15
|
+
// eslint-disable-line
|
|
16
|
+
res.push(`${j + 1}${repeat(` `, 3 - String(j + 1).length)}| ${lines[j]}`); // eslint-disable-line
|
|
17
|
+
const lineLength = lines[j].length;
|
|
18
|
+
if (j === i) {
|
|
19
|
+
// push underline
|
|
20
|
+
const pad = start - (count - lineLength);
|
|
21
|
+
// eslint-disable-line
|
|
22
|
+
res.push(` ` + repeat(` `, pad) + `^`); // eslint-disable-line
|
|
23
|
+
}
|
|
24
|
+
else if (j > i) {
|
|
25
|
+
if (end > count) {
|
|
26
|
+
const length = Math.min(end - count, lineLength);
|
|
27
|
+
res.push(`|` + repeat(`^`, length)); // eslint-disable-line
|
|
28
|
+
}
|
|
29
|
+
count += lineLength + 1;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return res.join("\n");
|
|
36
|
+
}
|
|
37
|
+
exports.generateCodeFrame = generateCodeFrame;
|
|
38
|
+
function repeat(str, n) {
|
|
39
|
+
let result = '';
|
|
40
|
+
if (n > 0) {
|
|
41
|
+
while (true) { // eslint-disable-line
|
|
42
|
+
if (n & 1)
|
|
43
|
+
result += str; // eslint-disable-line
|
|
44
|
+
n >>>= 1; // eslint-disable-line
|
|
45
|
+
if (n <= 0)
|
|
46
|
+
break;
|
|
47
|
+
str += str;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const path_1 = require("path");
|
|
30
|
+
const babel = __importStar(require("@babel/core"));
|
|
31
|
+
const frame_1 = require("./frame");
|
|
32
|
+
const getMlSuffixName_1 = __importDefault(require("../../../utils/getMlSuffixName"));
|
|
33
|
+
const common_1 = require("../../../utils/common");
|
|
34
|
+
const unexpectedIdentifier = ['Date', 'RegExp'];
|
|
35
|
+
const transform = (source, visitor) => babel.transform(source, {
|
|
36
|
+
babelrc: false,
|
|
37
|
+
configFile: false,
|
|
38
|
+
presets: [require.resolve('@babel/preset-env'), require.resolve('babel-preset-minify')],
|
|
39
|
+
plugins: [
|
|
40
|
+
({ types: t }) => ({
|
|
41
|
+
name: 'sjs transform',
|
|
42
|
+
visitor: visitor(t),
|
|
43
|
+
}),
|
|
44
|
+
],
|
|
45
|
+
});
|
|
46
|
+
function sjsLoader(source, sjsPath, miniprogramDir, onRequire) {
|
|
47
|
+
var _a;
|
|
48
|
+
const compilation = this;
|
|
49
|
+
return (_a = transform(source, types => ({
|
|
50
|
+
NewExpression(path) {
|
|
51
|
+
path.traverse({
|
|
52
|
+
Identifier(id) {
|
|
53
|
+
if (unexpectedIdentifier.includes(id.node.name)) {
|
|
54
|
+
const codeFrame = (0, frame_1.generateCodeFrame)(source, id.node.start, id.node.end);
|
|
55
|
+
// eslint-disable-next-line no-console
|
|
56
|
+
const error = new Error(`[ ${(0, getMlSuffixName_1.default)()} 文件编译错误 ] at '${sjsPath.replace(`${miniprogramDir}/`, '')}'\n` +
|
|
57
|
+
`Unexpected identifier '${id.node.name}'\n` +
|
|
58
|
+
`${codeFrame}`);
|
|
59
|
+
// _this.emitError(error)
|
|
60
|
+
compilation.errors.push(error);
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
DebuggerStatement(path) {
|
|
66
|
+
const codeFrame = (0, frame_1.generateCodeFrame)(source, path.node.start, path.node.end);
|
|
67
|
+
const error = new Error(`[ ${(0, getMlSuffixName_1.default)()} 文件编译错误 ] at '${sjsPath.replace(`${miniprogramDir}/`, '')}'\n` +
|
|
68
|
+
`Unexpected identifier 'debugger'\n` +
|
|
69
|
+
`${codeFrame}`);
|
|
70
|
+
compilation.errors.push(error);
|
|
71
|
+
},
|
|
72
|
+
MemberExpression(path) {
|
|
73
|
+
const property = path.node.property;
|
|
74
|
+
const isCtorVisitor = property.name === 'constructor' || property.value === 'constructor';
|
|
75
|
+
if (isCtorVisitor &&
|
|
76
|
+
!(types.isMemberExpression(path.parent) && path.parentKey === 'object')) {
|
|
77
|
+
path.replaceWith(types.logicalExpression('||', types.memberExpression(path.node, types.identifier('name')), path.node));
|
|
78
|
+
path.skip();
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
CallExpression(path) {
|
|
82
|
+
if (path.node.callee.name === 'require') {
|
|
83
|
+
let p = (0, common_1.unixResolve)((0, path_1.dirname)(sjsPath), path.node.arguments[0].value);
|
|
84
|
+
if (onRequire && typeof onRequire === 'function') {
|
|
85
|
+
onRequire(p);
|
|
86
|
+
}
|
|
87
|
+
p = p.replace(`${miniprogramDir}/`, '');
|
|
88
|
+
path.node.arguments[0] = types.stringLiteral(p);
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
}))) === null || _a === void 0 ? void 0 : _a.code;
|
|
92
|
+
}
|
|
93
|
+
module.exports = sjsLoader;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 根据是否分包获取资源路径
|
|
3
|
+
*/
|
|
4
|
+
export declare const getResourceUris: (options: {
|
|
5
|
+
appCssExist: boolean;
|
|
6
|
+
enableLazyCodeLoading: boolean;
|
|
7
|
+
subPackage: any;
|
|
8
|
+
}) => string[];
|
|
9
|
+
/**
|
|
10
|
+
* @NOTE
|
|
11
|
+
* Create a request and handle the conversion of esModule modules
|
|
12
|
+
* */
|
|
13
|
+
export declare function createRequire(modulePath: string): string;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRequire = exports.getResourceUris = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 根据是否分包获取资源路径
|
|
6
|
+
*/
|
|
7
|
+
const getResourceUris = (options) => {
|
|
8
|
+
const resourceList = [];
|
|
9
|
+
const { appCssExist, enableLazyCodeLoading, subPackage } = options;
|
|
10
|
+
// sjs 无法识别是否引用 所以一律push
|
|
11
|
+
// 加载顺序 app.css 主包sjs 分包sjs 主包components.js 分包components.js
|
|
12
|
+
if (!subPackage) {
|
|
13
|
+
// 主包
|
|
14
|
+
appCssExist && resourceList.push(`app.css`);
|
|
15
|
+
resourceList.push('sjs.js');
|
|
16
|
+
!enableLazyCodeLoading && resourceList.push(`components.js`);
|
|
17
|
+
}
|
|
18
|
+
else if (subPackage === null || subPackage === void 0 ? void 0 : subPackage.independent) {
|
|
19
|
+
// 独立分包, 自己的components.js
|
|
20
|
+
resourceList.push(`${subPackage === null || subPackage === void 0 ? void 0 : subPackage.root}/sjs.js`);
|
|
21
|
+
!enableLazyCodeLoading && resourceList.push(`${subPackage === null || subPackage === void 0 ? void 0 : subPackage.root}/components.js`);
|
|
22
|
+
}
|
|
23
|
+
else if (subPackage) {
|
|
24
|
+
// 普通分包, 自己的components.js,主包components.js app.css
|
|
25
|
+
appCssExist && resourceList.push(`app.css`);
|
|
26
|
+
resourceList.push('sjs.js');
|
|
27
|
+
resourceList.push(`${subPackage === null || subPackage === void 0 ? void 0 : subPackage.root}/sjs.js`);
|
|
28
|
+
!enableLazyCodeLoading && resourceList.push(`components.js`);
|
|
29
|
+
!enableLazyCodeLoading && resourceList.push(`${subPackage === null || subPackage === void 0 ? void 0 : subPackage.root}/components.js`);
|
|
30
|
+
}
|
|
31
|
+
return resourceList;
|
|
32
|
+
};
|
|
33
|
+
exports.getResourceUris = getResourceUris;
|
|
34
|
+
/**
|
|
35
|
+
* @NOTE
|
|
36
|
+
* Create a request and handle the conversion of esModule modules
|
|
37
|
+
* */
|
|
38
|
+
function createRequire(modulePath) {
|
|
39
|
+
return `function() { var obj = require('${modulePath}'); return obj && obj.__esModule ? obj.default : obj; }`;
|
|
40
|
+
}
|
|
41
|
+
exports.createRequire = createRequire;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
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 postcss_1 = __importDefault(require("postcss"));
|
|
16
|
+
const postcss_import_1 = __importDefault(require("postcss-import"));
|
|
17
|
+
const postcss_prefix_selector_1 = __importDefault(require("postcss-prefix-selector"));
|
|
18
|
+
const CssSyntaxError_1 = __importDefault(require("css-loader/dist/CssSyntaxError"));
|
|
19
|
+
const tagTransformMap_1 = __importDefault(require("../lib/tagTransformMap"));
|
|
20
|
+
const getCssSuffixName_1 = __importDefault(require("../../utils/getCssSuffixName"));
|
|
21
|
+
const common_1 = require("../../utils/common");
|
|
22
|
+
const tags = Object.keys(tagTransformMap_1.default).join('|');
|
|
23
|
+
const labelStr = `(^|\\s)(${tags}|page|audio|live-player|map|cover-view|cover-image|video)`;
|
|
24
|
+
const labelReg = new RegExp(labelStr, 'g');
|
|
25
|
+
function wxssLoader(source) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
var _a, _b, _c, _d, _e;
|
|
28
|
+
const done = this.async();
|
|
29
|
+
this._compiler.xhsData = this._compiler.xhsData || {};
|
|
30
|
+
const { appJSON = {}, miniprogramDir = '' } = this._compiler.xhsData;
|
|
31
|
+
const shortPath = (0, common_1.getShortPath)(miniprogramDir, this.resourcePath).replace(new RegExp(`\\.${(0, getCssSuffixName_1.default)()}$`), '');
|
|
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
|
+
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
|
+
const selectorIndex = styleIsolation === 'shared' ? 0 : index || 0;
|
|
35
|
+
// js / json 的配置会影响样式
|
|
36
|
+
const extReg = new RegExp(`${(0, getCssSuffixName_1.default)()}$`);
|
|
37
|
+
this.addDependency(this.resourcePath.replace(extReg, 'js'));
|
|
38
|
+
this.addDependency(this.resourcePath.replace(extReg, 'json'));
|
|
39
|
+
(0, postcss_1.default)()
|
|
40
|
+
.use((0, postcss_import_1.default)({ root: miniprogramDir }))
|
|
41
|
+
.use((0, postcss_prefix_selector_1.default)({
|
|
42
|
+
prefix: 'xhs',
|
|
43
|
+
transform(prefix, selector) {
|
|
44
|
+
// 支持 host 选择器 https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html
|
|
45
|
+
if (selector === ':host') {
|
|
46
|
+
return `[is="${shortPath}"]`;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 替换所有类选择器,用于做样式隔离 wiki: https://wiki.xiaohongshu.com/pages/viewpage.action?pageId=181017177
|
|
50
|
+
* .app -> .xhs_0_app
|
|
51
|
+
*/
|
|
52
|
+
selector = selector.replace(/\.(\w)/g, `.xhs_${selectorIndex}_$1`);
|
|
53
|
+
// 为内置组件加上 xhs 前缀
|
|
54
|
+
if (selector.match(labelReg)) {
|
|
55
|
+
selector = selector.replace(labelReg, `$1${prefix}-$2`);
|
|
56
|
+
}
|
|
57
|
+
return selector;
|
|
58
|
+
},
|
|
59
|
+
}))
|
|
60
|
+
.process(source, {
|
|
61
|
+
from: this.resourcePath,
|
|
62
|
+
})
|
|
63
|
+
.then(result => {
|
|
64
|
+
result.messages.forEach(({ file, type }) => {
|
|
65
|
+
if (type === 'dependency') {
|
|
66
|
+
this.addDependency(file);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
done(null, result.css);
|
|
70
|
+
})
|
|
71
|
+
.catch(error => {
|
|
72
|
+
done(error.name === 'CssSyntaxError' ? new CssSyntaxError_1.default(error) : error);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
module.exports = wxssLoader;
|