xhs-mp-compiler-cli 2.0.0-beta.3 → 2.0.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.
Files changed (94) hide show
  1. package/dist/bin/xhs-mp-cli-build.js +48 -34
  2. package/dist/bin/xhs-mp-cli-dev.js +44 -44
  3. package/dist/bin/xhs-mp-cli.js +22 -12
  4. package/dist/compiler.d.ts +21 -28
  5. package/dist/compiler.js +327 -327
  6. package/dist/compilerImpl.d.ts +19 -0
  7. package/dist/compilerImpl.js +173 -0
  8. package/dist/config/constant.config.d.ts +24 -0
  9. package/dist/config/constant.config.js +82 -30
  10. package/dist/config/dir.config.js +23 -13
  11. package/dist/index.d.ts +9 -9
  12. package/dist/index.js +454 -408
  13. package/dist/packs/index.d.ts +4 -4
  14. package/dist/packs/index.js +38 -30
  15. package/dist/packs/mp-pack/index.js +38 -30
  16. package/dist/packs/webpack/dev-server/index.js +61 -50
  17. package/dist/packs/webpack/dev-server/lib/ensurePort.js +33 -23
  18. package/dist/packs/webpack/dev-server/lib/openBrowser.js +28 -18
  19. package/dist/packs/webpack/index.d.ts +1 -1
  20. package/dist/packs/webpack/index.js +99 -90
  21. package/dist/packs/webpack/webpack.d.ts +2 -1
  22. package/dist/packs/webpack/webpack.js +81 -63
  23. package/dist/presets/babel.d.ts +0 -1
  24. package/dist/presets/babel.js +64 -58
  25. package/dist/presets/common.js +42 -45
  26. package/dist/presets/configs/minigame/assets/assetsEntryPlugin.js +50 -40
  27. package/dist/presets/configs/minigame/assets/index.js +62 -52
  28. package/dist/presets/configs/minigame/service/index.js +49 -30
  29. package/dist/presets/configs/minigame/service/resolveLimitPlugin.js +33 -23
  30. package/dist/presets/configs/minigame/service/serviceChunkPlugin.d.ts +2 -2
  31. package/dist/presets/configs/minigame/service/serviceChunkPlugin.js +69 -60
  32. package/dist/presets/configs/minigame/service/serviceEntryPlugin.d.ts +3 -3
  33. package/dist/presets/configs/minigame/service/serviceEntryPlugin.js +39 -29
  34. package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.js +120 -113
  35. package/dist/presets/configs/miniprogram/assets/index.js +45 -43
  36. package/dist/presets/configs/miniprogram/render/component.js +51 -41
  37. package/dist/presets/configs/miniprogram/render/index.d.ts +2 -3
  38. package/dist/presets/configs/miniprogram/render/index.js +85 -68
  39. package/dist/presets/configs/miniprogram/render/render.js +53 -43
  40. package/dist/presets/configs/miniprogram/render/renderChunkPlugin.js +84 -49
  41. package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.d.ts +15 -0
  42. package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.js +164 -126
  43. package/dist/presets/configs/miniprogram/service/index.js +82 -65
  44. package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.js +60 -50
  45. package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.js +93 -55
  46. package/dist/presets/index.js +100 -90
  47. package/dist/presets/loaders/mg-entry-loader.js +32 -22
  48. package/dist/presets/loaders/mini-style-loader.js +79 -55
  49. package/dist/presets/loaders/mp-entry-loader.js +149 -140
  50. package/dist/presets/loaders/wxss-loader.js +73 -63
  51. package/dist/presets/plugins/InjectorPlugin.js +23 -13
  52. package/dist/presets/plugins/SourceMapDevToolPlugin.d.ts +1 -0
  53. package/dist/presets/plugins/SourceMapDevToolPlugin.js +23 -0
  54. package/dist/presets/prod.js +88 -78
  55. package/dist/sharedFs.d.ts +2 -0
  56. package/dist/sharedFs.js +24 -0
  57. package/dist/types/index.d.ts +11 -37
  58. package/dist/types/index.js +23 -13
  59. package/dist/utils/{apm/index.d.ts → apm.d.ts} +5 -3
  60. package/dist/utils/apm.js +245 -0
  61. package/dist/utils/cache.d.ts +28 -0
  62. package/dist/utils/cache.js +49 -0
  63. package/dist/utils/common.js +42 -32
  64. package/dist/utils/css.d.ts +1 -1
  65. package/dist/utils/css.js +43 -35
  66. package/dist/utils/depenedHelper.js +95 -85
  67. package/dist/utils/file.js +39 -29
  68. package/dist/utils/loader-utils.js +63 -53
  69. package/dist/utils/postcssRpx2Vw.js +43 -33
  70. package/dist/utils/project.d.ts +3 -2
  71. package/dist/utils/project.js +129 -119
  72. package/dist/utils/projectConfig.js +24 -15
  73. package/dist/utils/utils.js +51 -42
  74. package/dist/utils/workerPool.d.ts +29 -0
  75. package/dist/utils/workerPool.js +125 -0
  76. package/dist/utils/zip.js +239 -229
  77. package/package.json +33 -14
  78. package/dist/compilerCP.d.ts +0 -1
  79. package/dist/compilerCP.js +0 -175
  80. package/dist/presets/loaders/sjs-loader/index.d.ts +0 -12
  81. package/dist/presets/loaders/sjs-loader/index.js +0 -605
  82. package/dist/presets/loaders/sjs-loader/scope.d.ts +0 -36
  83. package/dist/presets/loaders/sjs-loader/scope.js +0 -122
  84. package/dist/presets/loaders/sjs-loader/tranform.d.ts +0 -2
  85. package/dist/presets/loaders/sjs-loader/tranform.js +0 -31
  86. package/dist/utils/apm/index.js +0 -198
  87. package/dist/utils/asyncWebpack.d.ts +0 -3
  88. package/dist/utils/asyncWebpack.js +0 -38
  89. package/dist/utils/const.d.ts +0 -27
  90. package/dist/utils/const.js +0 -47
  91. package/dist/utils/getSuffixName.d.ts +0 -3
  92. package/dist/utils/getSuffixName.js +0 -18
  93. package/dist/utils/tagTransformMap.d.ts +0 -36
  94. package/dist/utils/tagTransformMap.js +0 -39
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,125 +7,133 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
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 const_1 = __importDefault(require("../../../../utils/const"));
17
- class XhsAssetsPlugin {
18
- constructor(options) {
19
- this.options = options;
20
- this.copyPatterns = new packs_1.CopyPatterns();
10
+ (function (factory) {
11
+ if (typeof module === "object" && typeof module.exports === "object") {
12
+ var v = factory(require, exports);
13
+ if (v !== undefined) module.exports = v;
14
+ }
15
+ else if (typeof define === "function" && define.amd) {
16
+ define(["require", "exports", "../../../../packs", "../../../../config/constant.config"], factory);
21
17
  }
22
- apply(compiler) {
23
- compiler.hooks.compilation.tap('XhsMpAssetsPlugin', compilation => {
24
- const { project, packSetting } = this.options;
25
- const { appJSON, legacyAppJSON } = project;
26
- const usingPackageType = packSetting.usingPackageType;
27
- // app.json
28
- if (compilation) {
29
- this.emitAppJson(compilation, JSON.parse(JSON.stringify(appJSON)));
30
- // 兼容服务端,始终创建 v0/app.json
31
- this.emitLegacyAppJSON(compilation, legacyAppJSON);
18
+ })(function (require, exports) {
19
+ "use strict";
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ const packs_1 = require("../../../../packs");
22
+ const constant_config_1 = require("../../../../config/constant.config");
23
+ class XhsAssetsPlugin {
24
+ constructor(options) {
25
+ this.options = options;
26
+ this.copyPatterns = new packs_1.CopyPatterns();
27
+ }
28
+ apply(compiler) {
29
+ compiler.hooks.compilation.tap('XhsMpAssetsPlugin', compilation => {
30
+ const { project, packSetting } = this.options;
31
+ const { appJSON, legacyAppJSON } = project;
32
+ const usingPackageType = packSetting.usingPackageType;
33
+ // app.json
34
+ if (compilation) {
35
+ this.emitAppJson(compilation, JSON.parse(JSON.stringify(appJSON)));
36
+ // 兼容服务端,始终创建 v0/app.json
37
+ this.emitLegacyAppJSON(compilation, legacyAppJSON);
38
+ }
39
+ // app.css 复用
40
+ compilation.hooks.processAssets.tap({
41
+ name: 'XhsMpAssetsCommonPlugin',
42
+ stage: packs_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
43
+ }, assets => {
44
+ // 删除因为 entry 是 app.(wxss|css) 而产生的的 js 文件
45
+ for (const key of Object.keys(assets)) {
46
+ if (key === `${usingPackageType}/${constant_config_1.ENTRY_CSS_NAME}.js` ||
47
+ key === `${usingPackageType}/${constant_config_1.ENTRY_CSS_NAME}.js.map`) {
48
+ Reflect.deleteProperty(assets, key);
49
+ }
50
+ }
51
+ // 复用app.css,copy v2到v1
52
+ if (packSetting.usingPackageType === 'v2' && packSetting.enableV1) {
53
+ if (assets[`${usingPackageType}/app.css`]) {
54
+ assets['v1/app.css'] = assets[`${usingPackageType}/app.css`];
55
+ }
56
+ }
57
+ });
58
+ // 图片等资源
59
+ const cache = compilation.getCache('CopyWebpackPlugin');
60
+ const logger = compilation.getLogger('XhsMpAssetsCopyPlugin');
61
+ compilation.hooks.processAssets.tapAsync({
62
+ name: 'XhsMpAssetsCopyPlugin',
63
+ stage: packs_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
64
+ }, (assets, callback) => __awaiter(this, void 0, void 0, function* () {
65
+ const patterns = [];
66
+ if (packSetting.enableV2) {
67
+ patterns.push({
68
+ noErrorOnMissing: true,
69
+ from: `**/*.{${constant_config_1.ASSETS_EXTS}}`,
70
+ to: 'v2',
71
+ context: project.projectMiniprogramPath,
72
+ globOptions: { gitignore: true }
73
+ });
74
+ }
75
+ if (packSetting.enableV1) {
76
+ patterns.push({
77
+ noErrorOnMissing: true,
78
+ from: `**/*.{${constant_config_1.ASSETS_EXTS}}`,
79
+ to: 'v1',
80
+ context: project.projectMiniprogramPath,
81
+ globOptions: { gitignore: true }
82
+ });
83
+ }
84
+ yield this.copyPatterns.copy({
85
+ compiler,
86
+ compilation,
87
+ cache,
88
+ logger,
89
+ patterns
90
+ });
91
+ callback();
92
+ }));
93
+ });
94
+ }
95
+ emitAppJson(compilation, appJSON) {
96
+ const { project, packSetting, packMode } = this.options;
97
+ const { compilePkgs = [constant_config_1.MAIN_PKG] } = packSetting;
98
+ // const { mainPkg, subPkgs } = packSetting.getCompilePkgsForEntries()
99
+ appJSON.allowLazyAppJs = true; // 允许预加载业务包标识 for 客户端
100
+ // 先删除,用户配置的默认不生效
101
+ Reflect.deleteProperty(appJSON, 'lazyCodeLoading');
102
+ if (packSetting.enableVDom) {
103
+ appJSON.xhsVersionStrategy.enableVDom = true;
104
+ appJSON.usingFramework = '2.0';
105
+ }
106
+ if (packSetting.enableV2) {
107
+ appJSON.xhsVersionStrategy.lazyCodeLoading = true;
108
+ appJSON.lazyCodeLoading = 'requiredComponents';
109
+ }
110
+ const appJsonSource = new packs_1.RawSource(JSON.stringify(appJSON));
111
+ // app.json合并了普通分包的json内容,每次都emit
112
+ if (packSetting.enableV2) {
113
+ this.emitJson(compilation, 'v2/app.json', appJsonSource);
32
114
  }
33
- // app.css 复用
34
- compilation.hooks.processAssets.tap({
35
- name: 'XhsMpAssetsCommonPlugin',
36
- stage: packs_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
37
- }, assets => {
38
- // 删除因为 entry 是 app.(wxss|css) 而产生的的 js 文件
39
- for (const key of Object.keys(assets)) {
40
- if (key === `${usingPackageType}/${const_1.default.ENTRY_CSS_NAME}.js` ||
41
- key === `${usingPackageType}/${const_1.default.ENTRY_CSS_NAME}.js.map`) {
42
- Reflect.deleteProperty(assets, key);
115
+ if (packSetting.enableV1) {
116
+ this.emitJson(compilation, 'v1/app.json', appJsonSource);
117
+ }
118
+ // 独立分包的 app.json
119
+ const subPkgs = project.getSubPackages();
120
+ subPkgs.forEach(subPkg => {
121
+ if (subPkg === null || subPkg === void 0 ? void 0 : subPkg.independent) {
122
+ if (packSetting.enableV2) {
123
+ this.emitJson(compilation, `v2/${subPkg.root}/app.json`, appJsonSource);
43
124
  }
44
- }
45
- // 复用app.css,copy v2到v1
46
- if (packSetting.usingPackageType === 'v2' && packSetting.enableV1) {
47
- if (assets[`${usingPackageType}/app.css`]) {
48
- assets['v1/app.css'] = assets[`${usingPackageType}/app.css`];
125
+ if (packSetting.enableV1) {
126
+ this.emitJson(compilation, `v1/${subPkg.root}/app.json`, appJsonSource);
49
127
  }
50
128
  }
51
129
  });
52
- // 图片等资源
53
- const cache = compilation.getCache('CopyWebpackPlugin');
54
- const logger = compilation.getLogger('XhsMpAssetsCopyPlugin');
55
- compilation.hooks.processAssets.tapAsync({
56
- name: 'XhsMpAssetsCopyPlugin',
57
- stage: packs_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
58
- }, (assets, callback) => __awaiter(this, void 0, void 0, function* () {
59
- const patterns = [];
60
- if (packSetting.enableV2) {
61
- patterns.push({
62
- noErrorOnMissing: true,
63
- from: `**/*.{${const_1.default.ASSETS_EXTS}}`,
64
- to: 'v2',
65
- context: project.projectMiniprogramPath,
66
- globOptions: { gitignore: true }
67
- });
68
- }
69
- if (packSetting.enableV1) {
70
- patterns.push({
71
- noErrorOnMissing: true,
72
- from: `**/*.{${const_1.default.ASSETS_EXTS}}`,
73
- to: 'v1',
74
- context: project.projectMiniprogramPath,
75
- globOptions: { gitignore: true }
76
- });
77
- }
78
- yield this.copyPatterns.copy({
79
- compiler,
80
- compilation,
81
- cache,
82
- logger,
83
- patterns
84
- });
85
- callback();
86
- }));
87
- });
88
- }
89
- emitAppJson(compilation, appJSON) {
90
- const { project, packSetting, packMode } = this.options;
91
- const { compilePkgs = [const_1.default.MAIN_PKG] } = packSetting;
92
- // const { mainPkg, subPkgs } = packSetting.getCompilePkgsForEntries()
93
- // 先删除,用户配置的默认不生效
94
- Reflect.deleteProperty(appJSON, 'lazyCodeLoading');
95
- if (packSetting.enableVDom) {
96
- appJSON.xhsVersionStrategy.enableVDom = true;
97
- appJSON.usingFramework = '2.0';
98
- }
99
- if (packSetting.enableV2) {
100
- appJSON.xhsVersionStrategy.lazyCodeLoading = true;
101
- appJSON.lazyCodeLoading = 'requiredComponents';
102
130
  }
103
- const appJsonSource = new packs_1.RawSource(JSON.stringify(appJSON));
104
- // app.json合并了普通分包的json内容,每次都emit
105
- if (packSetting.enableV2) {
106
- this.emitJson(compilation, 'v2/app.json', appJsonSource);
131
+ emitLegacyAppJSON(compilation, legacyAppJSON) {
132
+ this.emitJson(compilation, 'v0/app.json', new packs_1.RawSource(JSON.stringify(legacyAppJSON)));
107
133
  }
108
- if (packSetting.enableV1) {
109
- this.emitJson(compilation, 'v1/app.json', appJsonSource);
134
+ emitJson(compilation, path, json) {
135
+ compilation.emitAsset(path, json);
110
136
  }
111
- // 独立分包的 app.json
112
- const subPkgs = project.getSubPackages();
113
- subPkgs.forEach(subPkg => {
114
- if (subPkg === null || subPkg === void 0 ? void 0 : subPkg.independent) {
115
- if (packSetting.enableV2) {
116
- this.emitJson(compilation, `v2/${subPkg.root}/app.json`, appJsonSource);
117
- }
118
- if (packSetting.enableV1) {
119
- this.emitJson(compilation, `v1/${subPkg.root}/app.json`, appJsonSource);
120
- }
121
- }
122
- });
123
- }
124
- emitLegacyAppJSON(compilation, legacyAppJSON) {
125
- this.emitJson(compilation, 'v0/app.json', new packs_1.RawSource(JSON.stringify(legacyAppJSON)));
126
- }
127
- emitJson(compilation, path, json) {
128
- // @ts-ignore
129
- compilation.emitAsset(path, json);
130
137
  }
131
- }
132
- exports.default = XhsAssetsPlugin;
138
+ exports.default = XhsAssetsPlugin;
139
+ });
@@ -1,47 +1,49 @@
1
- "use strict";
2
1
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
2
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
3
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.presetAssets = exports.getAssetsEntry = void 0;
7
- const css_1 = __importDefault(require("../../../../utils/css"));
8
- const getSuffixName_1 = require("../../../../utils/getSuffixName");
9
- const assetsEntryPlugin_1 = __importDefault(require("./assetsEntryPlugin"));
10
- const const_1 = __importDefault(require("../../../../utils/const"));
11
- const InjectorPlugin_1 = require("../../../plugins/InjectorPlugin");
12
- const getAssetsEntry = (options) => () => {
13
- const { project, packSetting } = options;
14
- const entry = {};
15
- entry[`${packSetting.usingPackageType}/${const_1.default.ENTRY_CSS_NAME}`] = `${project.projectMiniprogramPath}/app.${(0, getSuffixName_1.getCssSuffixName)()}`;
16
- return entry;
17
- };
18
- exports.getAssetsEntry = getAssetsEntry;
19
- const presetAssets = (chain, options) => {
20
- const { packSetting, project } = options;
21
- const { distDir, enableV1, enableV2 } = packSetting;
22
- const { miniprogramDir } = project;
23
- const cssReg = new RegExp(`.${(0, getSuffixName_1.getCssSuffixName)()}$`);
24
- chain.merge({
25
- output: {
26
- path: distDir
27
- },
28
- // cache: {
29
- // type: 'filesystem',
30
- // cacheDirectory: packSetting.cacheDirectory,
31
- // },
32
- module: {
33
- rule: {
34
- [(0, getSuffixName_1.getCssSuffixName)()]: {
35
- test: cssReg,
36
- use: Object.assign({ 'mini-style-loader': {
37
- loader: require.resolve('../../../loaders/mini-style-loader'),
38
- options: Object.assign(Object.assign({}, options), { independent: true })
39
- } }, (0, css_1.default)(options, ['css-loader', 'postcss-loader', 'wxss-loader']))
4
+ (function (factory) {
5
+ if (typeof module === "object" && typeof module.exports === "object") {
6
+ var v = factory(require, exports);
7
+ if (v !== undefined) module.exports = v;
8
+ }
9
+ else if (typeof define === "function" && define.amd) {
10
+ define(["require", "exports", "../../../../utils/css", "xhs-mp-compiler-utils", "./assetsEntryPlugin", "../../../../config/constant.config", "../../../plugins/InjectorPlugin", "path", "../../../../utils/cache"], factory);
11
+ }
12
+ })(function (require, exports) {
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.presetAssets = exports.getAssetsEntry = void 0;
16
+ const css_1 = __importDefault(require("../../../../utils/css"));
17
+ const xhs_mp_compiler_utils_1 = require("xhs-mp-compiler-utils");
18
+ const assetsEntryPlugin_1 = __importDefault(require("./assetsEntryPlugin"));
19
+ const constant_config_1 = require("../../../../config/constant.config");
20
+ const InjectorPlugin_1 = require("../../../plugins/InjectorPlugin");
21
+ const path_1 = __importDefault(require("path"));
22
+ const cache_1 = require("../../../../utils/cache");
23
+ const getAssetsEntry = (options) => () => {
24
+ const { project, packSetting } = options;
25
+ const entry = {};
26
+ entry[`${packSetting.usingPackageType}/${constant_config_1.ENTRY_CSS_NAME}`] = `${project.projectMiniprogramPath}/app.${(0, xhs_mp_compiler_utils_1.getCssSuffixName)()}`;
27
+ return entry;
28
+ };
29
+ exports.getAssetsEntry = getAssetsEntry;
30
+ const presetAssets = (chain, options) => {
31
+ const { packSetting, project } = options;
32
+ const { distDir, cacheDirectory } = packSetting;
33
+ const absCacheDirectory = path_1.default.join(cacheDirectory, 'assets');
34
+ const cssReg = new RegExp(`.${(0, xhs_mp_compiler_utils_1.getCssSuffixName)()}$`);
35
+ chain.merge(Object.assign(Object.assign({ output: {
36
+ path: distDir
37
+ } }, (0, cache_1.getCacheConfig)(absCacheDirectory, options)), { module: {
38
+ rule: {
39
+ [(0, xhs_mp_compiler_utils_1.getCssSuffixName)()]: {
40
+ test: cssReg,
41
+ use: (0, css_1.default)(packSetting, options, ['mini-style-loader', 'postcss-loader', 'wxss-loader'], true)
42
+ }
40
43
  }
41
- }
42
- }
43
- });
44
- chain.plugin('InjectorPlugin').use(InjectorPlugin_1.InjectorPlugin, [options]);
45
- chain.plugin('XhsMpAssetsPlugin').use(assetsEntryPlugin_1.default, [options]);
46
- };
47
- exports.presetAssets = presetAssets;
44
+ } }));
45
+ chain.plugin('InjectorPlugin').use(InjectorPlugin_1.InjectorPlugin, [options]);
46
+ chain.plugin('XhsMpAssetsPlugin').use(assetsEntryPlugin_1.default, [options]);
47
+ };
48
+ exports.presetAssets = presetAssets;
49
+ });
@@ -1,47 +1,57 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getComponentEntry = void 0;
4
- const xhs_mp_pack_1 = require("xhs-mp-pack");
5
- const getComponentEntry = (options) => {
6
- const entries = {};
7
- const { packSetting } = options;
8
- // 编译v2
9
- if (packSetting.enableV2) {
10
- appendV2Entry(options, entries);
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
11
5
  }
12
- // 构建 v1 的包
13
- if (packSetting.enableV1) {
14
- appendV1Entry(options, entries);
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "xhs-mp-pack"], factory);
15
8
  }
16
- return entries;
17
- };
18
- exports.getComponentEntry = getComponentEntry;
19
- const appendV2Entry = (options, entries) => {
20
- const { project, packSetting } = options;
21
- const subPackages = project.getSubPackages();
22
- const subPackageRoots = subPackages.map(pkg => pkg.root);
23
- const componentsMap = project.getComponentsMap();
24
- const { mainPkg, subPkgs } = packSetting.getCompilePkgsForEntries();
25
- Object.keys(componentsMap).forEach(compPath => {
26
- if (mainPkg && project.isFileInMainPkg(compPath)) {
27
- entries[`v2/${compPath}`] = `mp-entry-loader?type=component&mode=v2&compPath=${compPath}&pkg=${xhs_mp_pack_1.CONSTANTS.MAIN_PKG}!`;
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getComponentEntry = void 0;
13
+ const xhs_mp_pack_1 = require("xhs-mp-pack");
14
+ const getComponentEntry = (options) => {
15
+ const entries = {};
16
+ const { packSetting } = options;
17
+ // 编译v2
18
+ if (packSetting.enableV2) {
19
+ appendV2Entry(options, entries);
28
20
  }
29
- for (const subPkg of subPkgs) {
30
- if (compPath.startsWith(`${subPkg.root}/`)) {
31
- const root = subPackageRoots.find(root => compPath.startsWith(`${root}/`));
32
- entries[`v2/${root}/${compPath}`] = `mp-entry-loader?type=component&mode=v2&compPath=${compPath}&pkg=${xhs_mp_pack_1.CONSTANTS.SUB_PKG}&root=${root}!`;
21
+ // 构建 v1 的包
22
+ if (packSetting.enableV1) {
23
+ appendV1Entry(options, entries);
24
+ }
25
+ return entries;
26
+ };
27
+ exports.getComponentEntry = getComponentEntry;
28
+ const appendV2Entry = (options, entries) => {
29
+ const { project, packSetting } = options;
30
+ const subPackages = project.getSubPackages();
31
+ const subPackageRoots = subPackages.map(pkg => pkg.root);
32
+ const componentsMap = project.getComponentsMap();
33
+ const { mainPkg, subPkgs } = packSetting.getCompilePkgsForEntries();
34
+ Object.keys(componentsMap).forEach(compPath => {
35
+ if (mainPkg && project.isFileInMainPkg(compPath)) {
36
+ entries[`v2/${compPath}`] = `mp-entry-loader?type=component&mode=v2&compPath=${compPath}&pkg=${xhs_mp_pack_1.CONSTANTS.MAIN_PKG}!`;
37
+ }
38
+ for (const subPkg of subPkgs) {
39
+ if (compPath.startsWith(`${subPkg.root}/`)) {
40
+ const root = subPackageRoots.find(root => compPath.startsWith(`${root}/`));
41
+ entries[`v2/${root}/${compPath}`] = `mp-entry-loader?type=component&mode=v2&compPath=${compPath}&pkg=${xhs_mp_pack_1.CONSTANTS.SUB_PKG}&root=${root}!`;
42
+ }
33
43
  }
44
+ });
45
+ };
46
+ function appendV1Entry(options, entries) {
47
+ const { packSetting } = options;
48
+ const { mainPkg, subPkgs } = packSetting.getCompilePkgsForEntries();
49
+ if (mainPkg) {
50
+ entries['v1/components'] = `mp-entry-loader?type=component&mode=v1&pkg=${xhs_mp_pack_1.CONSTANTS.MAIN_PKG}!`;
51
+ }
52
+ for (const subPkg of subPkgs) {
53
+ const { root } = subPkg;
54
+ entries[`v1/${root}/components`] = `mp-entry-loader?type=component&mode=v1&pkg=${xhs_mp_pack_1.CONSTANTS.SUB_PKG}&root=${root}!`;
34
55
  }
35
- });
36
- };
37
- function appendV1Entry(options, entries) {
38
- const { packSetting } = options;
39
- const { mainPkg, subPkgs } = packSetting.getCompilePkgsForEntries();
40
- if (mainPkg) {
41
- entries['v1/components'] = `mp-entry-loader?type=component&mode=v1&pkg=${xhs_mp_pack_1.CONSTANTS.MAIN_PKG}!`;
42
- }
43
- for (const subPkg of subPkgs) {
44
- const { root } = subPkg;
45
- entries[`v1/${root}/components`] = `mp-entry-loader?type=component&mode=v1&pkg=${xhs_mp_pack_1.CONSTANTS.SUB_PKG}&root=${root}!`;
46
56
  }
47
- }
57
+ });
@@ -1,5 +1,4 @@
1
1
  import { Config } from '../../../../packs';
2
2
  import { IPresetOptions } from '../../../../types';
3
- declare const getRenderEntry: (options: IPresetOptions) => () => {};
4
- declare const presetRender: (chain: Config, options: IPresetOptions) => void;
5
- export { getRenderEntry, presetRender };
3
+ export declare const getRenderEntry: (options: IPresetOptions) => () => {};
4
+ export declare const presetRender: (chain: Config, options: IPresetOptions) => void;
@@ -1,73 +1,90 @@
1
- "use strict";
2
1
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
2
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
3
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.presetRender = exports.getRenderEntry = void 0;
7
- const css_1 = __importDefault(require("../../../../utils/css"));
8
- const getSuffixName_1 = require("../../../../utils/getSuffixName");
9
- const sjsEntryPlugin_1 = __importDefault(require("./sjsEntryPlugin"));
10
- const render_1 = require("./render");
11
- const component_1 = require("./component");
12
- const renderChunkPlugin_1 = __importDefault(require("./renderChunkPlugin"));
13
- const types_1 = require("../../../../types");
14
- const InjectorPlugin_1 = require("../../../plugins/InjectorPlugin");
15
- const getRenderEntry = (options) => () => {
16
- const res = Object.assign(Object.assign({}, (0, render_1.getRenderEntry)(options)), (0, component_1.getComponentEntry)(options));
17
- return res;
18
- };
19
- exports.getRenderEntry = getRenderEntry;
20
- const presetRender = (chain, options) => {
21
- const { packSetting } = options;
22
- const { enableVDom, env, distDir, cacheDirectory } = packSetting;
23
- const mlReg = new RegExp(`.${(0, getSuffixName_1.getMlSuffixName)()}$`);
24
- const cssReg = new RegExp(`.${(0, getSuffixName_1.getCssSuffixName)()}$`);
25
- const isProd = env === types_1.ENV.production;
26
- chain.merge({
27
- externals: { vue: 'vue' },
28
- output: {
29
- path: distDir,
30
- globalObject: 'globalThis',
31
- libraryTarget: 'umd',
32
- uniqueName: 'MpRender',
33
- },
34
- // cache: {
35
- // type: 'filesystem',
36
- // cacheDirectory: path.join(cacheDirectory!, 'render'),
37
- // },
38
- module: {
39
- rule: {
40
- ml: {
41
- test: mlReg,
42
- use: {
43
- // 'thread-loader': {
44
- // loader: require.resolve('thread-loader'),
45
- // options: {
46
- // workers: require('os').cpus().length,
47
- // },
48
- // },
49
- 'ml-loader': {
50
- loader: require.resolve('xhs-mp-compiler-ml-loader'),
51
- options: {
52
- removeComentNode: isProd,
53
- vdom: enableVDom,
54
- },
55
- },
4
+ (function (factory) {
5
+ if (typeof module === "object" && typeof module.exports === "object") {
6
+ var v = factory(require, exports);
7
+ if (v !== undefined) module.exports = v;
8
+ }
9
+ else if (typeof define === "function" && define.amd) {
10
+ define(["require", "exports", "../../../../utils/css", "xhs-mp-compiler-utils", "./sjsEntryPlugin", "./render", "./component", "./renderChunkPlugin", "../../../../types", "../../../plugins/InjectorPlugin", "../../../plugins/SourceMapDevToolPlugin", "../../../../utils/cache", "path"], factory);
11
+ }
12
+ })(function (require, exports) {
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.presetRender = exports.getRenderEntry = void 0;
16
+ const css_1 = __importDefault(require("../../../../utils/css"));
17
+ const xhs_mp_compiler_utils_1 = require("xhs-mp-compiler-utils");
18
+ const sjsEntryPlugin_1 = __importDefault(require("./sjsEntryPlugin"));
19
+ const render_1 = require("./render");
20
+ const component_1 = require("./component");
21
+ const renderChunkPlugin_1 = __importDefault(require("./renderChunkPlugin"));
22
+ const types_1 = require("../../../../types");
23
+ const InjectorPlugin_1 = require("../../../plugins/InjectorPlugin");
24
+ const SourceMapDevToolPlugin_1 = require("../../../plugins/SourceMapDevToolPlugin");
25
+ const cache_1 = require("../../../../utils/cache");
26
+ const path_1 = __importDefault(require("path"));
27
+ const getRenderEntry = (options) => () => {
28
+ const entries = Object.assign(Object.assign({}, (0, render_1.getRenderEntry)(options)), (0, component_1.getComponentEntry)(options));
29
+ return entries;
30
+ };
31
+ exports.getRenderEntry = getRenderEntry;
32
+ const presetRender = (chain, options) => {
33
+ const { packSetting } = options;
34
+ const { enableVDom, env, distDir, cacheDirectory, enableSourcemap, appendSourcemapComment } = packSetting;
35
+ const mlReg = new RegExp(`.${(0, xhs_mp_compiler_utils_1.getMlSuffixName)()}$`);
36
+ const cssReg = new RegExp(`.${(0, xhs_mp_compiler_utils_1.getCssSuffixName)()}$`);
37
+ const isProd = env === types_1.ENV.production;
38
+ const absCacheDirectory = path_1.default.join(cacheDirectory, 'render');
39
+ chain.merge(Object.assign(Object.assign({ externals: { vue: 'vue' }, output: {
40
+ path: distDir,
41
+ globalObject: 'globalThis',
42
+ libraryTarget: 'umd',
43
+ uniqueName: 'MpRender',
44
+ } }, (0, cache_1.getCacheConfig)(absCacheDirectory, options)), { module: {
45
+ rule: {
46
+ ml: {
47
+ test: mlReg,
48
+ use: Object.assign(Object.assign({}, (isProd ?
49
+ {
50
+ 'swc-loader': {
51
+ loader: require.resolve('swc-loader'),
52
+ options: {
53
+ jsc: {
54
+ // ?. ?? 运算符号从 es2020支持
55
+ target: 'es2019',
56
+ externalHelpers: false
57
+ },
58
+ }
59
+ }
60
+ } : {})), { 'ml-loader': {
61
+ loader: require.resolve('xhs-mp-ml-loader'),
62
+ options: {
63
+ removeComentNode: isProd,
64
+ vdom: enableVDom,
65
+ },
66
+ } }),
67
+ },
68
+ [(0, xhs_mp_compiler_utils_1.getCssSuffixName)()]: {
69
+ test: cssReg,
70
+ use: (0, css_1.default)(packSetting, options, [
71
+ "mini-style-loader",
72
+ 'postcss-loader',
73
+ 'wxss-loader',
74
+ ]),
56
75
  },
57
76
  },
58
- [(0, getSuffixName_1.getCssSuffixName)()]: {
59
- test: cssReg,
60
- use: (0, css_1.default)(options, [
61
- "mini-style-loader",
62
- 'postcss-loader',
63
- 'wxss-loader',
64
- ]),
65
- },
66
- },
67
- },
68
- });
69
- chain.plugin('InjectorPlugin').use(InjectorPlugin_1.InjectorPlugin, [options]);
70
- chain.plugin('SjsEntryPlugin').use(sjsEntryPlugin_1.default, [options]);
71
- chain.plugin("RenderChunkPlugin").use(renderChunkPlugin_1.default, [options]);
72
- };
73
- exports.presetRender = presetRender;
77
+ } }));
78
+ chain.plugin('InjectorPlugin').use(InjectorPlugin_1.InjectorPlugin, [options]);
79
+ chain.plugin('SjsEntryPlugin').use(sjsEntryPlugin_1.default, [options]);
80
+ chain.plugin("RenderChunkPlugin").use(renderChunkPlugin_1.default, [options]);
81
+ if (enableSourcemap && !appendSourcemapComment) {
82
+ const SourceMapDevToolPlugin = (0, SourceMapDevToolPlugin_1.getSourceMapDevtoolPlugin)(options.packMode);
83
+ chain.plugin('SourceMapDevToolPlugin').use(SourceMapDevToolPlugin, [{
84
+ filename: '[file].map',
85
+ append: false
86
+ }]);
87
+ }
88
+ };
89
+ exports.presetRender = presetRender;
90
+ });