xhs-mp-compiler-cli 1.1.1 → 1.1.3

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.
Files changed (110) hide show
  1. package/package.json +11 -5
  2. package/dist/bin/xhs-mp-cli-build.d.ts +0 -2
  3. package/dist/bin/xhs-mp-cli-build.js +0 -40
  4. package/dist/bin/xhs-mp-cli-dev.d.ts +0 -2
  5. package/dist/bin/xhs-mp-cli-dev.js +0 -59
  6. package/dist/bin/xhs-mp-cli.d.ts +0 -2
  7. package/dist/bin/xhs-mp-cli.js +0 -16
  8. package/dist/compiler.d.ts +0 -76
  9. package/dist/compiler.js +0 -361
  10. package/dist/compilerCP.d.ts +0 -1
  11. package/dist/compilerCP.js +0 -175
  12. package/dist/config/constant.config.d.ts +0 -7
  13. package/dist/config/constant.config.js +0 -10
  14. package/dist/dev-server/index.d.ts +0 -3
  15. package/dist/dev-server/index.js +0 -64
  16. package/dist/dev-server/lib/ensurePort.d.ts +0 -2
  17. package/dist/dev-server/lib/ensurePort.js +0 -32
  18. package/dist/dev-server/lib/openBrowser.d.ts +0 -2
  19. package/dist/dev-server/lib/openBrowser.js +0 -23
  20. package/dist/dev-server/lib/openChrome.applescript +0 -78
  21. package/dist/index.d.ts +0 -1
  22. package/dist/index.js +0 -5
  23. package/dist/packs/index.d.ts +0 -14
  24. package/dist/packs/index.js +0 -31
  25. package/dist/packs/mp-pack/index.d.ts +0 -3
  26. package/dist/packs/mp-pack/index.js +0 -32
  27. package/dist/packs/webpack/index.d.ts +0 -3
  28. package/dist/packs/webpack/index.js +0 -92
  29. package/dist/packs/webpack/webpack.d.ts +0 -21
  30. package/dist/packs/webpack/webpack.js +0 -79
  31. package/dist/presets/babel.d.ts +0 -8
  32. package/dist/presets/babel.js +0 -59
  33. package/dist/presets/common.d.ts +0 -4
  34. package/dist/presets/common.js +0 -46
  35. package/dist/presets/configs/minigame/assets/assetsEntryPlugin.d.ts +0 -10
  36. package/dist/presets/configs/minigame/assets/assetsEntryPlugin.js +0 -46
  37. package/dist/presets/configs/minigame/assets/index.d.ts +0 -2
  38. package/dist/presets/configs/minigame/assets/index.js +0 -65
  39. package/dist/presets/configs/minigame/service/index.d.ts +0 -3
  40. package/dist/presets/configs/minigame/service/index.js +0 -34
  41. package/dist/presets/configs/minigame/service/resolveLimitPlugin.d.ts +0 -8
  42. package/dist/presets/configs/minigame/service/resolveLimitPlugin.js +0 -35
  43. package/dist/presets/configs/minigame/service/serviceChunkPlugin.d.ts +0 -9
  44. package/dist/presets/configs/minigame/service/serviceChunkPlugin.js +0 -69
  45. package/dist/presets/configs/minigame/service/serviceEntryPlugin.d.ts +0 -10
  46. package/dist/presets/configs/minigame/service/serviceEntryPlugin.js +0 -32
  47. package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.d.ts +0 -12
  48. package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.js +0 -132
  49. package/dist/presets/configs/miniprogram/assets/index.d.ts +0 -4
  50. package/dist/presets/configs/miniprogram/assets/index.js +0 -47
  51. package/dist/presets/configs/miniprogram/render/component.d.ts +0 -3
  52. package/dist/presets/configs/miniprogram/render/component.js +0 -47
  53. package/dist/presets/configs/miniprogram/render/index.d.ts +0 -5
  54. package/dist/presets/configs/miniprogram/render/index.js +0 -70
  55. package/dist/presets/configs/miniprogram/render/render.d.ts +0 -3
  56. package/dist/presets/configs/miniprogram/render/render.js +0 -49
  57. package/dist/presets/configs/miniprogram/render/renderChunkPlugin.d.ts +0 -8
  58. package/dist/presets/configs/miniprogram/render/renderChunkPlugin.js +0 -55
  59. package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.d.ts +0 -15
  60. package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.js +0 -163
  61. package/dist/presets/configs/miniprogram/service/index.d.ts +0 -5
  62. package/dist/presets/configs/miniprogram/service/index.js +0 -72
  63. package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.d.ts +0 -8
  64. package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.js +0 -66
  65. package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.d.ts +0 -9
  66. package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.js +0 -65
  67. package/dist/presets/index.d.ts +0 -2
  68. package/dist/presets/index.js +0 -95
  69. package/dist/presets/loaders/mg-entry-loader.d.ts +0 -1
  70. package/dist/presets/loaders/mg-entry-loader.js +0 -27
  71. package/dist/presets/loaders/mini-style-loader.d.ts +0 -1
  72. package/dist/presets/loaders/mini-style-loader.js +0 -72
  73. package/dist/presets/loaders/mp-entry-loader.d.ts +0 -1
  74. package/dist/presets/loaders/mp-entry-loader.js +0 -196
  75. package/dist/presets/loaders/sjs-loader/index.d.ts +0 -12
  76. package/dist/presets/loaders/sjs-loader/index.js +0 -605
  77. package/dist/presets/loaders/sjs-loader/scope.d.ts +0 -36
  78. package/dist/presets/loaders/sjs-loader/scope.js +0 -122
  79. package/dist/presets/loaders/sjs-loader/tranform.d.ts +0 -2
  80. package/dist/presets/loaders/sjs-loader/tranform.js +0 -31
  81. package/dist/presets/loaders/wxss-loader.d.ts +0 -1
  82. package/dist/presets/loaders/wxss-loader.js +0 -77
  83. package/dist/presets/plugins/InjectorPlugin.d.ts +0 -7
  84. package/dist/presets/plugins/InjectorPlugin.js +0 -14
  85. package/dist/presets/prod.d.ts +0 -4
  86. package/dist/presets/prod.js +0 -80
  87. package/dist/types/index.d.ts +0 -118
  88. package/dist/types/index.js +0 -13
  89. package/dist/utils/asyncWebpack.d.ts +0 -3
  90. package/dist/utils/asyncWebpack.js +0 -38
  91. package/dist/utils/common.d.ts +0 -8
  92. package/dist/utils/common.js +0 -36
  93. package/dist/utils/const.d.ts +0 -27
  94. package/dist/utils/const.js +0 -47
  95. package/dist/utils/css.d.ts +0 -2
  96. package/dist/utils/css.js +0 -41
  97. package/dist/utils/depenedHelper.d.ts +0 -31
  98. package/dist/utils/depenedHelper.js +0 -89
  99. package/dist/utils/getSuffixName.d.ts +0 -3
  100. package/dist/utils/getSuffixName.js +0 -18
  101. package/dist/utils/loader-utils.d.ts +0 -15
  102. package/dist/utils/loader-utils.js +0 -59
  103. package/dist/utils/postcssRpx2Vw.d.ts +0 -12
  104. package/dist/utils/postcssRpx2Vw.js +0 -35
  105. package/dist/utils/projectConfig.d.ts +0 -1
  106. package/dist/utils/projectConfig.js +0 -20
  107. package/dist/utils/tagTransformMap.d.ts +0 -35
  108. package/dist/utils/tagTransformMap.js +0 -38
  109. package/dist/utils/utils.d.ts +0 -5
  110. package/dist/utils/utils.js +0 -37
