@ray-js/builder-mp 0.10.2 → 0.20.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -152,13 +152,24 @@ function ContextAndHoc() {
152
152
  let exportDefaultDeclarationName;
153
153
  return {
154
154
  pre(state) {
155
+ isPage = false;
155
156
  exportDefaultDeclarationName = '';
156
157
  entries = Object.keys(builder_1.builder.entry);
157
158
  const sourceDir = (0, slash_1.default)(P.join(builder_1.builder.options.cwd, builder_1.builder.options.source));
158
159
  const filename = (0, slash_1.default)(state.opts.filename);
159
160
  const fileName = P.relative(sourceDir, filename);
160
- const fileEntryName = fileName.replace(P.extname(fileName), '');
161
- isPage = fileEntryName.toLowerCase() !== 'app' && entries.some((e) => e === fileEntryName);
161
+ const ext = P.extname(fileName);
162
+ const entryNames = ['.mini', `.${builder_1.builder.options.target}`, ''].map((x) => fileName.replace(`${x}${ext}`, ''));
163
+ for (const p of entryNames) {
164
+ if (p.toLowerCase() === 'app')
165
+ return;
166
+ for (const e of entries) {
167
+ if (e === p) {
168
+ isPage = true;
169
+ return;
170
+ }
171
+ }
172
+ }
162
173
  },
163
174
  visitor: {
164
175
  ExportDefaultDeclaration(path, state) {
package/lib/build.js CHANGED
@@ -32,11 +32,18 @@ const defaultCompileOptions = {
32
32
  devtools: false,
33
33
  debug: false,
34
34
  output: 'dist',
35
+ blended: false,
35
36
  };
36
37
  function build(options, context) {
37
38
  return __awaiter(this, void 0, void 0, function* () {
38
39
  const { api } = context;
39
- let compileOptions = Object.assign({}, defaultCompileOptions, options);
40
+ const cfgFromRayConfigFile = Object.keys(defaultCompileOptions).reduce((o, k) => {
41
+ if (k in api.config) {
42
+ o[k] = api.config[k];
43
+ }
44
+ return o;
45
+ }, {});
46
+ let compileOptions = Object.assign({}, defaultCompileOptions, cfgFromRayConfigFile, options);
40
47
  const { cwd, target, output, devtools } = compileOptions;
41
48
  /**
42
49
  * 又是历史原因
package/lib/build.rjs.js CHANGED
@@ -105,6 +105,7 @@ class RjsBuilder {
105
105
  .end() // rjs模块需要导出给minipack 使用,蹩脚
106
106
  .optimization.runtimeChunk({ name: 'runtime-rjs' })
107
107
  .splitChunks({ cacheGroups });
108
+ cfg.output.delete('libraryExport');
108
109
  cfg.output.set('clean', false);
109
110
  const config = cfg.toConfig();
110
111
  config.entry = () => this.entries;
@@ -1,5 +1,29 @@
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
  Object.defineProperty(exports, "__esModule", { value: true });
26
+ const babel = __importStar(require("@babel/core"));
3
27
  // TODO 动态生成app.config.ts文件还是会造成二次编译,待优化
4
28
  // 原有实现方案会造成二次编译,导致编译性能下降
5
29
  // https://registry.code.tuya-inc.top/godzilla/ray-monorepo/-/blob/3bb0c0754881b4bc0ebdb4540f628c941bfb3be8/packages/builder-mp/src/webpack/plugins/AppFrameworkEntry/index.ts
@@ -13,11 +37,44 @@ function configWebpack(context) {
13
37
  if (thePlugin._staticModules) {
14
38
  const file = Object.keys(thePlugin._staticModules).find((name) => /\/?app\./.test(name));
15
39
  const source = thePlugin._staticModules[file];
16
- const content = `import '@ray-js/ray/main';${source}`;
40
+ const content = `
41
+ import router from '@ray-js/ray/main';
42
+ ${updateCode(source, file)};
43
+ function reOverloadNativeAppConstructor(config) {
44
+ const app = overloadNativeAppConstructor(config);
45
+ return function(opts) {
46
+ const cfg = app(opts);
47
+ cfg.asSubPackageRuntimeOptions && router.setUrlPrefix(cfg.asSubPackageRuntimeOptions.subPackageRoot);
48
+ return cfg;
49
+ }
50
+ }
51
+ `;
17
52
  thePlugin._staticModules[file] = content;
18
53
  plugin.set('plugin', thePlugin);
19
54
  }
20
55
  }
56
+ function updateCode(code, name) {
57
+ const opts = {
58
+ plugins: [
59
+ function () {
60
+ return {
61
+ visitor: {
62
+ Identifier(path) {
63
+ if (path.parent.type === 'CallExpression' &&
64
+ path.node.name === 'overloadNativeAppConstructor') {
65
+ path.node.name = 'reOverloadNativeAppConstructor';
66
+ }
67
+ },
68
+ },
69
+ };
70
+ },
71
+ ],
72
+ sourceFileName: name,
73
+ filename: name,
74
+ };
75
+ const res = babel.transformSync(code, opts);
76
+ return res === null || res === void 0 ? void 0 : res.code;
77
+ }
21
78
  exports.default = {
22
79
  name: 'app-entry-wrapper',
23
80
  configWebpack,
@@ -26,7 +26,7 @@ exports.default = {
26
26
  configWebpack(context) {
27
27
  const { config } = context;
28
28
  const { target } = builder_1.builder.options;
29
- // alias('ray', '@ray-js/ray', config)
29
+ alias('ray', '@ray-js/ray', config);
30
30
  // 修改 mini-css-extract-plugin 的配置
31
31
  config.plugin('mini-css-extract-plugin').tap(([options]) => [Object.assign(Object.assign({}, options), { ignoreOrder: true })]);
32
32
  // 收敛 babel.config 配置
package/lib/ray-core.js CHANGED
@@ -25,22 +25,25 @@ const less_1 = __importDefault(require("./plugins/less"));
25
25
  const resolve_legacy_1 = __importDefault(require("./plugins/resolve-legacy"));
26
26
  const builder_1 = require("./builder");
27
27
  const _a = (0, legacyExport_1.getDefaultOptions)(), { UNSAFE_wechatTemplateDepth } = _a, remaxDefaultOptions = __rest(_a, ["UNSAFE_wechatTemplateDepth"]);
28
- const defaultTemplateDepth = {
29
- swiper: 3,
30
- text: 1,
31
- ad: -1,
32
- 'match-media': -1,
33
- 'page-container': -1,
34
- 'share-element': -1,
35
- 'keyboard-accessory': -1,
36
- 'voip-room': -1,
37
- 'ad-custom': -1,
38
- 'page-meta': -1,
39
- 'navigation-bar': -1,
40
- };
28
+ const isThing = process.env.PLATFORM === 'thing';
29
+ const defaultTemplateDepth = isThing
30
+ ? {
31
+ swiper: 3,
32
+ text: 1,
33
+ ad: -1,
34
+ 'match-media': -1,
35
+ 'page-container': -1,
36
+ 'share-element': -1,
37
+ 'keyboard-accessory': -1,
38
+ 'voip-room': -1,
39
+ 'ad-custom': -1,
40
+ 'page-meta': -1,
41
+ 'navigation-bar': -1,
42
+ }
43
+ : {};
41
44
  const innerPlugins = [resolve_legacy_1.default, app_entry_1.default, less_1.default, resolve_alias_1.default];
42
45
  function getRayCoreOptions(rjsBuilder) {
43
- const { cwd, source, watch, target, mini, analyze, output } = builder_1.builder.options;
46
+ const { cwd, source, watch, target, mini, analyze, output, blended } = builder_1.builder.options;
44
47
  const api = builder_1.builder.api;
45
48
  const injectWebpackConfigToRjs = {
46
49
  configWebpack({ config }) {
@@ -51,7 +54,8 @@ function getRayCoreOptions(rjsBuilder) {
51
54
  const plugins = innerPlugins.concat(api.plugins, injectWebpackConfigToRjs);
52
55
  const remaxBuildConfig = Object.assign(Object.assign({}, remaxDefaultOptions), { UNSAFE_wechatTemplateDepth: Object.assign(UNSAFE_wechatTemplateDepth, defaultTemplateDepth), compressTemplate: mini, pxToRpx: false, minimize: mini, analyze,
53
56
  cwd, loglevel: 'warn', rootDir: source, target, output: path_1.default.relative(cwd, output), watch,
54
- plugins });
57
+ plugins,
58
+ blended });
55
59
  return remaxBuildConfig;
56
60
  }
57
61
  exports.getRayCoreOptions = getRayCoreOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/builder-mp",
3
- "version": "0.10.2",
3
+ "version": "0.20.0-beta.0",
4
4
  "description": "Ray builder for mini program",
5
5
  "keywords": [
6
6
  "ray"
@@ -24,14 +24,14 @@
24
24
  "@babel/template": "^7.16.0",
25
25
  "@babel/traverse": "^7.16.3",
26
26
  "@babel/types": "^7.16.0",
27
- "@ray-core/babel-preset-remax": "^0.1.3",
28
- "@ray-core/build-store": "^0.1.3",
29
- "@ray-core/cli": "^0.1.3",
30
- "@ray-core/ray": "^0.1.3",
31
- "@ray-js/adapter": "^0.10.2",
27
+ "@ray-core/babel-preset-remax": "^0.2.0-beta.3",
28
+ "@ray-core/build-store": "^0.2.0-beta.3",
29
+ "@ray-core/cli": "^0.2.0-beta.3",
30
+ "@ray-core/ray": "^0.2.0-beta.3",
31
+ "@ray-js/adapter": "^0.20.0-beta.0",
32
32
  "@ray-js/rjs-for-wechat": "^0.0.3",
33
- "@ray-js/shared": "^0.10.2",
34
- "@ray-js/types": "^0.10.2",
33
+ "@ray-js/shared": "^0.20.0-beta.0",
34
+ "@ray-js/types": "^0.20.0-beta.0",
35
35
  "babel-loader": "^8.2.3",
36
36
  "babel-plugin-minify-dead-code-elimination": "^0.5.1",
37
37
  "babel-plugin-transform-prune-unused-imports": "^1.0.1",
@@ -48,7 +48,7 @@
48
48
  "webpack-virtual-modules": "^0.4.4"
49
49
  },
50
50
  "devDependencies": {
51
- "@ray-core/types": "^0.1.3",
51
+ "@ray-core/types": "^0.2.0-beta.3",
52
52
  "@types/jest": "^27.0.2",
53
53
  "@types/node": "^16.9.1",
54
54
  "babel-plugin-tester": "^10.1.0",
@@ -62,6 +62,6 @@
62
62
  "email": "tuyafe@tuya.com"
63
63
  }
64
64
  ],
65
- "gitHead": "05f65fee00b3174d78bd9201df6eb8cedfcfe03f",
65
+ "gitHead": "5f36d50a16fb4a25a16b04d35b211af44b677dce",
66
66
  "repository": {}
67
67
  }