xhs-mp-compiler-cli 1.0.1-beta.1 → 1.0.1-beta.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.js +0 -2
- package/dist/bin/xhs-mp-cli-dev.js +0 -3
- package/dist/index.js +7 -11
- package/dist/types/index.d.ts +1 -5
- package/dist/webpack-config/lib/postcssRpx2Vw.d.ts +0 -1
- package/dist/webpack-config/lib/postcssRpx2Vw.js +12 -17
- package/dist/webpack-config/loaders/mini-style-loader.js +3 -3
- package/dist/webpack-config/loaders/sjs-loader/index.d.ts +12 -1
- package/dist/webpack-config/loaders/sjs-loader/index.js +602 -86
- 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/presets/prod.js +3 -5
- package/dist/webpack-config/presets/render/RenderChunkPlugin.d.ts +0 -4
- package/dist/webpack-config/presets/render/RenderChunkPlugin.js +7 -22
- package/dist/webpack-config/presets/render/SjsEntryPlugin.js +47 -11
- package/dist/webpack-config/presets/render/index.js +12 -49
- package/dist/webpack-config/presets/service/XhsMpServiceChunkPlugin.js +2 -2
- package/dist/webpack-config/presets/service/index.js +1 -0
- package/package.json +4 -4
- package/dist/webpack-config/loaders/ml-loader/index.d.ts +0 -3
- package/dist/webpack-config/loaders/ml-loader/index.js +0 -66
- package/dist/webpack-config/loaders/ml-loader/ml2vue/generator.d.ts +0 -2
- package/dist/webpack-config/loaders/ml-loader/ml2vue/generator.js +0 -107
- package/dist/webpack-config/loaders/ml-loader/ml2vue/index.d.ts +0 -6
- package/dist/webpack-config/loaders/ml-loader/ml2vue/index.js +0 -64
- package/dist/webpack-config/loaders/ml-loader/ml2vue/injectScript.d.ts +0 -11
- package/dist/webpack-config/loaders/ml-loader/ml2vue/injectScript.js +0 -41
- package/dist/webpack-config/loaders/ml-loader/ml2vue/injectTemplate.d.ts +0 -2
- package/dist/webpack-config/loaders/ml-loader/ml2vue/injectTemplate.js +0 -18
- package/dist/webpack-config/loaders/ml-loader/ml2vue/parser.d.ts +0 -2
- package/dist/webpack-config/loaders/ml-loader/ml2vue/parser.js +0 -21
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformer.d.ts +0 -7
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformer.js +0 -185
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBindAttribute.d.ts +0 -2
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBindAttribute.js +0 -73
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBlockTag.d.ts +0 -13
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBlockTag.js +0 -42
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleCatchAttribute.d.ts +0 -2
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleCatchAttribute.js +0 -30
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleClassAttribute.d.ts +0 -2
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleClassAttribute.js +0 -17
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleDataAttribute.d.ts +0 -2
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleDataAttribute.js +0 -23
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleHiddenAttribute.d.ts +0 -13
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleHiddenAttribute.js +0 -25
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleImportTag.d.ts +0 -4
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleImportTag.js +0 -30
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleIncludeTag.d.ts +0 -2
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleIncludeTag.js +0 -30
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleLoopAttribute.d.ts +0 -2
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleLoopAttribute.js +0 -89
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleMLAttribute.d.ts +0 -2
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleMLAttribute.js +0 -33
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleModelAttribute.d.ts +0 -2
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleModelAttribute.js +0 -61
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleOtherAttribute.d.ts +0 -2
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleOtherAttribute.js +0 -35
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSjsEvent.d.ts +0 -11
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSjsEvent.js +0 -72
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSlotAttribute.d.ts +0 -2
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSlotAttribute.js +0 -74
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSpaceAttribute.d.ts +0 -2
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSpaceAttribute.js +0 -12
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleStyleAttribute.d.ts +0 -2
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleStyleAttribute.js +0 -16
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/utils.d.ts +0 -10
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/utils.js +0 -80
- package/dist/webpack-config/loaders/ml-loader/ml2vue/utils.d.ts +0 -7
- package/dist/webpack-config/loaders/ml-loader/ml2vue/utils.js +0 -41
- package/dist/webpack-config/loaders/sjs-loader/frame.d.ts +0 -1
- package/dist/webpack-config/loaders/sjs-loader/frame.js +0 -51
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Span, Identifier } from '@swc/core';
|
|
2
|
+
export declare const SPECIFY_VAR: string[];
|
|
3
|
+
declare module "@swc/core" {
|
|
4
|
+
interface Identifier {
|
|
5
|
+
_xhsScope?: Scope;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export declare class Scope {
|
|
9
|
+
private parentScope;
|
|
10
|
+
private defines;
|
|
11
|
+
private access;
|
|
12
|
+
toString(): string;
|
|
13
|
+
/**
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
anlysis(): {
|
|
17
|
+
variable: string;
|
|
18
|
+
span: Span;
|
|
19
|
+
} | undefined;
|
|
20
|
+
checkGlobal(key: string): boolean;
|
|
21
|
+
setAccess(key: string, value: Span): void;
|
|
22
|
+
setDefines(key: string, value: Span): void;
|
|
23
|
+
setParentScope(scope: Scope | undefined): void;
|
|
24
|
+
}
|
|
25
|
+
export declare class ScopeManager {
|
|
26
|
+
private _scopeStack;
|
|
27
|
+
private _scopeTables;
|
|
28
|
+
private _stop;
|
|
29
|
+
stop(): void;
|
|
30
|
+
enterScope(): void;
|
|
31
|
+
exitScope(): void;
|
|
32
|
+
getCurrentScope(): Scope | undefined;
|
|
33
|
+
pushIdentifier(id: Identifier): void;
|
|
34
|
+
pushAccess(id: Identifier): void;
|
|
35
|
+
getDFSScope(): Scope[];
|
|
36
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScopeManager = exports.Scope = exports.SPECIFY_VAR = void 0;
|
|
4
|
+
exports.SPECIFY_VAR = ["getDate", "getRegExp", "console"];
|
|
5
|
+
const IDENTIFIER_WHITE_LIST = [
|
|
6
|
+
"Object", "Boolean", "Array", "String", "Number", "Date", "Map", "Set",
|
|
7
|
+
"decodeURI", "decodeURIComponent", "encodeURI", "encodeURIComponent", "isNaN", "isFinite", "parseFloat", "parseInt",
|
|
8
|
+
"Infinity", "NaN", "undefined",
|
|
9
|
+
"setTimeout", "clearTimeout", "setInterval", "clearInterval",
|
|
10
|
+
"JSON", "Math",
|
|
11
|
+
// 模块化
|
|
12
|
+
"module", "require", "exports",
|
|
13
|
+
...exports.SPECIFY_VAR
|
|
14
|
+
];
|
|
15
|
+
// 变量作用域表
|
|
16
|
+
class Scope {
|
|
17
|
+
constructor() {
|
|
18
|
+
// 当前作用域定义的变量
|
|
19
|
+
this.defines = {};
|
|
20
|
+
// 当前作用域使用的变量
|
|
21
|
+
this.access = {};
|
|
22
|
+
}
|
|
23
|
+
toString() {
|
|
24
|
+
return `defines: ${Object.keys(this.defines)} access: ${Object.keys(this.access)}`;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
anlysis() {
|
|
30
|
+
// TODO 优化算法复杂度
|
|
31
|
+
// 在自身作用域 以及 上级作用域寻找,找到顶层作用域时 则需要看 白名单是否含有
|
|
32
|
+
for (const variable in this.access) {
|
|
33
|
+
// 白名单也不包含此变量
|
|
34
|
+
if (this.checkGlobal(variable) && !IDENTIFIER_WHITE_LIST.includes(variable)) {
|
|
35
|
+
return { variable, span: this.access[variable] };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
// 检查是否是全局调用
|
|
41
|
+
checkGlobal(key) {
|
|
42
|
+
let scope = this;
|
|
43
|
+
while (scope) {
|
|
44
|
+
if (!scope.defines[key]) {
|
|
45
|
+
scope = scope.parentScope;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return !scope;
|
|
53
|
+
}
|
|
54
|
+
setAccess(key, value) {
|
|
55
|
+
this.access[key] = value;
|
|
56
|
+
}
|
|
57
|
+
setDefines(key, value) {
|
|
58
|
+
this.defines[key] = value;
|
|
59
|
+
}
|
|
60
|
+
setParentScope(scope) {
|
|
61
|
+
this.parentScope = scope;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.Scope = Scope;
|
|
65
|
+
class ScopeManager {
|
|
66
|
+
constructor() {
|
|
67
|
+
// 栈帧
|
|
68
|
+
this._scopeStack = [];
|
|
69
|
+
// 栈 深度遍历结果
|
|
70
|
+
this._scopeTables = [];
|
|
71
|
+
// 是否停止收集
|
|
72
|
+
this._stop = false;
|
|
73
|
+
}
|
|
74
|
+
// 停止分析
|
|
75
|
+
stop() {
|
|
76
|
+
this._stop = true;
|
|
77
|
+
}
|
|
78
|
+
enterScope() {
|
|
79
|
+
if (this._stop)
|
|
80
|
+
return;
|
|
81
|
+
this._scopeStack.push(new Scope());
|
|
82
|
+
}
|
|
83
|
+
exitScope() {
|
|
84
|
+
if (this._stop)
|
|
85
|
+
return;
|
|
86
|
+
const scope = this._scopeStack.pop();
|
|
87
|
+
if (scope) {
|
|
88
|
+
this._scopeTables.push(scope);
|
|
89
|
+
scope.setParentScope(this.getCurrentScope());
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
getCurrentScope() {
|
|
93
|
+
if (this._stop)
|
|
94
|
+
return;
|
|
95
|
+
return this._scopeStack[this._scopeStack.length - 1];
|
|
96
|
+
}
|
|
97
|
+
// 记录定义的值
|
|
98
|
+
pushIdentifier(id) {
|
|
99
|
+
var _a;
|
|
100
|
+
if (this._stop)
|
|
101
|
+
return;
|
|
102
|
+
if (this.getCurrentScope()) {
|
|
103
|
+
(_a = this.getCurrentScope()) === null || _a === void 0 ? void 0 : _a.setDefines(id.value, id.span);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// 记录使用的值
|
|
107
|
+
pushAccess(id) {
|
|
108
|
+
if (this._stop)
|
|
109
|
+
return;
|
|
110
|
+
const current = this.getCurrentScope();
|
|
111
|
+
if (current) {
|
|
112
|
+
current === null || current === void 0 ? void 0 : current.setAccess(id.value, id.span);
|
|
113
|
+
if (exports.SPECIFY_VAR.includes(id.value)) {
|
|
114
|
+
id._xhsScope = current;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
getDFSScope() {
|
|
119
|
+
return this._scopeTables;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.ScopeManager = ScopeManager;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transform = void 0;
|
|
4
|
+
const core_1 = require("@swc/core");
|
|
5
|
+
const transform = (code, plugin, target = 'esnext', minify = false) => (0, core_1.transformSync)(code, {
|
|
6
|
+
swcrc: false,
|
|
7
|
+
configFile: false,
|
|
8
|
+
minify,
|
|
9
|
+
sourceMaps: false,
|
|
10
|
+
jsc: {
|
|
11
|
+
preserveAllComments: true,
|
|
12
|
+
target,
|
|
13
|
+
// minify: false,
|
|
14
|
+
externalHelpers: false,
|
|
15
|
+
parser: {
|
|
16
|
+
syntax: "ecmascript",
|
|
17
|
+
jsx: false,
|
|
18
|
+
dynamicImport: false,
|
|
19
|
+
privateMethod: false,
|
|
20
|
+
functionBind: false,
|
|
21
|
+
classPrivateProperty: false,
|
|
22
|
+
exportDefaultFrom: false,
|
|
23
|
+
exportNamespaceFrom: false,
|
|
24
|
+
decorators: false,
|
|
25
|
+
decoratorsBeforeExport: false,
|
|
26
|
+
importMeta: false,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
plugin,
|
|
30
|
+
});
|
|
31
|
+
exports.transform = transform;
|
|
@@ -7,6 +7,7 @@ const const_1 = __importDefault(require("../lib/const"));
|
|
|
7
7
|
// import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
|
|
8
8
|
const getProdConfig = (chain, options) => {
|
|
9
9
|
chain.mode('production');
|
|
10
|
+
chain.devtool(false);
|
|
10
11
|
if (!options.noJs) {
|
|
11
12
|
// 生产环境使用 babel-loader
|
|
12
13
|
chain.module
|
|
@@ -40,13 +41,10 @@ const getProdConfig = (chain, options) => {
|
|
|
40
41
|
.options({
|
|
41
42
|
sourceType: 'unambiguous',
|
|
42
43
|
presets: [
|
|
43
|
-
[
|
|
44
|
-
require.resolve('@babel/preset-typescript'),
|
|
45
|
-
{
|
|
44
|
+
[require.resolve('@babel/preset-typescript'), {
|
|
46
45
|
allExtensions: true,
|
|
47
46
|
isTSX: true,
|
|
48
|
-
},
|
|
49
|
-
],
|
|
47
|
+
}],
|
|
50
48
|
[
|
|
51
49
|
require.resolve('@babel/preset-env'),
|
|
52
50
|
{
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const webpack_1 = require("webpack");
|
|
4
4
|
const webpack_sources_1 = require("webpack-sources");
|
|
5
|
-
const runtimeName = 'runtime.render.js';
|
|
6
5
|
const injectCSS = `
|
|
6
|
+
globalThis.__XHS_IS_WEBVIEW = (globalThis.localStorage && document && document.getElementsByTagName)
|
|
7
7
|
globalThis.__XHS_APPEND_CSS = function(cssText){
|
|
8
|
+
if (!globalThis.__XHS_IS_WEBVIEW) return;
|
|
8
9
|
var headTags = document.getElementsByTagName('head')
|
|
9
10
|
var head = document.head || (headTags && headTags[0])
|
|
10
11
|
var cssTextNode = document.createTextNode(String(cssText))
|
|
@@ -15,36 +16,20 @@ globalThis.__XHS_APPEND_CSS = function(cssText){
|
|
|
15
16
|
`;
|
|
16
17
|
// 注入css跟webpack runtime
|
|
17
18
|
class RenderChunkPlugin {
|
|
18
|
-
constructor(options) {
|
|
19
|
-
this.enableVDom = options.enableVDom;
|
|
20
|
-
}
|
|
21
19
|
apply(compiler) {
|
|
22
20
|
compiler.hooks.compilation.tap(RenderChunkPlugin.name, compilation => {
|
|
23
21
|
compilation.hooks.processAssets.tap({
|
|
24
22
|
name: RenderChunkPlugin.name,
|
|
25
23
|
stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
|
|
26
24
|
}, (assets) => {
|
|
27
|
-
var _a, _b
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// 向前兼容旧架构
|
|
31
|
-
injectCode = injectCSS;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
const runtimeCode = (_a = compilation.getAsset(runtimeName)) === null || _a === void 0 ? void 0 : _a.source.source();
|
|
35
|
-
// 注入css逻辑
|
|
36
|
-
injectCode = `
|
|
37
|
-
${injectCSS}
|
|
38
|
-
if (!globalThis.__XHS_RUNTIME_REGISTERED__) {
|
|
39
|
-
globalThis.__XHS_RUNTIME_REGISTERED__ = true;
|
|
40
|
-
${runtimeCode}
|
|
41
|
-
};`;
|
|
42
|
-
}
|
|
25
|
+
var _a, _b;
|
|
26
|
+
// 注入css逻辑
|
|
27
|
+
const injectCode = injectCSS;
|
|
43
28
|
// @ts-ignore
|
|
44
29
|
const appJSON = compiler.xhsData.appJSON;
|
|
45
30
|
const pathMap = [
|
|
46
|
-
(
|
|
47
|
-
(
|
|
31
|
+
(_a = appJSON.pages) === null || _a === void 0 ? void 0 : _a.map(({ path }) => path),
|
|
32
|
+
(_b = appJSON.subPackages) === null || _b === void 0 ? void 0 : _b.map(sub => { var _a; return (_a = sub.pages) === null || _a === void 0 ? void 0 : _a.map(({ path }) => path); })
|
|
48
33
|
].flat(4).filter(Boolean)
|
|
49
34
|
.reduce((ac, path) => {
|
|
50
35
|
ac[`v1/${path}.render.js`] = true;
|
|
@@ -1,14 +1,37 @@
|
|
|
1
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
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
29
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
7
30
|
const glob_1 = __importDefault(require("glob"));
|
|
31
|
+
const path_1 = __importDefault(require("path"));
|
|
8
32
|
const webpack_sources_1 = require("webpack-sources");
|
|
9
33
|
const webpack_1 = require("webpack");
|
|
10
|
-
|
|
11
|
-
const sjs_loader_1 = __importDefault(require("../../loaders/sjs-loader"));
|
|
34
|
+
const index_1 = __importStar(require("../../loaders/sjs-loader/index"));
|
|
12
35
|
const common_1 = require("../../../utils/common");
|
|
13
36
|
function formatSJSPath(i) {
|
|
14
37
|
if (/\.(sjs|wxs)$/.test(i)) {
|
|
@@ -51,7 +74,8 @@ class SjsEntryPlugin {
|
|
|
51
74
|
this.subPackageRoots.forEach(root => {
|
|
52
75
|
this.subPackagePaths.has(root) || this.subPackagePaths.set(root, []);
|
|
53
76
|
});
|
|
54
|
-
const relativePaths = glob_1.default.sync('**/*.sjs', { cwd: miniprogramDir })
|
|
77
|
+
const relativePaths = glob_1.default.sync('**/*.sjs', { cwd: miniprogramDir })
|
|
78
|
+
.concat(glob_1.default.sync('**/*.wxs', { cwd: miniprogramDir }));
|
|
55
79
|
relativePaths.forEach(relativePath => {
|
|
56
80
|
var _a;
|
|
57
81
|
const sjsAbsPath = (0, common_1.unixJoin)(miniprogramDir, relativePath);
|
|
@@ -79,6 +103,7 @@ class SjsEntryPlugin {
|
|
|
79
103
|
});
|
|
80
104
|
}
|
|
81
105
|
makeSjsFileContent(compilation, chunkName, sjsFiles = [], sjsModuleName, pkgRoot) {
|
|
106
|
+
var _a;
|
|
82
107
|
const sjsModules = [];
|
|
83
108
|
// 用于去除重复引入
|
|
84
109
|
const sjsPathCache = new Set();
|
|
@@ -94,23 +119,34 @@ class SjsEntryPlugin {
|
|
|
94
119
|
continue;
|
|
95
120
|
}
|
|
96
121
|
const sjsAbsPath = formatSJSPath(sjsPath);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const relativePath =
|
|
122
|
+
const content = fs_extra_1.default.readFileSync(sjsAbsPath, 'utf8');
|
|
123
|
+
const result = index_1.default.call(compilation, content, requirePath => {
|
|
124
|
+
const realPath = (0, common_1.unixResolve)(path_1.default.dirname(sjsAbsPath), requirePath);
|
|
125
|
+
const relativePath = (0, common_1.getShortPath)(this.miniprogramDir, realPath);
|
|
101
126
|
/**
|
|
102
127
|
* 不是当前分包的 sjs 文件不处理
|
|
103
128
|
*/
|
|
104
129
|
if (pkgRoot && !relativePath.startsWith(pkgRoot)) {
|
|
105
|
-
throw new
|
|
130
|
+
throw new Error(`require(${JSON.stringify(requirePath)}),请检测引入路径是否正确或符合分包规则!`);
|
|
106
131
|
}
|
|
107
|
-
|
|
132
|
+
if (!fs_extra_1.default.existsSync(realPath)) {
|
|
133
|
+
throw new Error(`require(${JSON.stringify(requirePath)}) file does not exist`);
|
|
134
|
+
}
|
|
135
|
+
sjsFiles.push(realPath);
|
|
136
|
+
return relativePath;
|
|
108
137
|
});
|
|
109
|
-
|
|
138
|
+
if ((_a = result.errors) === null || _a === void 0 ? void 0 : _a.length) {
|
|
139
|
+
throw new webpack_1.WebpackError(`[SJS 文件编译错误] ${sjsAbsPath}\n${result.errors.map(i => i.message).join("\n")}`);
|
|
140
|
+
}
|
|
141
|
+
const moduleName = (0, common_1.getShortPath)(this.miniprogramDir, sjsAbsPath);
|
|
142
|
+
// 老版本兼容代码
|
|
143
|
+
sjsModules.push(`"${moduleName}": ${JSON.stringify(result.legacyCode)}`);
|
|
144
|
+
// 模块化代码
|
|
145
|
+
sjsModules.push(`".sjs#${moduleName}": function(exports,require,module,${index_1.SJS_HELPER}){${(result.code)};return module;}`);
|
|
110
146
|
// 处理后的加入缓存
|
|
111
147
|
sjsPathCache.add(sjsPath);
|
|
112
148
|
}
|
|
113
|
-
const source = new webpack_sources_1.ConcatSource(`globalThis['${sjsModuleName}'] = {`, `${sjsModules.join('
|
|
149
|
+
const source = new webpack_sources_1.ConcatSource(`globalThis['${sjsModuleName}'] = {`, `${sjsModules.join(',\n')}`, '}');
|
|
114
150
|
if (this.enableV1) {
|
|
115
151
|
// @ts-ignore
|
|
116
152
|
compilation.assets[`v1/${chunkName}`] = source;
|
|
@@ -3,12 +3,9 @@ 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
|
-
const webpack_1 = __importDefault(require("webpack"));
|
|
7
|
-
const VueLoaderPlugin_1 = __importDefault(require("../../plugins/VueLoaderPlugin"));
|
|
8
6
|
const XhsMpJsonPlugin_1 = __importDefault(require("../../plugins/XhsMpJsonPlugin"));
|
|
9
7
|
const RenderEntryPlugin_1 = __importDefault(require("./RenderEntryPlugin"));
|
|
10
8
|
const ComponentEntryPlugin_1 = __importDefault(require("./ComponentEntryPlugin"));
|
|
11
|
-
const XhsMpErrorTransformPlugin_1 = __importDefault(require("../../plugins/XhsMpErrorTransformPlugin"));
|
|
12
9
|
const css_1 = __importDefault(require("../../lib/css"));
|
|
13
10
|
const types_1 = require("../../../types");
|
|
14
11
|
const getMlSuffixName_1 = __importDefault(require("../../../utils/getMlSuffixName"));
|
|
@@ -26,41 +23,22 @@ const getBaseConfig = (chain, options) => {
|
|
|
26
23
|
path: options.distDir,
|
|
27
24
|
filename: '[name].render.js',
|
|
28
25
|
globalObject: 'globalThis',
|
|
26
|
+
uniqueName: 'MpRender',
|
|
29
27
|
},
|
|
30
28
|
module: {
|
|
31
29
|
rule: {
|
|
32
|
-
ml:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
'
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
transformAssetUrls: { tags: {} },
|
|
41
|
-
compilerOptions: {
|
|
42
|
-
isCustomElement: tag => ['xhs-page', 'xhs-template'].includes(tag),
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
'ml-loader': {
|
|
47
|
-
loader: require.resolve('../../loaders/ml-loader'),
|
|
48
|
-
options,
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
}
|
|
52
|
-
: {
|
|
53
|
-
test: mlReg,
|
|
54
|
-
use: {
|
|
55
|
-
'ml-loader': {
|
|
56
|
-
loader: require.resolve('xhs-mp-compiler-ml-loader'),
|
|
57
|
-
options: {
|
|
58
|
-
removeComentNode: isProd,
|
|
59
|
-
vdom: enableVDom,
|
|
60
|
-
},
|
|
30
|
+
ml: {
|
|
31
|
+
test: mlReg,
|
|
32
|
+
use: {
|
|
33
|
+
'ml-loader': {
|
|
34
|
+
loader: require.resolve('xhs-mp-compiler-ml-loader'),
|
|
35
|
+
options: {
|
|
36
|
+
removeComentNode: isProd,
|
|
37
|
+
vdom: enableVDom,
|
|
61
38
|
},
|
|
62
39
|
},
|
|
63
40
|
},
|
|
41
|
+
},
|
|
64
42
|
[(0, getCssSuffixName_1.default)()]: {
|
|
65
43
|
test: cssReg,
|
|
66
44
|
use: (0, css_1.default)(options, [
|
|
@@ -78,22 +56,7 @@ const getBaseConfig = (chain, options) => {
|
|
|
78
56
|
// 渲染层
|
|
79
57
|
chain.plugin('XhsMpEntryPlugin').use(RenderEntryPlugin_1.default, [{ enableV1, enableV2 }]);
|
|
80
58
|
chain.plugin('SjsEntryPlugin').use(SjsEntryPlugin_1.default, [{ miniprogramDir, enableV1, enableV2 }]);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
chain.plugin('XhsMpErrorTransformPlugin').use(XhsMpErrorTransformPlugin_1.default);
|
|
84
|
-
chain.plugin('DefinePlugin').use(webpack_1.default.DefinePlugin, [
|
|
85
|
-
{
|
|
86
|
-
__VUE_PROD_DEVTOOLS__: JSON.stringify(false),
|
|
87
|
-
__VUE_OPTIONS_API__: JSON.stringify(true),
|
|
88
|
-
},
|
|
89
|
-
]);
|
|
90
|
-
}
|
|
91
|
-
if (!enableVDom) {
|
|
92
|
-
// 抽取runtime
|
|
93
|
-
chain.optimization.runtimeChunk({
|
|
94
|
-
name: 'runtime', // runtime.render.js
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
chain.plugin("RenderChunkPlugin").use(RenderChunkPlugin_1.default, [{ enableVDom }]);
|
|
59
|
+
// 公共模块
|
|
60
|
+
chain.plugin("RenderChunkPlugin").use(RenderChunkPlugin_1.default);
|
|
98
61
|
};
|
|
99
62
|
exports.default = getBaseConfig;
|
|
@@ -16,8 +16,8 @@ class XhsMpServiceChunkPlugin {
|
|
|
16
16
|
// 当没有引用相同 js 场景时, commonChunk 将是 undefined
|
|
17
17
|
const commonSource = ((_c = compilation.getAsset('service-common.js')) === null || _c === void 0 ? void 0 : _c.source) || '';
|
|
18
18
|
runtimeCode = `
|
|
19
|
-
if (!globalThis.
|
|
20
|
-
globalThis.
|
|
19
|
+
if (!globalThis.__XHS_SERVICE_RUNTIME_REGISTERED__) {
|
|
20
|
+
globalThis.__XHS_SERVICE_RUNTIME_REGISTERED__ = true;
|
|
21
21
|
${runtimeCode}
|
|
22
22
|
}`;
|
|
23
23
|
// 独立分包加入 runtimeChunk
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xhs-mp-compiler-cli",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
3
|
+
"version": "1.0.1-beta.2",
|
|
4
4
|
"description": "xhs mp command tool.",
|
|
5
5
|
"preferGlobal": true,
|
|
6
6
|
"category": "esm",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"@swc/core": "^1.3.74",
|
|
34
34
|
"@swc/helpers": "^0.5.1",
|
|
35
35
|
"@vue/babel-preset-jsx": "^1.2.4",
|
|
36
|
-
"xhs-mp-compiler-core-fork": "1.0.1-beta.
|
|
37
|
-
"xhs-mp-compiler-ml-loader": "1.0.1-beta.
|
|
38
|
-
"xhs-mp-compiler-utils": "1.0.1-beta.
|
|
36
|
+
"xhs-mp-compiler-core-fork": "1.0.1-beta.2",
|
|
37
|
+
"xhs-mp-compiler-ml-loader": "1.0.1-beta.2",
|
|
38
|
+
"xhs-mp-compiler-utils": "1.0.1-beta.2",
|
|
39
39
|
"babel-loader": "^8.2.2",
|
|
40
40
|
"babel-plugin-istanbul": "^6.0.0",
|
|
41
41
|
"babel-preset-minify": "^0.4.3",
|
|
@@ -1,66 +0,0 @@
|
|
|
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 fs_extra_1 = __importDefault(require("fs-extra"));
|
|
16
|
-
const ml2vue_1 = __importDefault(require("./ml2vue"));
|
|
17
|
-
const getCssSuffixName_1 = __importDefault(require("../../../utils/getCssSuffixName"));
|
|
18
|
-
const getMlSuffixName_1 = __importDefault(require("../../../utils/getMlSuffixName"));
|
|
19
|
-
const common_1 = require("../../../utils/common");
|
|
20
|
-
const isCustomComponents = (filePath) => {
|
|
21
|
-
try {
|
|
22
|
-
const json = JSON.parse(fs_extra_1.default.readFileSync(`${filePath}.json`, 'utf-8'));
|
|
23
|
-
return json.component;
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
function mlLoader(source) {
|
|
30
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
32
|
-
const callback = this.async();
|
|
33
|
-
try {
|
|
34
|
-
const { resourcePath, _compiler, resourceQuery } = this;
|
|
35
|
-
// @ts-ignore
|
|
36
|
-
const xhsData = (_compiler === null || _compiler === void 0 ? void 0 : _compiler.xhsData) || {};
|
|
37
|
-
const shortPath = (0, common_1.getShortPath)(xhsData.miniprogramDir, resourcePath);
|
|
38
|
-
const styleIsolation = (_d = (_c = (_b = (_a = xhsData.appJSON) === null || _a === void 0 ? void 0 : _a.componentsMap) === null || _b === void 0 ? void 0 : _b[shortPath]) === null || _c === void 0 ? void 0 : _c.styleIsolation) !== null && _d !== void 0 ? _d : null;
|
|
39
|
-
const componentIndex = styleIsolation === 'shared' ? 0 : (_h = (_g = (_f = (_e = xhsData.appJSON) === null || _e === void 0 ? void 0 : _e.componentsMap) === null || _f === void 0 ? void 0 : _f[shortPath]) === null || _g === void 0 ? void 0 : _g.index) !== null && _h !== void 0 ? _h : null;
|
|
40
|
-
const reg = new RegExp(`.${(0, getMlSuffixName_1.default)()}$`);
|
|
41
|
-
const filePath = (0, common_1.toUnixPath)(resourcePath.replace(reg, ''));
|
|
42
|
-
// 收集 imports / includes
|
|
43
|
-
const importMap = {};
|
|
44
|
-
const includeMap = {};
|
|
45
|
-
// 收集 sjs module name
|
|
46
|
-
const sjsScopeNames = [];
|
|
47
|
-
const res = yield (0, ml2vue_1.default)(this, xhsData.miniprogramDir, source, shortPath, filePath, importMap, includeMap, isCustomComponents(filePath), componentIndex, resourceQuery, sjsScopeNames);
|
|
48
|
-
if (fs_extra_1.default.existsSync(`${filePath}.${(0, getCssSuffixName_1.default)()}`)) {
|
|
49
|
-
this.addDependency(`${filePath}.${(0, getCssSuffixName_1.default)()}`);
|
|
50
|
-
}
|
|
51
|
-
// fse.writeFileSync(`${__dirname}/.testTemp.vue`, res)
|
|
52
|
-
// if (/catchTapTest/g.test(res)) {
|
|
53
|
-
// fse.writeFileSync(`${__dirname}/.testTemp.vue`, res)
|
|
54
|
-
// }
|
|
55
|
-
// if (res.includes('include')) {
|
|
56
|
-
// fse.writeFileSync(`${__dirname}/.testTemp.vue`, res)
|
|
57
|
-
// debugger
|
|
58
|
-
// }
|
|
59
|
-
callback(null, res);
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
callback(error);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
exports.default = mlLoader;
|