@@ -1,72 +0,0 @@
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.presetService = exports.getServiceEntry = void 0;
7
- const xhs_mp_pack_1 = require("xhs-mp-pack");
8
- const serviceChunkPlugin_1 = __importDefault(require("./serviceChunkPlugin"));
9
- const InjectorPlugin_1 = require("../../../plugins/InjectorPlugin");
10
- const getServiceEntry = options => () => {
11
- const entries = {};
12
- const { packSetting } = options;
13
- if (packSetting.enableV2) {
14
- appendV2Entry(options, entries);
15
- }
16
- if (packSetting.enableV1) {
17
- appendV1Entry(options, entries);
18
- }
19
- return entries;
20
- };
21
- exports.getServiceEntry = getServiceEntry;
22
- const appendV2Entry = (options, entries) => {
23
- const { packSetting } = options;
24
- const { mainPkg, subPkgs } = packSetting.getCompilePkgsForEntries();
25
- if (mainPkg) {
26
- entries['v2/service'] = `mp-entry-loader?type=service&pkg=${xhs_mp_pack_1.CONSTANTS.MAIN_PKG}!`;
27
- }
28
- for (const { root } of subPkgs) {
29
- entries[`v2/${root}/service`] = `mp-entry-loader?type=service&pkg=${xhs_mp_pack_1.CONSTANTS.SUB_PKG}&root=${root}!`;
30
- }
31
- };
32
- const appendV1Entry = (options, entries) => {
33
- const { packSetting } = options;
34
- const { mainPkg, subPkgs } = packSetting.getCompilePkgsForEntries();
35
- if (mainPkg) {
36
- entries['v1/service'] = `mp-entry-loader?type=service&pkg=${xhs_mp_pack_1.CONSTANTS.MAIN_PKG}!`;
37
- }
38
- for (const { root } of subPkgs) {
39
- entries[`v1/${root}/service`] = `mp-entry-loader?type=service&pkg=${xhs_mp_pack_1.CONSTANTS.SUB_PKG}&root=${root}!`;
40
- }
41
- };
42
- const presetService = (chain, options) => {
43
- const { packSetting } = options;
44
- const { env, distDir } = packSetting;
45
- const isProd = env === xhs_mp_pack_1.ENV.production;
46
- chain.merge({
47
- output: {
48
- path: distDir,
49
- globalObject: 'globalThis',
50
- libraryTarget: 'umd',
51
- uniqueName: 'MpService',
52
- }
53
- // cache: {
54
- // type: 'filesystem',
55
- // cacheDirectory: cacheDirectory,
56
- // },
57
- });
58
- chain.plugin('InjectorPlugin').use(InjectorPlugin_1.InjectorPlugin, [options]);
59
- chain.plugin('ServiceChunkPlugin').use(serviceChunkPlugin_1.default, [options]);
60
- chain.optimization.runtimeChunk({
61
- name: 'runtime'
62
- });
63
- // dev模式下开启懒编译,不能抽离common chunk
64
- if (env !== xhs_mp_pack_1.ENV.development) {
65
- chain.optimization.splitChunks({
66
- chunks: chunk => !chunk.name.startsWith('v0/'),
67
- minSize: 0,
68
- name: 'service-common'
69
- });
70
- }
71
- };
72
- exports.presetService = presetService;
@@ -1,8 +0,0 @@
1
- import { Resolver } from 'xhs-mp-pack';
2
- import { IPresetOptions } from '../../../../types';
3
- declare class XhsResolveLimitPlugin {
4
- options: IPresetOptions;
5
- constructor(options: IPresetOptions);
6
- apply(compiler: any, resolver: Resolver): void;
7
- }
8
- export default XhsResolveLimitPlugin;
@@ -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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const fs_extra_1 = require("fs-extra");
13
- class XhsResolveLimitPlugin {
14
- constructor(options) {
15
- this.options = options;
16
- }
17
- apply(compiler, resolver) {
18
- resolver
19
- .getHook('file')
20
- .tapAsync('XhsResolveLimitPlugin', (request, contextResolver, callback) => __awaiter(this, void 0, void 0, function* () {
21
- var _a;
22
- const { project } = this.options;
23
- const projectMiniprogramPath = project.projectMiniprogramPath;
24
- // @ts-ignore
25
- let issuer = ((_a = request.context) === null || _a === void 0 ? void 0 : _a.issuer) || '';
26
- let target = request.path || '';
27
- if (!issuer ||
28
- target.includes('node_modules') ||
29
- !issuer.startsWith(projectMiniprogramPath) ||
30
- !target.startsWith(projectMiniprogramPath)) {
31
- return callback();
32
- }
33
- issuer = issuer.replace(`${projectMiniprogramPath}/`, '');
34
- target = target.replace(new RegExp(projectMiniprogramPath, 'g'), '').replace(/^\/+/g, '');
35
- const appJSON = yield (0, fs_extra_1.readJson)(`${projectMiniprogramPath}/app.json`);
36
- appJSON.subPackages = appJSON.subPackages || appJSON.subpackages || [];
37
- const subPkgs = appJSON.subPackages.map(pkg => pkg.root);
38
- // 当 issuer 是分包
39
- const issuerSubPkg = subPkgs.find(pkg => issuer.startsWith(pkg));
40
- if (issuerSubPkg) {
41
- // 允许 target 和 issuer 在同一个分包
42
- if (issuer.startsWith(issuerSubPkg) && target.startsWith(issuerSubPkg)) {
43
- return callback();
44
- }
45
- // issuer 是分包 target 是主包
46
- if (appJSON.pages.some(page => target.startsWith(page))) {
47
- // 当 issuer 是 **独立分包** 时,不能引用主包资源
48
- if (appJSON.subPackages.find(subPkg => subPkg.root === issuerSubPkg).independent) {
49
- return callback(new Error(`${issuer} 在独立分包内,独立分包不可引用主包 ${target} 资源`), request);
50
- }
51
- return callback();
52
- }
53
- // issuer 是分包,target 是分包
54
- if (subPkgs.some(sub => target.startsWith(sub))) {
55
- return callback(new Error(`${issuer} 不能引用 ${target},因为他们不在同一个分包`), request);
56
- }
57
- }
58
- // issuer 是主包,此时 target 不能在分包
59
- if (subPkgs.some(pkg => target.startsWith(pkg))) {
60
- return callback(new Error(`${issuer} 在主包内,主包不可引用分包资源 ${target}`), request);
61
- }
62
- return callback();
63
- }));
64
- }
65
- }
66
- exports.default = XhsResolveLimitPlugin;
@@ -1,9 +0,0 @@
1
- import { IXhsCompiler } from 'xhs-mp-pack';
2
- import { IPresetOptions } from '../../../../types';
3
- declare class ServiceChunkPlugin {
4
- options: IPresetOptions;
5
- constructor(options: IPresetOptions);
6
- apply(compiler: IXhsCompiler): void;
7
- updateIndependentService(compilation: any, runtimeCode: any): void;
8
- }
9
- export default ServiceChunkPlugin;
@@ -1,65 +0,0 @@
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 path_1 = __importDefault(require("path"));
7
- const xhs_mp_pack_1 = require("xhs-mp-pack");
8
- class ServiceChunkPlugin {
9
- constructor(options) {
10
- this.options = options;
11
- }
12
- apply(compiler) {
13
- compiler.hooks.compilation.tap('ServiceChunkPlugin', compilation => {
14
- compilation.hooks.processAssets.tap({
15
- name: 'ServiceChunkPlugin',
16
- }, () => {
17
- var _a, _b, _c, _d;
18
- const { project, packSetting } = this.options;
19
- const serviceSourceV2 = (_a = compilation.getAsset('v2/service.js')) === null || _a === void 0 ? void 0 : _a.source;
20
- const serviceSource = (_b = compilation.getAsset('v1/service.js')) === null || _b === void 0 ? void 0 : _b.source;
21
- let runtimeCode = (_c = compilation.getAsset('runtime.js')) === null || _c === void 0 ? void 0 : _c.source.source();
22
- // 当没有引用相同 js 场景时, commonChunk 将是 undefined
23
- const commonSource = ((_d = compilation.getAsset('service-common.js')) === null || _d === void 0 ? void 0 : _d.source) || '';
24
- runtimeCode = `
25
- if (!globalThis.__XHS_RUNTIME_REGISTERED__) {
26
- globalThis.__XHS_RUNTIME_REGISTERED__ = true;
27
- ${runtimeCode}
28
- }`;
29
- if (packSetting.enableV2 && serviceSourceV2) {
30
- // 注入 v2 service.js
31
- // 主包加入 runtimeChunk、commonChunk
32
- compilation.updateAsset('v2/service.js', new xhs_mp_pack_1.ConcatSource(runtimeCode, commonSource, serviceSourceV2));
33
- }
34
- // 独立分包加入 runtimeChunk
35
- if (packSetting.enableV1 && serviceSource) {
36
- // 主包加入 runtimeChunk、commonChunk
37
- compilation.updateAsset('v1/service.js', new xhs_mp_pack_1.ConcatSource(runtimeCode, commonSource, serviceSource));
38
- }
39
- this.updateIndependentService(compilation, runtimeCode);
40
- compilation.deleteAsset('runtime.js');
41
- compilation.deleteAsset('service-common.js');
42
- });
43
- });
44
- }
45
- updateIndependentService(compilation, runtimeCode) {
46
- const { project, packSetting } = this.options;
47
- const usingPackageType = packSetting.usingPackageType;
48
- const subPackages = project.getSubPackages();
49
- subPackages
50
- .filter(sub => sub.independent)
51
- .map(sub => path_1.default.join(usingPackageType, sub.root, 'service.js'))
52
- .forEach(servicePath => {
53
- var _a;
54
- const independentServiceSource = (_a = compilation.getAsset(servicePath)) === null || _a === void 0 ? void 0 : _a.source;
55
- if (compilation.getAsset(servicePath)) {
56
- const subServiceSource = new xhs_mp_pack_1.ConcatSource(runtimeCode, independentServiceSource);
57
- compilation.updateAsset(servicePath, subServiceSource);
58
- if (packSetting.enableV2 && packSetting.enableV1) {
59
- compilation.updateAsset(servicePath.replace(usingPackageType, 'v1'), subServiceSource);
60
- }
61
- }
62
- });
63
- }
64
- }
65
- exports.default = ServiceChunkPlugin;
@@ -1,2 +0,0 @@
1
- import { IPresetOptions } from '../types';
2
- export declare const createConfigs: (options: IPresetOptions) => any[];
@@ -1,95 +0,0 @@
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.createConfigs = void 0;
7
- const xhs_mp_pack_1 = require("xhs-mp-pack");
8
- const path_1 = __importDefault(require("path"));
9
- const common_1 = __importDefault(require("./common"));
10
- const babel_1 = __importDefault(require("./babel"));
11
- const prod_1 = __importDefault(require("./prod"));
12
- const assets_1 = require("./configs/miniprogram/assets");
13
- const service_1 = require("./configs/miniprogram/service");
14
- const render_1 = require("./configs/miniprogram/render");
15
- const assets_2 = require("./configs/minigame/assets");
16
- const service_2 = require("./configs/minigame/service");
17
- /**
18
- * 小程序编译配置
19
- */
20
- const createMPConfigs = (options) => {
21
- const { packSetting } = options;
22
- const { env } = packSetting;
23
- const assetsChain = new xhs_mp_pack_1.Config();
24
- const serviceChain = new xhs_mp_pack_1.Config();
25
- const renderChain = new xhs_mp_pack_1.Config();
26
- const assetsPresets = [assets_1.presetAssets, common_1.default];
27
- const servicePresets = [service_1.presetService, common_1.default, babel_1.default];
28
- const renderPresets = [render_1.presetRender, common_1.default, babel_1.default];
29
- if (env === xhs_mp_pack_1.ENV.production) {
30
- assetsPresets.push(prod_1.default);
31
- servicePresets.push(prod_1.default);
32
- renderPresets.push(prod_1.default);
33
- }
34
- assetsPresets.forEach(preset => preset(assetsChain, Object.assign(Object.assign({}, options), { otherSetting: { noJs: true } })));
35
- servicePresets.forEach(preset => preset(serviceChain, options));
36
- renderPresets.forEach(preset => preset(renderChain, options));
37
- const assetsConfig = assetsChain.toConfig();
38
- const serviceConfig = serviceChain.toConfig();
39
- const renderConfig = renderChain.toConfig();
40
- assetsConfig.entry = (0, assets_1.getAssetsEntry)(options);
41
- serviceConfig.entry = (0, service_1.getServiceEntry)(options);
42
- renderConfig.entry = (0, render_1.getRenderEntry)(options);
43
- let configs = [renderConfig, serviceConfig, assetsConfig];
44
- configs = configs.map(options => {
45
- var _a, _b, _c, _d;
46
- // 查找ide根目录下的node_modules
47
- (_b = (_a = options.resolve) === null || _a === void 0 ? void 0 : _a.modules) === null || _b === void 0 ? void 0 : _b.push(path_1.default.resolve(__dirname, '../../../../../'));
48
- // cli的node_modules路径
49
- (_d = (_c = options.resolve) === null || _c === void 0 ? void 0 : _c.modules) === null || _d === void 0 ? void 0 : _d.push(path_1.default.resolve(__dirname, '../../../../'));
50
- return options;
51
- });
52
- return configs;
53
- };
54
- /**
55
- * 小游戏编译配置
56
- */
57
- const createMGConfigs = (options) => {
58
- const { packSetting } = options;
59
- const { env } = packSetting;
60
- const assetsChain = new xhs_mp_pack_1.Config();
61
- const serviceChain = new xhs_mp_pack_1.Config();
62
- const assetsPresets = [assets_2.presetAssets, common_1.default];
63
- const servicePresets = [service_2.presetService, common_1.default, babel_1.default];
64
- if (env === xhs_mp_pack_1.ENV.production) {
65
- assetsPresets.push(prod_1.default);
66
- servicePresets.push(prod_1.default);
67
- }
68
- assetsPresets.forEach(preset => preset(assetsChain, Object.assign(Object.assign({}, options), { otherSetting: { noJs: true } })));
69
- servicePresets.forEach(preset => preset(serviceChain, options));
70
- const assetsConfig = assetsChain.toConfig();
71
- const serviceConfig = serviceChain.toConfig();
72
- assetsConfig.entry = {};
73
- serviceConfig.entry = {};
74
- let configs = [serviceConfig, assetsConfig];
75
- configs = configs.map(options => {
76
- var _a, _b, _c, _d;
77
- // 查找ide根目录下的node_modules
78
- (_b = (_a = options.resolve) === null || _a === void 0 ? void 0 : _a.modules) === null || _b === void 0 ? void 0 : _b.push(path_1.default.resolve(__dirname, '../../../../../'));
79
- // cli的node_modules路径
80
- (_d = (_c = options.resolve) === null || _c === void 0 ? void 0 : _c.modules) === null || _d === void 0 ? void 0 : _d.push(path_1.default.resolve(__dirname, '../../../../'));
81
- return options;
82
- });
83
- return configs;
84
- };
85
- // 获取编译配置
86
- const createConfigs = (options) => {
87
- const { project } = options;
88
- if (project.appMode === 'miniprogram') {
89
- return createMPConfigs(options);
90
- }
91
- else {
92
- return createMGConfigs(options);
93
- }
94
- };
95
- exports.createConfigs = createConfigs;
@@ -1 +0,0 @@
1
- export {};
@@ -1,27 +0,0 @@
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 = __importDefault(require("fs-extra"));
7
- const common_1 = require("../../utils/common");
8
- const xhs_mp_project_1 = require("xhs-mp-project");
9
- function entryLoader() {
10
- // @ts-ignore
11
- const { appJSON, projectPath } = this._compiler.project;
12
- const { entry } = this.getOptions();
13
- const addAppJs = () => {
14
- const absolutePath = (0, common_1.unixJoin)(projectPath, entry);
15
- if (fs_extra_1.default.existsSync(`${absolutePath}.js`)) {
16
- return `require('${absolutePath}.js')`;
17
- }
18
- if (fs_extra_1.default.existsSync(`${absolutePath}.ts`)) {
19
- return `require('${absolutePath}.ts')`;
20
- }
21
- throw new Error(`${absolutePath}.(js|ts) 不存在`);
22
- };
23
- return `
24
- ;globalThis['__MP_APP_JSON__'] = ${JSON.stringify(xhs_mp_project_1.utils.pureAppJSON(appJSON))};
25
- ${addAppJs()}`;
26
- }
27
- module.exports = entryLoader;
@@ -1 +0,0 @@
1
- export {};
@@ -1,72 +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 packs_1 = require("../../packs");
16
- const cssnano_1 = __importDefault(require("cssnano"));
17
- const common_1 = require("../../utils/common");
18
- const CSS_MINIMIZER_OPTIONS = {
19
- preset: ['default', { normalizeUrl: false, calc: false }]
20
- };
21
- const minify = (source, name) => __awaiter(void 0, void 0, void 0, function* () {
22
- var _a, _b;
23
- const postcssOptions = {
24
- to: name,
25
- from: name
26
- };
27
- try {
28
- const result = yield cssnano_1.default.process(source, postcssOptions, CSS_MINIMIZER_OPTIONS);
29
- return {
30
- code: result.css,
31
- warnings: (_b = (_a = result.warnings()) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, i => i.toString())
32
- };
33
- }
34
- catch (error) {
35
- return {
36
- code: source
37
- };
38
- }
39
- });
40
- function miniStyleLoader(source) {
41
- var _a;
42
- const callback = this.async();
43
- const { resourcePath } = this;
44
- // const {miniprogramDir, enableVDom, enableV1, enableV2, independent} = this.getOptions() as any
45
- const { project, packSetting, independent } = this.getOptions();
46
- const { miniprogramDir } = project;
47
- const { enableVDom, enableV1, enableV2 } = packSetting;
48
- const shortPath = (0, common_1.getShortPath)(miniprogramDir, resourcePath).replace(/\.wxss$/, '.css');
49
- source = (_a = source === null || source === void 0 ? void 0 : source.trim) === null || _a === void 0 ? void 0 : _a.call(source);
50
- function result(code) {
51
- if (!code) {
52
- return `export default void 0;`;
53
- }
54
- // 判断浏览器环境,注入css添加逻辑
55
- return new packs_1.RawSource(`globalThis.__XHS_IS_WEBVIEW && globalThis.__XHS_APPEND_CSS(${JSON.stringify(code)});` +
56
- `export default ${JSON.stringify(shortPath)};`).source();
57
- }
58
- // 压缩css
59
- minify(source, shortPath)
60
- .then(({ code, warnings }) => {
61
- // vdom架构下emit出一份css文件
62
- if ((independent || enableVDom) && code) {
63
- enableV1 && this.emitFile(`v1/${shortPath}`, code);
64
- enableV2 && this.emitFile(`v2/${shortPath}`, code);
65
- }
66
- callback(null, result(code));
67
- })
68
- .catch(error => {
69
- callback(error);
70
- });
71
- }
72
- module.exports = miniStyleLoader;
@@ -1 +0,0 @@
1
- export {};
@@ -1,196 +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
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const fs_extra_1 = __importStar(require("fs-extra"));
27
- const path_1 = __importStar(require("path"));
28
- const xhs_mp_pack_1 = require("xhs-mp-pack");
29
- const loader_utils_1 = require("../../utils/loader-utils");
30
- const getSuffixName_1 = require("../../utils/getSuffixName");
31
- function genComponentLoaderScript(project, context, opts) {
32
- const { pkg, root, mode, compPath } = opts;
33
- const { projectMiniprogramPath, jsonDependencies = [] } = project;
34
- const componentsMap = project.getComponentsMap();
35
- const entries = [];
36
- for (const file of jsonDependencies) {
37
- context.addDependency(file);
38
- }
39
- let name = 'XHS_COMPONENTS';
40
- if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG) {
41
- name = `XHS_COMPONENTS_${root}`;
42
- }
43
- // v2
44
- if (mode === 'v2') {
45
- return `
46
- ;(globalThis['${name}'] || (globalThis['${name}'] = { default: {} }))
47
- ;globalThis['${name}'].default['${compPath}'] = () => require('${(0, loader_utils_1.formatPath)(path_1.default.join(projectMiniprogramPath, `${compPath}.${(0, getSuffixName_1.getMlSuffixName)()}`))}')
48
- `;
49
- }
50
- // v1和v0
51
- Object.keys(componentsMap).forEach(compPath => {
52
- const push = () => entries.push(`;globalThis['${name}'].default['${compPath}'] = () => require('${(0, loader_utils_1.formatPath)(path_1.default.join(projectMiniprogramPath, `${compPath}.${(0, getSuffixName_1.getMlSuffixName)()}`))}')`);
53
- if (pkg === xhs_mp_pack_1.CONSTANTS.FULL_PKG) {
54
- push();
55
- }
56
- if (pkg === xhs_mp_pack_1.CONSTANTS.MAIN_PKG && project.isFileInMainPkg(compPath)) {
57
- push();
58
- }
59
- if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG && compPath.startsWith(`${root}/`)) {
60
- push();
61
- }
62
- });
63
- return `
64
- ;(globalThis['${name}'] || (globalThis['${name}'] = { default: {} }))
65
- ;${entries.join('\n ')}
66
- `;
67
- }
68
- const genRenderLoaderScript = (project, context, opts) => {
69
- const { projectMiniprogramPath, appJSON, jsonDependencies } = project;
70
- const { pkg, mode } = opts;
71
- const isFull = pkg === 'full';
72
- for (const file of jsonDependencies) {
73
- context.addDependency(file);
74
- }
75
- const appCssPath = (0, path_1.resolve)(projectMiniprogramPath, 'app.css');
76
- const appCssExist = (0, fs_extra_1.existsSync)(appCssPath);
77
- const resourcePath = (0, loader_utils_1.formatPath)(context.resourcePath);
78
- const path = (0, loader_utils_1.formatPath)(resourcePath.replace(`${projectMiniprogramPath}/`, '').replace(`.${(0, getSuffixName_1.getMlSuffixName)()}`, ''));
79
- const subPackage = (appJSON.subPackages || []).find(subPack => !!subPack.pages.find(page => page.path === path));
80
- const enableLazyCodeLoading = mode === 'v2';
81
- // 资源文件
82
- const resources = (0, loader_utils_1.getResourceUris)({
83
- appCssExist,
84
- subPackage,
85
- enableLazyCodeLoading
86
- });
87
- // 开启了按需注入,注入依赖组件
88
- if (enableLazyCodeLoading) {
89
- const isIndependent = (subPackage === null || subPackage === void 0 ? void 0 : subPackage.independent) || false;
90
- const dependsTree = project.getPageDependComponentPaths(path, isIndependent);
91
- const subPackagesPrefix = (appJSON.subPackages || []).map(sub => sub.root);
92
- const depends = [];
93
- for (let i = 0; i < dependsTree.length; i++) {
94
- let uri = dependsTree[i];
95
- const subRoot = subPackagesPrefix.find(subRoot => uri.startsWith(`${subRoot}/`));
96
- if (subRoot) {
97
- uri = `${subRoot}/${uri}`;
98
- }
99
- depends.push(uri);
100
- }
101
- return `
102
- import Component from '${resourcePath}';
103
- globalThis.__render.mount(Component, '${path}', ${JSON.stringify(resources)}, ${JSON.stringify(depends)})
104
- `;
105
- }
106
- return `
107
- import Component from '${resourcePath}';
108
- globalThis.__render.mount(Component, '${path}', ${JSON.stringify(resources)})
109
- `;
110
- };
111
- function genServiceLoderScript(project, context, opts) {
112
- const { appJSON, legacyAppJSON, projectMiniprogramPath, jsonDependencies } = project;
113
- const { pkg, root } = opts;
114
- const modules = [];
115
- let name = 'XHS_SERVICE';
116
- if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG) {
117
- name = `XHS_SERVICE_${root}`;
118
- }
119
- for (const file of jsonDependencies) {
120
- context.addDependency(file);
121
- }
122
- const addAppJs = () => {
123
- if (fs_extra_1.default.existsSync(`${projectMiniprogramPath}/app.js`) ||
124
- fs_extra_1.default.existsSync(`${projectMiniprogramPath}/app.ts`)) {
125
- modules.unshift(`;globalThis['${name}'].default['app'] = require('${(0, loader_utils_1.formatPath)(`${projectMiniprogramPath}/app`)}')`);
126
- }
127
- };
128
- if (pkg === xhs_mp_pack_1.CONSTANTS.FULL_PKG) {
129
- addAppJs();
130
- for (const page of legacyAppJSON.pages) {
131
- const resourcePath = (0, loader_utils_1.formatPath)(`${projectMiniprogramPath}/${page.path}`);
132
- modules.push(`;globalThis['${name}'].default['${page.path}'] = () => require('${resourcePath}')`);
133
- }
134
- }
135
- else {
136
- if (pkg === xhs_mp_pack_1.CONSTANTS.MAIN_PKG) {
137
- addAppJs();
138
- }
139
- for (const page of legacyAppJSON.pages) {
140
- const resourcePath = (0, loader_utils_1.formatPath)(`${projectMiniprogramPath}/${page.path}`);
141
- const content = `;globalThis['${name}'].default['${page.path}'] = () => require('${resourcePath}')`;
142
- if (pkg === xhs_mp_pack_1.CONSTANTS.MAIN_PKG) {
143
- const subPackageRoots = appJSON.subPackages.map(pkg => pkg.root);
144
- if (subPackageRoots.every(root => !page.path.startsWith(`${root}/`))) {
145
- modules.push(content);
146
- }
147
- }
148
- if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG) {
149
- if (page.path.startsWith(`${root}/`)) {
150
- modules.push(content);
151
- }
152
- }
153
- }
154
- }
155
- Object.keys(appJSON.componentsMap).forEach(compPath => {
156
- const resourcePath = (0, loader_utils_1.formatPath)(`${projectMiniprogramPath}/${compPath}`);
157
- const content = `;globalThis['${name}'].default['${compPath}'] = () => require('${resourcePath}')`;
158
- if (pkg === xhs_mp_pack_1.CONSTANTS.FULL_PKG) {
159
- modules.push(content);
160
- }
161
- if (pkg === xhs_mp_pack_1.CONSTANTS.MAIN_PKG) {
162
- const subPackageRoots = appJSON.subPackages.map(pkg => pkg.root);
163
- if (subPackageRoots.every(root => !compPath.startsWith(`${root}/`))) {
164
- modules.push(content);
165
- }
166
- }
167
- if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG) {
168
- if (compPath.startsWith(`${root}/`)) {
169
- modules.push(content);
170
- }
171
- }
172
- });
173
- const runtimeJSON = pkg === xhs_mp_pack_1.CONSTANTS.FULL_PKG ? legacyAppJSON : appJSON;
174
- return `;globalThis['__MP_APP_JSON__'] = ${JSON.stringify(runtimeJSON)};
175
- ;(globalThis['${name}'] || (globalThis['${name}'] = { default: {} }))
176
- ${modules.join('\n ')}
177
- `;
178
- }
179
- function entryLoader() {
180
- // @ts-ignore
181
- const options = this.getOptions();
182
- const { type } = options;
183
- // @ts-ignore
184
- const handelrs = {
185
- render: genRenderLoaderScript,
186
- component: genComponentLoaderScript,
187
- service: genServiceLoderScript
188
- };
189
- const handler = handelrs[type];
190
- if (!handler) {
191
- throw new Error(`not found loader handler of ${type}`);
192
- }
193
- // @ts-ignore
194
- return handler(this._compiler.project, this, options);
195
- }
196
- module.exports = entryLoader;
@@ -1,12 +0,0 @@
1
- import type { Span } from '@swc/core';
2
- export declare const SJS_HELPER = "_sjs$";
3
- declare function sjsCompiler(code: any, onRequire: (s: string) => string): {
4
- code: string;
5
- map: string | undefined;
6
- legacyCode: string;
7
- errors: {
8
- message: string;
9
- span: Span;
10
- }[];
11
- };
12
- export default sjsCompiler;