@ray-js/builder-mp 1.4.3 → 1.4.5-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/package.json +4 -4
- package/lib/babel-plugins/ray-hooks/index.d.ts +0 -14
- package/lib/babel-plugins/ray-hooks/index.js +0 -63
- package/lib/babel-plugins/ray-page-context/__fixtures__/page-anonymous-fn/code.config.d.ts +0 -3
- package/lib/babel-plugins/ray-page-context/__fixtures__/page-anonymous-fn/code.config.js +0 -6
- package/lib/babel-plugins/ray-page-context/__fixtures__/page-fn/code.config.d.ts +0 -3
- package/lib/babel-plugins/ray-page-context/__fixtures__/page-fn/code.config.js +0 -6
- package/lib/babel-plugins/ray-page-context/__fixtures__/page-instance/code.config.d.ts +0 -3
- package/lib/babel-plugins/ray-page-context/__fixtures__/page-instance/code.config.js +0 -6
- package/lib/babel-plugins/ray-page-context/__fixtures__/single/code.config.d.ts +0 -3
- package/lib/babel-plugins/ray-page-context/__fixtures__/single/code.config.js +0 -6
- package/lib/babel-plugins/ray-page-context/app.config.d.ts +0 -3
- package/lib/babel-plugins/ray-page-context/app.config.js +0 -6
- package/lib/babel-plugins/ray-page-context/index.d.ts +0 -17
- package/lib/babel-plugins/ray-page-context/index.js +0 -258
- package/lib/configs/babel.config.d.ts +0 -12
- package/lib/configs/babel.config.js +0 -18
- package/lib/webpack-plugins/AppFrameworkEntry/index.d.ts +0 -13
- package/lib/webpack-plugins/AppFrameworkEntry/index.js +0 -49
- /package/lib/{Builder.d.ts → builder.d.ts} +0 -0
- /package/lib/{Builder.js → builder.js} +0 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ray-js/builder-mp",
|
3
|
-
"version": "1.4.
|
3
|
+
"version": "1.4.5-beta.0",
|
4
4
|
"description": "Ray builder for mini program",
|
5
5
|
"keywords": [
|
6
6
|
"ray"
|
@@ -33,10 +33,10 @@
|
|
33
33
|
"@ray-core/build-store": "^0.3.6",
|
34
34
|
"@ray-core/cli": "^0.3.6",
|
35
35
|
"@ray-core/ray": "^0.3.6",
|
36
|
-
"@ray-js/adapter": "^1.4.
|
36
|
+
"@ray-js/adapter": "^1.4.5-beta.0",
|
37
37
|
"@ray-js/rjs-for-wechat": "^0.0.3",
|
38
|
-
"@ray-js/shared": "^1.4.
|
39
|
-
"@ray-js/types": "^1.4.
|
38
|
+
"@ray-js/shared": "^1.4.5-beta.0",
|
39
|
+
"@ray-js/types": "^1.4.5-beta.0",
|
40
40
|
"babel-loader": "^8.3.0",
|
41
41
|
"babel-plugin-minify-dead-code-elimination": "^0.5.2",
|
42
42
|
"babel-plugin-transform-prune-unused-imports": "^1.0.1",
|
@@ -1,14 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* 1. 替换 usePageEvent 到 @remax/macro
|
3
|
-
*/
|
4
|
-
import { NodePath } from '@babel/traverse';
|
5
|
-
import * as t from '@babel/types';
|
6
|
-
/**
|
7
|
-
* web 构建模式加, 替换到 ray 的运行时 API
|
8
|
-
* @constructor
|
9
|
-
*/
|
10
|
-
export default function RayHooks(): {
|
11
|
-
visitor: {
|
12
|
-
ImportSpecifier(path: NodePath<t.ImportSpecifier>, state: any): void;
|
13
|
-
};
|
14
|
-
};
|
@@ -1,63 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
/**
|
3
|
-
* 1. 替换 usePageEvent 到 @remax/macro
|
4
|
-
*/
|
5
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
6
|
-
if (k2 === undefined) k2 = k;
|
7
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
8
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
9
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
10
|
-
}
|
11
|
-
Object.defineProperty(o, k2, desc);
|
12
|
-
}) : (function(o, m, k, k2) {
|
13
|
-
if (k2 === undefined) k2 = k;
|
14
|
-
o[k2] = m[k];
|
15
|
-
}));
|
16
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
17
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
18
|
-
}) : function(o, v) {
|
19
|
-
o["default"] = v;
|
20
|
-
});
|
21
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
22
|
-
if (mod && mod.__esModule) return mod;
|
23
|
-
var result = {};
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
25
|
-
__setModuleDefault(result, mod);
|
26
|
-
return result;
|
27
|
-
};
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
-
const t = __importStar(require("@babel/types"));
|
30
|
-
function insertImport(program, imports, moduleName) {
|
31
|
-
const specifiers = imports.map((i) => t.importSpecifier(t.identifier(i), t.identifier(i)));
|
32
|
-
const importDeclaration = t.importDeclaration(specifiers, t.stringLiteral(moduleName));
|
33
|
-
program.unshiftContainer('body', importDeclaration);
|
34
|
-
}
|
35
|
-
/**
|
36
|
-
* web 构建模式加, 替换到 ray 的运行时 API
|
37
|
-
* @constructor
|
38
|
-
*/
|
39
|
-
function RayHooks() {
|
40
|
-
return {
|
41
|
-
visitor: {
|
42
|
-
ImportSpecifier(path, state) {
|
43
|
-
const program = state.file.path;
|
44
|
-
const { node } = path;
|
45
|
-
const name = node.local.name;
|
46
|
-
if (['usePageEvent', 'useAppEvent'].includes(name) &&
|
47
|
-
t.isImportDeclaration(path.parentPath)) {
|
48
|
-
const { node } = path.parentPath;
|
49
|
-
if (node.source.value === 'ray') {
|
50
|
-
if (node.specifiers.length > 1) {
|
51
|
-
path.remove();
|
52
|
-
insertImport(program, [name], `@remax/macro`);
|
53
|
-
}
|
54
|
-
else {
|
55
|
-
node.source.value = '@remax/macro';
|
56
|
-
}
|
57
|
-
}
|
58
|
-
}
|
59
|
-
},
|
60
|
-
},
|
61
|
-
};
|
62
|
-
}
|
63
|
-
exports.default = RayHooks;
|
@@ -1,17 +0,0 @@
|
|
1
|
-
import { NodePath } from '@babel/traverse';
|
2
|
-
import * as t from '@babel/types';
|
3
|
-
/**
|
4
|
-
* 1. 增加小程序运行时 context appConfig pageConfig 的导入, 并共享到 PageInstanceContext 上
|
5
|
-
* 2. 或增加 withPage 的依赖项
|
6
|
-
* 3. 早于 ray-hooks 执行
|
7
|
-
* @param _ babel
|
8
|
-
* @param options compileOptions
|
9
|
-
* @constructor
|
10
|
-
*/
|
11
|
-
export default function ContextAndHoc(): {
|
12
|
-
pre(state: any): void;
|
13
|
-
visitor: {
|
14
|
-
ExportDefaultDeclaration(path: NodePath<t.ExportDefaultDeclaration>, state: any): void;
|
15
|
-
};
|
16
|
-
post(state: any): void;
|
17
|
-
};
|
@@ -1,258 +0,0 @@
|
|
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 change_case_1 = require("change-case");
|
30
|
-
const fs_1 = __importDefault(require("fs"));
|
31
|
-
const P = __importStar(require("path"));
|
32
|
-
const slash_1 = __importDefault(require("slash"));
|
33
|
-
const template_1 = __importDefault(require("@babel/template"));
|
34
|
-
const t = __importStar(require("@babel/types"));
|
35
|
-
const shared_1 = require("@ray-js/shared");
|
36
|
-
const Builder_1 = require("../../Builder");
|
37
|
-
function insertSpecifierImport(program, imports, moduleName) {
|
38
|
-
const specifiers = imports.map((i) => t.importSpecifier(t.identifier(i), t.identifier(i)));
|
39
|
-
const importDeclaration = t.importDeclaration(specifiers, t.stringLiteral(moduleName));
|
40
|
-
program.unshiftContainer('body', importDeclaration);
|
41
|
-
}
|
42
|
-
const contextTemplate = (0, template_1.default)(`const id = forwardRef((props, ref) => {
|
43
|
-
const isClassType = (c) => c.prototype && typeof c.prototype.render === 'function';
|
44
|
-
const $instance = new PageInstance();
|
45
|
-
usePageEvent('onLoad', () => {
|
46
|
-
lifecycle.addInstance($instance);
|
47
|
-
lifecycle.emit({ name: 'onLoad', uniqueId: $instance.uniqueId })
|
48
|
-
});
|
49
|
-
usePageEvent('onUnload', () => {
|
50
|
-
lifecycle.emit({ name: 'onUnload', uniqueId: $instance.uniqueId })
|
51
|
-
lifecycle.removeInstance($instance);
|
52
|
-
});
|
53
|
-
usePageEvent('onShow', () => {
|
54
|
-
lifecycle.emit({ name: 'onShow', uniqueId: $instance.uniqueId })
|
55
|
-
});
|
56
|
-
return (
|
57
|
-
<PageInstanceContext.Provider value={{
|
58
|
-
$instance: $instance,
|
59
|
-
}}
|
60
|
-
>
|
61
|
-
{isClassType(compName) ? <compTag ref={ref} {...props}/> : <compTag {...props}/> }
|
62
|
-
</PageInstanceContext.Provider>
|
63
|
-
);
|
64
|
-
});`, {
|
65
|
-
plugins: ['jsx'],
|
66
|
-
syntacticPlaceholders: false,
|
67
|
-
placeholderWhitelist: new Set(['id', 'compTag', 'compName', 'platform']),
|
68
|
-
placeholderPattern: false,
|
69
|
-
});
|
70
|
-
const pageConfigTemplate = (0, template_1.default)(`const __pageConfig = require("file");
|
71
|
-
const __pageConfigData = __pageConfig.platform ? {...__pageConfig.platform} : __pageConfig.default ? {...__pageConfig.default} : {}
|
72
|
-
`, {
|
73
|
-
syntacticPlaceholders: false,
|
74
|
-
placeholderWhitelist: new Set(['file', 'platform']),
|
75
|
-
placeholderPattern: false,
|
76
|
-
});
|
77
|
-
const appConfigTemplate = (0, template_1.default)(`import __appConfig from 'file';
|
78
|
-
const __appConfigData = __appConfig.platform || __appConfig || {};
|
79
|
-
`, {
|
80
|
-
syntacticPlaceholders: false,
|
81
|
-
placeholderWhitelist: new Set(['file', 'platform']),
|
82
|
-
placeholderPattern: false,
|
83
|
-
});
|
84
|
-
function insertPageConfig(program, filename) {
|
85
|
-
const pageDir = P.dirname(filename);
|
86
|
-
const importBasename = P.basename(filename, P.extname(filename));
|
87
|
-
const pageConfigPath = (0, shared_1.searchJSFile)(`${importBasename}.config`, {
|
88
|
-
cwd: pageDir,
|
89
|
-
});
|
90
|
-
if (fs_1.default.existsSync(pageConfigPath)) {
|
91
|
-
const file = (0, shared_1.replaceExtension)(`./${P.relative(pageDir, pageConfigPath)}`);
|
92
|
-
const ast = pageConfigTemplate({
|
93
|
-
file: t.stringLiteral(file),
|
94
|
-
platform: t.identifier(process.env.PLATFORM),
|
95
|
-
});
|
96
|
-
program.unshiftContainer('body', ast);
|
97
|
-
}
|
98
|
-
else {
|
99
|
-
program.unshiftContainer('body', t.variableDeclaration('const', [
|
100
|
-
t.variableDeclarator(t.identifier('__pageConfigData'), t.objectExpression([])),
|
101
|
-
]));
|
102
|
-
}
|
103
|
-
return true;
|
104
|
-
}
|
105
|
-
function insertAppConfig(program, filename) {
|
106
|
-
const pageDir = P.dirname(filename);
|
107
|
-
const sourceDir = P.join(Builder_1.builder.options.cwd, Builder_1.builder.options.source);
|
108
|
-
const appConfigPath = (0, shared_1.searchJSFile)('app.config', {
|
109
|
-
cwd: sourceDir,
|
110
|
-
});
|
111
|
-
if (fs_1.default.existsSync(appConfigPath)) {
|
112
|
-
const file = (0, shared_1.replaceExtension)(P.relative(pageDir, appConfigPath));
|
113
|
-
const ast = appConfigTemplate({
|
114
|
-
file: t.stringLiteral(file),
|
115
|
-
platform: t.identifier(process.env.PLATFORM),
|
116
|
-
});
|
117
|
-
program.unshiftContainer('body', ast);
|
118
|
-
}
|
119
|
-
else {
|
120
|
-
program.unshiftContainer('body', t.variableDeclaration('const', [
|
121
|
-
t.variableDeclarator(t.identifier('__appConfigData'), t.objectExpression([])),
|
122
|
-
]));
|
123
|
-
}
|
124
|
-
return true;
|
125
|
-
}
|
126
|
-
let appConfig = null;
|
127
|
-
function getAppConfig() {
|
128
|
-
if (appConfig)
|
129
|
-
return appConfig;
|
130
|
-
const sourceDir = P.join(Builder_1.builder.options.cwd, Builder_1.builder.options.source);
|
131
|
-
const appConfigPath = (0, shared_1.searchJSFile)('app.config', {
|
132
|
-
cwd: sourceDir,
|
133
|
-
});
|
134
|
-
if (fs_1.default.existsSync(appConfigPath)) {
|
135
|
-
appConfig = require(appConfigPath);
|
136
|
-
}
|
137
|
-
return appConfig || { pageWrapper: '' };
|
138
|
-
}
|
139
|
-
const { target } = Builder_1.builder.options;
|
140
|
-
const { [target]: { pageWrapper }, } = getAppConfig();
|
141
|
-
/**
|
142
|
-
* 1. 增加小程序运行时 context appConfig pageConfig 的导入, 并共享到 PageInstanceContext 上
|
143
|
-
* 2. 或增加 withPage 的依赖项
|
144
|
-
* 3. 早于 ray-hooks 执行
|
145
|
-
* @param _ babel
|
146
|
-
* @param options compileOptions
|
147
|
-
* @constructor
|
148
|
-
*/
|
149
|
-
function ContextAndHoc() {
|
150
|
-
let entries = [];
|
151
|
-
let isPage;
|
152
|
-
let exportDefaultDeclarationName;
|
153
|
-
return {
|
154
|
-
pre(state) {
|
155
|
-
exportDefaultDeclarationName = '';
|
156
|
-
entries = Object.keys(Builder_1.builder.entry);
|
157
|
-
const sourceDir = (0, slash_1.default)(P.join(Builder_1.builder.options.cwd, Builder_1.builder.options.source));
|
158
|
-
const filename = (0, slash_1.default)(state.opts.filename);
|
159
|
-
const fileName = P.relative(sourceDir, filename);
|
160
|
-
const fileEntryName = fileName.replace(P.extname(fileName), '');
|
161
|
-
isPage = fileEntryName.toLowerCase() !== 'app' && entries.some((e) => e === fileEntryName);
|
162
|
-
},
|
163
|
-
visitor: {
|
164
|
-
ExportDefaultDeclaration(path, state) {
|
165
|
-
if (!isPage)
|
166
|
-
return;
|
167
|
-
const { node } = path;
|
168
|
-
const program = state.file.path;
|
169
|
-
const importer = state.filename;
|
170
|
-
if (pageWrapper && pageWrapper.length) {
|
171
|
-
insertPageConfig(program, importer);
|
172
|
-
if (typeof pageWrapper === 'string') {
|
173
|
-
insertSpecifierImport(program, ['default as RayPageWrapper'], pageWrapper);
|
174
|
-
}
|
175
|
-
else {
|
176
|
-
let i = 0;
|
177
|
-
pageWrapper.forEach((element) => {
|
178
|
-
insertSpecifierImport(program, [`default as RayPageWrapper${i++}`], element);
|
179
|
-
});
|
180
|
-
}
|
181
|
-
}
|
182
|
-
// 导出的引用是一个 FunctionComponent 才进行运行时包裹
|
183
|
-
let pageName = 'default';
|
184
|
-
if (t.isIdentifier(node.declaration)) {
|
185
|
-
pageName = node.declaration.name;
|
186
|
-
path.remove();
|
187
|
-
}
|
188
|
-
else if (t.isFunctionDeclaration(node.declaration)) {
|
189
|
-
if (node.declaration.id) {
|
190
|
-
pageName = node.declaration.id.name;
|
191
|
-
}
|
192
|
-
else {
|
193
|
-
const [_, n] = importer.split(P.sep).reverse();
|
194
|
-
pageName = path.scope.generateUid((0, change_case_1.pascalCase)(n));
|
195
|
-
}
|
196
|
-
const pageFn = t.functionExpression(t.identifier(pageName), node.declaration.params, node.declaration.body);
|
197
|
-
path.replaceWith(t.variableDeclaration('const', [t.variableDeclarator(t.identifier(pageName), pageFn)]));
|
198
|
-
}
|
199
|
-
else if (t.isClassDeclaration(node.declaration)) {
|
200
|
-
if (node.declaration.id) {
|
201
|
-
pageName = node.declaration.id.name;
|
202
|
-
path.replaceWith(node.declaration);
|
203
|
-
}
|
204
|
-
else {
|
205
|
-
const [_, n] = importer.split(P.sep).reverse();
|
206
|
-
pageName = path.scope.generateUid((0, change_case_1.pascalCase)(n));
|
207
|
-
path.replaceWith(t.classDeclaration(t.identifier(pageName), node.declaration.superClass, node.declaration.body, node.declaration.decorators));
|
208
|
-
}
|
209
|
-
}
|
210
|
-
else {
|
211
|
-
pageName = path.scope.generateUid(pageName);
|
212
|
-
path.replaceWith(t.variableDeclaration('const', [
|
213
|
-
// @ts-ignore
|
214
|
-
t.variableDeclarator(t.identifier(pageName), node.declaration),
|
215
|
-
]));
|
216
|
-
}
|
217
|
-
const id = path.scope.generateUid(pageName);
|
218
|
-
const ast = contextTemplate({
|
219
|
-
id: t.identifier(id),
|
220
|
-
compTag: t.jsxIdentifier(pageName),
|
221
|
-
compName: t.identifier(pageName),
|
222
|
-
});
|
223
|
-
if (pageWrapper && pageWrapper.length) {
|
224
|
-
if (typeof pageWrapper === 'string') {
|
225
|
-
exportDefaultDeclarationName = `RayPageWrapper(${id}, __pageConfigData);`;
|
226
|
-
}
|
227
|
-
else {
|
228
|
-
let ename = id;
|
229
|
-
for (let i = 0; i < pageWrapper.length; i++) {
|
230
|
-
ename = `RayPageWrapper${i}(` + ename + ', __pageConfigData)';
|
231
|
-
}
|
232
|
-
ename += ';';
|
233
|
-
exportDefaultDeclarationName = ename;
|
234
|
-
}
|
235
|
-
}
|
236
|
-
else {
|
237
|
-
exportDefaultDeclarationName = id;
|
238
|
-
}
|
239
|
-
program.pushContainer('body', ast);
|
240
|
-
const rayImportSpecifiers = ['PageInstanceContext', 'PageInstance', 'lifecycle'];
|
241
|
-
['usePageEvent', 'router', 'location'].forEach((key) => {
|
242
|
-
if (!path.scope.hasBinding(key)) {
|
243
|
-
rayImportSpecifiers.push(key);
|
244
|
-
}
|
245
|
-
});
|
246
|
-
insertSpecifierImport(program, rayImportSpecifiers, 'ray');
|
247
|
-
insertSpecifierImport(program, ['forwardRef'], 'react');
|
248
|
-
},
|
249
|
-
},
|
250
|
-
post(state) {
|
251
|
-
const program = state.path;
|
252
|
-
if (exportDefaultDeclarationName) {
|
253
|
-
program.pushContainer('body', t.exportDefaultDeclaration(t.identifier(exportDefaultDeclarationName)));
|
254
|
-
}
|
255
|
-
},
|
256
|
-
};
|
257
|
-
}
|
258
|
-
exports.default = ContextAndHoc;
|
@@ -1,18 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
function babelConfig(api) {
|
4
|
-
api.cache(true);
|
5
|
-
return {
|
6
|
-
presets: [
|
7
|
-
[
|
8
|
-
require.resolve('babel-preset-remax'),
|
9
|
-
{ typescript: true, decorators: { legacy: true }, classProperties: { loose: true } },
|
10
|
-
],
|
11
|
-
],
|
12
|
-
plugins: [
|
13
|
-
require.resolve('babel-plugin-minify-dead-code-elimination'),
|
14
|
-
require.resolve('babel-plugin-transform-prune-unused-imports'),
|
15
|
-
],
|
16
|
-
};
|
17
|
-
}
|
18
|
-
exports.default = babelConfig;
|
@@ -1,13 +0,0 @@
|
|
1
|
-
import VirtualModules from 'webpack-virtual-modules';
|
2
|
-
import { Compiler } from 'webpack';
|
3
|
-
/**
|
4
|
-
* 小程序框架启动, 在文件顶部增加 .ray/main.mini 的适配
|
5
|
-
* 读取 TabBar 信息,注册页面到 router 上。实现 web 路由的跳转
|
6
|
-
*/
|
7
|
-
export default class AppFrameworkEntry {
|
8
|
-
virtualModules: VirtualModules;
|
9
|
-
source: string;
|
10
|
-
appFile: string;
|
11
|
-
constructor(appFile: string);
|
12
|
-
apply(compiler: Compiler): void;
|
13
|
-
}
|
@@ -1,49 +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 webpack_virtual_modules_1 = __importDefault(require("webpack-virtual-modules"));
|
16
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
17
|
-
const PLUGIN_NAME = `AppFrameworkEntry`;
|
18
|
-
const AppFrameworkTemplate = function (source) {
|
19
|
-
return `import 'ray/main';
|
20
|
-
${source}`;
|
21
|
-
};
|
22
|
-
/**
|
23
|
-
* 小程序框架启动, 在文件顶部增加 .ray/main.mini 的适配
|
24
|
-
* 读取 TabBar 信息,注册页面到 router 上。实现 web 路由的跳转
|
25
|
-
*/
|
26
|
-
class AppFrameworkEntry {
|
27
|
-
constructor(appFile) {
|
28
|
-
this.virtualModules = new webpack_virtual_modules_1.default();
|
29
|
-
this.source = ``;
|
30
|
-
this.appFile = appFile;
|
31
|
-
}
|
32
|
-
apply(compiler) {
|
33
|
-
const { context } = compiler.options;
|
34
|
-
compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => __awaiter(this, void 0, void 0, function* () {
|
35
|
-
this.virtualModules.apply(compiler);
|
36
|
-
const appSource = yield fs_extra_1.default.readFile(this.appFile).then((b) => b.toString());
|
37
|
-
const newSource = appSource;
|
38
|
-
if (newSource !== this.source) {
|
39
|
-
this.source = newSource;
|
40
|
-
this.virtualModules.writeModule(this.appFile, AppFrameworkTemplate(this.source));
|
41
|
-
}
|
42
|
-
callback();
|
43
|
-
}));
|
44
|
-
compiler.hooks.afterCompile.tap(PLUGIN_NAME, (compilation) => {
|
45
|
-
compilation.fileDependencies.add(this.appFile);
|
46
|
-
});
|
47
|
-
}
|
48
|
-
}
|
49
|
-
exports.default = AppFrameworkEntry;
|
File without changes
|
File without changes
|