@ray-js/builder-mp 1.3.1 → 1.3.99-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/lib/build.worker.d.ts +1 -0
- package/lib/build.worker.js +61 -13
- package/package.json +10 -10
package/lib/build.worker.d.ts
CHANGED
package/lib/build.worker.js
CHANGED
@@ -8,6 +8,7 @@ const path_1 = __importDefault(require("path"));
|
|
8
8
|
const colors_1 = __importDefault(require("colors"));
|
9
9
|
const shared_1 = require("@ray-js/shared");
|
10
10
|
const legacyExport_1 = require("@ray-core/cli/lib/legacyExport");
|
11
|
+
const slash_1 = __importDefault(require("slash"));
|
11
12
|
const builder_1 = require("./builder");
|
12
13
|
const onBuildEnd_1 = __importDefault(require("./plugins/onBuildEnd"));
|
13
14
|
const utils_1 = require("./utils");
|
@@ -15,6 +16,7 @@ colors_1.default.enable();
|
|
15
16
|
const extensions = ['.mjs', '.js', '.jsx', '.ts', '.tsx'];
|
16
17
|
const moduleMatcher = new RegExp(`(${extensions.join('|')})$`);
|
17
18
|
const LOG_PREFIX_WORKER = 'build-worker';
|
19
|
+
const BUILD_WORKER_PLUGIN = `${LOG_PREFIX_WORKER}-plugin`;
|
18
20
|
const innerPlugins = [(0, onBuildEnd_1.default)(LOG_PREFIX_WORKER)];
|
19
21
|
class WorkerBuild {
|
20
22
|
constructor(options, parent) {
|
@@ -47,12 +49,13 @@ class WorkerBuild {
|
|
47
49
|
.options({
|
48
50
|
configFile: path_1.default.resolve(__dirname, './babel/configs/babel.config.js'),
|
49
51
|
});
|
52
|
+
const { root } = this.readConfig();
|
50
53
|
config.output
|
51
54
|
.set('filename', '[name].js')
|
52
55
|
.set('libraryTarget', 'commonjs2')
|
53
56
|
.set('clean', false)
|
54
57
|
.set('globalObject', 'worker')
|
55
|
-
.set('path', output)
|
58
|
+
.set('path', root ? path_1.default.join(output, root) : output)
|
56
59
|
.set('publicPath', '/')
|
57
60
|
.end()
|
58
61
|
.optimization.set('runtimeChunk', { name: 'runtime-worker' })
|
@@ -77,29 +80,39 @@ class WorkerBuild {
|
|
77
80
|
'process.env.PLATFORM': JSON.stringify(target),
|
78
81
|
},
|
79
82
|
])
|
83
|
+
.end()
|
84
|
+
.plugin(BUILD_WORKER_PLUGIN)
|
85
|
+
.use(BuildWorkerPlugin)
|
80
86
|
.end()
|
81
87
|
.watchOptions({ aggregateTimeout: 1000 });
|
82
88
|
innerPlugins.forEach((p) => p.configWebpack({ config }));
|
83
89
|
config.resolve.merge(this.parent.options.resolve);
|
84
90
|
return config.toConfig();
|
85
91
|
}
|
92
|
+
readConfig() {
|
93
|
+
this.routesConfigFile = builder_1.builder.api.searchJSFile('src/routes.config');
|
94
|
+
if (!this.routesConfigFile) {
|
95
|
+
shared_1.log.error(LOG_PREFIX_WORKER, `missing configuration file (routes.config.{ts|js})`);
|
96
|
+
return {};
|
97
|
+
}
|
98
|
+
delete require.cache[this.routesConfigFile];
|
99
|
+
const data = builder_1.builder.api.requireJSFile(this.routesConfigFile).workers || {};
|
100
|
+
const { root } = data;
|
101
|
+
if (!root) {
|
102
|
+
shared_1.log.verbose(LOG_PREFIX_WORKER, `missing prop 'workers' in ${this.routesConfigFile}`);
|
103
|
+
return {};
|
104
|
+
}
|
105
|
+
return data;
|
106
|
+
}
|
86
107
|
initWorkerBuilder() {
|
87
108
|
const cfg = this.createWebpackConfig();
|
88
109
|
cfg.entry = () => {
|
89
|
-
|
90
|
-
if (!this.routesConfigFile) {
|
91
|
-
shared_1.log.error(LOG_PREFIX_WORKER, `missing configuration file (routes.config.{ts|js})`);
|
92
|
-
return {};
|
93
|
-
}
|
94
|
-
delete require.cache[this.routesConfigFile];
|
95
|
-
const { root, workers = [] } = builder_1.builder.api.requireJSFile(this.routesConfigFile).workers || {};
|
96
|
-
if (!root) {
|
97
|
-
shared_1.log.verbose(LOG_PREFIX_WORKER, `missing prop 'workers' in ${this.routesConfigFile}`);
|
98
|
-
return {};
|
99
|
-
}
|
110
|
+
const { root, workers = [] } = this.readConfig();
|
100
111
|
const entries = workers.reduce((o, k) => {
|
101
112
|
const { source: rootDir, target, cwd } = this.options;
|
102
113
|
const name = path_1.default.join(root, k);
|
114
|
+
const ext = path_1.default.extname(k);
|
115
|
+
const outputName = k.replace(new RegExp(`${ext}$`), '');
|
103
116
|
const f = path_1.default.join(cwd, rootDir, name);
|
104
117
|
const m = (0, utils_1.getModuleOfPlatform)(f, {
|
105
118
|
rootDir,
|
@@ -108,7 +121,7 @@ class WorkerBuild {
|
|
108
121
|
extensions: ['ts', 'js', 'tsx', 'jsx'],
|
109
122
|
});
|
110
123
|
if (m) {
|
111
|
-
o[
|
124
|
+
o[outputName] = m[1];
|
112
125
|
}
|
113
126
|
else {
|
114
127
|
shared_1.log.warn(LOG_PREFIX_WORKER, `Can't resolve module ${k} in ${root}`);
|
@@ -175,3 +188,38 @@ class WorkerBuild {
|
|
175
188
|
}
|
176
189
|
}
|
177
190
|
exports.default = WorkerBuild;
|
191
|
+
const { ConcatSource } = legacyExport_1.customWebpack.sources;
|
192
|
+
class BuildWorkerPlugin {
|
193
|
+
apply(compiler) {
|
194
|
+
compiler.hooks.thisCompilation.tap(BUILD_WORKER_PLUGIN, (compilation) => {
|
195
|
+
compilation.hooks.processAssets.tapAsync({
|
196
|
+
name: BUILD_WORKER_PLUGIN,
|
197
|
+
stage: legacyExport_1.customWebpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
|
198
|
+
}, (chunks, callback) => {
|
199
|
+
compilation.chunkGroups.forEach((group) => {
|
200
|
+
group.chunks.reverse().forEach((chunk) => {
|
201
|
+
this.requireChunks(compilation, chunk, group);
|
202
|
+
});
|
203
|
+
});
|
204
|
+
callback();
|
205
|
+
});
|
206
|
+
});
|
207
|
+
}
|
208
|
+
requireChunks(compilation, chunk, group) {
|
209
|
+
var _a;
|
210
|
+
// require 相关的 chunk
|
211
|
+
if (chunk.name !== group.name) {
|
212
|
+
const requires = [];
|
213
|
+
const files = Array.from(chunk.files);
|
214
|
+
files.forEach((file) => {
|
215
|
+
if (file.endsWith('.js')) {
|
216
|
+
const relativePath = (0, slash_1.default)(path_1.default.relative(path_1.default.dirname(group.name), file));
|
217
|
+
requires.push(`require('./${relativePath}');\n`);
|
218
|
+
}
|
219
|
+
});
|
220
|
+
const assetPath = group.name + '.js';
|
221
|
+
const source = (_a = compilation.assets[assetPath]) !== null && _a !== void 0 ? _a : '';
|
222
|
+
compilation.assets[assetPath] = new ConcatSource(...requires, source);
|
223
|
+
}
|
224
|
+
}
|
225
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ray-js/builder-mp",
|
3
|
-
"version": "1.3.
|
3
|
+
"version": "1.3.99-beta.0",
|
4
4
|
"description": "Ray builder for mini program",
|
5
5
|
"keywords": [
|
6
6
|
"ray"
|
@@ -26,14 +26,14 @@
|
|
26
26
|
"@babel/template": "^7.16.0",
|
27
27
|
"@babel/traverse": "^7.16.3",
|
28
28
|
"@babel/types": "^7.16.0",
|
29
|
-
"@ray-core/babel-preset-remax": "^0.3.
|
30
|
-
"@ray-core/build-store": "^0.3.
|
31
|
-
"@ray-core/cli": "^0.3.
|
32
|
-
"@ray-core/ray": "^0.3.
|
33
|
-
"@ray-js/adapter": "^1.3.
|
29
|
+
"@ray-core/babel-preset-remax": "^0.3.1",
|
30
|
+
"@ray-core/build-store": "^0.3.1",
|
31
|
+
"@ray-core/cli": "^0.3.1",
|
32
|
+
"@ray-core/ray": "^0.3.1",
|
33
|
+
"@ray-js/adapter": "^1.3.99-beta.0",
|
34
34
|
"@ray-js/rjs-for-wechat": "^0.0.3",
|
35
|
-
"@ray-js/shared": "^1.3.
|
36
|
-
"@ray-js/types": "^1.3.
|
35
|
+
"@ray-js/shared": "^1.3.99-beta.0",
|
36
|
+
"@ray-js/types": "^1.3.99-beta.0",
|
37
37
|
"babel-loader": "^8.2.3",
|
38
38
|
"babel-plugin-minify-dead-code-elimination": "^0.5.1",
|
39
39
|
"babel-plugin-transform-prune-unused-imports": "^1.0.1",
|
@@ -50,7 +50,7 @@
|
|
50
50
|
"webpack-virtual-modules": "^0.4.4"
|
51
51
|
},
|
52
52
|
"devDependencies": {
|
53
|
-
"@ray-core/types": "^0.3.
|
53
|
+
"@ray-core/types": "^0.3.1",
|
54
54
|
"@types/jest": "^27.0.2",
|
55
55
|
"@types/node": "^16.9.1",
|
56
56
|
"babel-plugin-tester": "^10.1.0",
|
@@ -64,6 +64,6 @@
|
|
64
64
|
"email": "tuyafe@tuya.com"
|
65
65
|
}
|
66
66
|
],
|
67
|
-
"gitHead": "
|
67
|
+
"gitHead": "55e5b53442b4d17914c437b101e15e485ec4aebe",
|
68
68
|
"repository": {}
|
69
69
|
}
|