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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
2
  if (k2 === undefined) k2 = k;
4
3
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -22,175 +21,185 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
21
  __setModuleDefault(result, mod);
23
22
  return result;
24
23
  };
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);
24
+ (function (factory) {
25
+ if (typeof module === "object" && typeof module.exports === "object") {
26
+ var v = factory(require, exports);
27
+ if (v !== undefined) module.exports = v;
38
28
  }
39
- let name = 'XHS_COMPONENTS';
40
- if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG) {
41
- name = `XHS_COMPONENTS_${root}`;
29
+ else if (typeof define === "function" && define.amd) {
30
+ define(["require", "exports", "fs-extra", "path", "xhs-mp-pack", "../../utils/loader-utils", "xhs-mp-compiler-utils"], factory);
42
31
  }
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();
32
+ })(function (require, exports) {
33
+ "use strict";
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ const fs_extra_1 = __importStar(require("fs-extra"));
36
+ const path_1 = __importStar(require("path"));
37
+ const xhs_mp_pack_1 = require("xhs-mp-pack");
38
+ const loader_utils_1 = require("../../utils/loader-utils");
39
+ const xhs_mp_compiler_utils_1 = require("xhs-mp-compiler-utils");
40
+ function genComponentLoaderScript(project, context, opts) {
41
+ const { pkg, root, mode, compPath } = opts;
42
+ const { projectMiniprogramPath, jsonDependencies = [] } = project;
43
+ const componentsMap = project.getComponentsMap();
44
+ const entries = [];
45
+ for (const file of jsonDependencies) {
46
+ context.addDependency(file);
55
47
  }
56
- if (pkg === xhs_mp_pack_1.CONSTANTS.MAIN_PKG && project.isFileInMainPkg(compPath)) {
57
- push();
48
+ let name = 'XHS_COMPONENTS';
49
+ if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG) {
50
+ name = `XHS_COMPONENTS_${root}`;
58
51
  }
59
- if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG && compPath.startsWith(`${root}/`)) {
60
- push();
52
+ // v2
53
+ if (mode === 'v2') {
54
+ return `
55
+ ;(globalThis['${name}'] || (globalThis['${name}'] = { default: {} }))
56
+ ;globalThis['${name}'].default['${compPath}'] = () => require('${(0, loader_utils_1.formatPath)(path_1.default.join(projectMiniprogramPath, `${compPath}.${(0, xhs_mp_compiler_utils_1.getMlSuffixName)()}`))}')
57
+ `;
61
58
  }
62
- });
63
- return `
59
+ // v1和v0
60
+ Object.keys(componentsMap).forEach(compPath => {
61
+ const push = () => entries.push(`;globalThis['${name}'].default['${compPath}'] = () => require('${(0, loader_utils_1.formatPath)(path_1.default.join(projectMiniprogramPath, `${compPath}.${(0, xhs_mp_compiler_utils_1.getMlSuffixName)()}`))}')`);
62
+ if (pkg === xhs_mp_pack_1.CONSTANTS.FULL_PKG) {
63
+ push();
64
+ }
65
+ if (pkg === xhs_mp_pack_1.CONSTANTS.MAIN_PKG && project.isFileInMainPkg(compPath)) {
66
+ push();
67
+ }
68
+ if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG && compPath.startsWith(`${root}/`)) {
69
+ push();
70
+ }
71
+ });
72
+ return `
64
73
  ;(globalThis['${name}'] || (globalThis['${name}'] = { default: {} }))
65
74
  ;${entries.join('\n ')}
66
75
  `;
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
76
  }
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);
77
+ const genRenderLoaderScript = (project, context, opts) => {
78
+ const { projectMiniprogramPath, appJSON, jsonDependencies } = project;
79
+ const { pkg, mode } = opts;
80
+ const isFull = pkg === 'full';
81
+ for (const file of jsonDependencies) {
82
+ context.addDependency(file);
100
83
  }
101
- return `
84
+ const appCssPath = (0, path_1.resolve)(projectMiniprogramPath, 'app.css');
85
+ const appCssExist = (0, fs_extra_1.existsSync)(appCssPath);
86
+ const resourcePath = (0, loader_utils_1.formatPath)(context.resourcePath);
87
+ const path = (0, loader_utils_1.formatPath)(resourcePath.replace(`${projectMiniprogramPath}/`, '').replace(`.${(0, xhs_mp_compiler_utils_1.getMlSuffixName)()}`, ''));
88
+ const subPackage = (appJSON.subPackages || []).find(subPack => !!subPack.pages.find(page => page.path === path));
89
+ const enableLazyCodeLoading = mode === 'v2';
90
+ // 资源文件
91
+ const resources = (0, loader_utils_1.getResourceUris)({
92
+ appCssExist,
93
+ subPackage,
94
+ enableLazyCodeLoading
95
+ });
96
+ // 开启了按需注入,注入依赖组件
97
+ if (enableLazyCodeLoading) {
98
+ const isIndependent = (subPackage === null || subPackage === void 0 ? void 0 : subPackage.independent) || false;
99
+ const dependsTree = project.getPageDependComponentPaths(path, isIndependent);
100
+ const subPackagesPrefix = (appJSON.subPackages || []).map(sub => sub.root);
101
+ const depends = [];
102
+ for (let i = 0; i < dependsTree.length; i++) {
103
+ let uri = dependsTree[i];
104
+ const subRoot = subPackagesPrefix.find(subRoot => uri.startsWith(`${subRoot}/`));
105
+ if (subRoot) {
106
+ uri = `${subRoot}/${uri}`;
107
+ }
108
+ depends.push(uri);
109
+ }
110
+ return `
102
111
  import Component from '${resourcePath}';
103
112
  globalThis.__render.mount(Component, '${path}', ${JSON.stringify(resources)}, ${JSON.stringify(depends)})
104
113
  `;
105
- }
106
- return `
114
+ }
115
+ return `
107
116
  import Component from '${resourcePath}';
108
117
  globalThis.__render.mount(Component, '${path}', ${JSON.stringify(resources)})
109
118
  `;
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
119
  };
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}')`);
120
+ function genServiceLoderScript(project, context, opts) {
121
+ const { appJSON, legacyAppJSON, projectMiniprogramPath, jsonDependencies } = project;
122
+ const { pkg, root } = opts;
123
+ const modules = [];
124
+ let name = 'XHS_SERVICE';
125
+ if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG) {
126
+ name = `XHS_SERVICE_${root}`;
133
127
  }
134
- }
135
- else {
136
- if (pkg === xhs_mp_pack_1.CONSTANTS.MAIN_PKG) {
128
+ for (const file of jsonDependencies) {
129
+ context.addDependency(file);
130
+ }
131
+ const addAppJs = () => {
132
+ if (fs_extra_1.default.existsSync(`${projectMiniprogramPath}/app.js`) ||
133
+ fs_extra_1.default.existsSync(`${projectMiniprogramPath}/app.ts`)) {
134
+ modules.unshift(`const loadAppJs = () => require('${(0, loader_utils_1.formatPath)(`${projectMiniprogramPath}/app`)}');` +
135
+ `globalThis['${name}'].default['app'] = globalThis.xhsLazyAppJs ? loadAppJs : loadAppJs()`);
136
+ }
137
+ };
138
+ if (pkg === xhs_mp_pack_1.CONSTANTS.FULL_PKG) {
137
139
  addAppJs();
140
+ for (const page of legacyAppJSON.pages) {
141
+ const resourcePath = (0, loader_utils_1.formatPath)(`${projectMiniprogramPath}/${page.path}`);
142
+ modules.push(`;globalThis['${name}'].default['${page.path}'] = () => require('${resourcePath}')`);
143
+ }
138
144
  }
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}')`;
145
+ else {
146
+ if (pkg === xhs_mp_pack_1.CONSTANTS.MAIN_PKG) {
147
+ addAppJs();
148
+ }
149
+ for (const page of legacyAppJSON.pages) {
150
+ const resourcePath = (0, loader_utils_1.formatPath)(`${projectMiniprogramPath}/${page.path}`);
151
+ const content = `;globalThis['${name}'].default['${page.path}'] = () => require('${resourcePath}')`;
152
+ if (pkg === xhs_mp_pack_1.CONSTANTS.MAIN_PKG) {
153
+ const subPackageRoots = appJSON.subPackages.map(pkg => pkg.root);
154
+ if (subPackageRoots.every(root => !page.path.startsWith(`${root}/`))) {
155
+ modules.push(content);
156
+ }
157
+ }
158
+ if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG) {
159
+ if (page.path.startsWith(`${root}/`)) {
160
+ modules.push(content);
161
+ }
162
+ }
163
+ }
164
+ }
165
+ Object.keys(appJSON.componentsMap).forEach(compPath => {
166
+ const resourcePath = (0, loader_utils_1.formatPath)(`${projectMiniprogramPath}/${compPath}`);
167
+ const content = `;globalThis['${name}'].default['${compPath}'] = () => require('${resourcePath}')`;
168
+ if (pkg === xhs_mp_pack_1.CONSTANTS.FULL_PKG) {
169
+ modules.push(content);
170
+ }
142
171
  if (pkg === xhs_mp_pack_1.CONSTANTS.MAIN_PKG) {
143
172
  const subPackageRoots = appJSON.subPackages.map(pkg => pkg.root);
144
- if (subPackageRoots.every(root => !page.path.startsWith(`${root}/`))) {
173
+ if (subPackageRoots.every(root => !compPath.startsWith(`${root}/`))) {
145
174
  modules.push(content);
146
175
  }
147
176
  }
148
177
  if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG) {
149
- if (page.path.startsWith(`${root}/`)) {
178
+ if (compPath.startsWith(`${root}/`)) {
150
179
  modules.push(content);
151
180
  }
152
181
  }
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)};
182
+ });
183
+ const runtimeJSON = pkg === xhs_mp_pack_1.CONSTANTS.FULL_PKG ? legacyAppJSON : appJSON;
184
+ return `;globalThis['__MP_APP_JSON__'] = ${JSON.stringify(runtimeJSON)};
175
185
  ;(globalThis['${name}'] || (globalThis['${name}'] = { default: {} }))
176
186
  ${modules.join('\n ')}
177
187
  `;
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
188
  }
193
- // @ts-ignore
194
- return handler(this._compiler.project, this, options);
195
- }
196
- module.exports = entryLoader;
189
+ function entryLoader() {
190
+ // @ts-ignore
191
+ const options = this.getOptions();
192
+ const { type } = options;
193
+ const handelrs = {
194
+ render: genRenderLoaderScript,
195
+ component: genComponentLoaderScript,
196
+ service: genServiceLoderScript
197
+ };
198
+ const handler = handelrs[type];
199
+ if (!handler) {
200
+ throw new Error(`not found loader handler of ${type}`);
201
+ }
202
+ return handler(this._compiler.project, this, options);
203
+ }
204
+ module.exports = entryLoader;
205
+ });
@@ -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) {
@@ -11,67 +10,78 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
10
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
11
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
12
  };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const postcss_1 = __importDefault(require("postcss"));
16
- const postcss_import_1 = __importDefault(require("postcss-import"));
17
- const postcss_prefix_selector_1 = __importDefault(require("postcss-prefix-selector"));
18
- const CssSyntaxError_1 = __importDefault(require("css-loader/dist/CssSyntaxError"));
19
- const tagTransformMap_1 = __importDefault(require("../../utils/tagTransformMap"));
20
- const getSuffixName_1 = require("../../utils/getSuffixName");
21
- const common_1 = require("../../utils/common");
22
- const tags = Object.keys(tagTransformMap_1.default).join('|');
23
- const labelStr = `(^|\\s)(${tags}|page|audio|live-player|map|cover-view|cover-image|video)`;
24
- const labelReg = new RegExp(labelStr, 'g');
25
- function wxssLoader(source) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- var _a, _b, _c, _d, _e;
28
- const done = this.async();
29
- const { project } = this._compiler;
30
- const { appJSON = {}, miniprogramDir = '' } = project || {};
31
- const shortPath = (0, common_1.getShortPath)(miniprogramDir, this.resourcePath).replace(new RegExp(`\\.${(0, getSuffixName_1.getCssSuffixName)()}$`), '');
32
- const index = (_c = (_b = (_a = appJSON === null || appJSON === void 0 ? void 0 : appJSON.componentsMap) === null || _a === void 0 ? void 0 : _a[shortPath]) === null || _b === void 0 ? void 0 : _b.index) !== null && _c !== void 0 ? _c : null;
33
- const styleIsolation = (_e = (_d = appJSON === null || appJSON === void 0 ? void 0 : appJSON.componentsMap) === null || _d === void 0 ? void 0 : _d[shortPath]) === null || _e === void 0 ? void 0 : _e.styleIsolation;
34
- const selectorIndex = styleIsolation === 'shared' ? 0 : index || 0;
35
- // js / json 的配置会影响样式
36
- const extReg = new RegExp(`${(0, getSuffixName_1.getCssSuffixName)()}$`);
37
- this.addDependency(this.resourcePath.replace(extReg, 'js'));
38
- this.addDependency(this.resourcePath.replace(extReg, 'json'));
39
- (0, postcss_1.default)()
40
- // @ts-ignore
41
- .use((0, postcss_import_1.default)({ root: miniprogramDir }))
42
- .use((0, postcss_prefix_selector_1.default)({
43
- prefix: 'xhs',
44
- transform(prefix, selector) {
45
- // 支持 host 选择器 https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html
46
- if (selector === ':host') {
47
- return `[is="${shortPath}"]`;
48
- }
49
- /**
50
- * 替换所有类选择器,用于做样式隔离 wiki: https://wiki.xiaohongshu.com/pages/viewpage.action?pageId=181017177
51
- * .app -> .xhs_0_app
52
- */
53
- selector = selector.replace(/\.(\w)/g, `.xhs_${selectorIndex}_$1`);
54
- // 为内置组件加上 xhs 前缀
55
- if (selector.match(labelReg)) {
56
- selector = selector.replace(labelReg, `$1${prefix}-$2`);
57
- }
58
- return selector;
59
- },
60
- }))
61
- .process(source, {
62
- from: this.resourcePath,
63
- })
64
- .then(result => {
65
- result.messages.forEach(({ file, type }) => {
66
- if (type === 'dependency') {
67
- this.addDependency(file);
68
- }
13
+ (function (factory) {
14
+ if (typeof module === "object" && typeof module.exports === "object") {
15
+ var v = factory(require, exports);
16
+ if (v !== undefined) module.exports = v;
17
+ }
18
+ else if (typeof define === "function" && define.amd) {
19
+ define(["require", "exports", "postcss", "postcss-import", "postcss-prefix-selector", "css-loader/dist/CssSyntaxError", "xhs-mp-ml-parser", "xhs-mp-compiler-utils", "../../utils/common"], factory);
20
+ }
21
+ })(function (require, exports) {
22
+ "use strict";
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ const postcss_1 = __importDefault(require("postcss"));
25
+ const postcss_import_1 = __importDefault(require("postcss-import"));
26
+ const postcss_prefix_selector_1 = __importDefault(require("postcss-prefix-selector"));
27
+ const CssSyntaxError_1 = __importDefault(require("css-loader/dist/CssSyntaxError"));
28
+ const xhs_mp_ml_parser_1 = require("xhs-mp-ml-parser");
29
+ const xhs_mp_compiler_utils_1 = require("xhs-mp-compiler-utils");
30
+ const common_1 = require("../../utils/common");
31
+ const tags = Object.keys(xhs_mp_ml_parser_1.tagTransformMap).join('|');
32
+ const labelStr = `(^|\\s)(${tags}|audio|live-player|cover-view|cover-image)`;
33
+ const labelReg = new RegExp(labelStr, 'g');
34
+ function wxssLoader(source) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ var _a, _b, _c, _d, _e;
37
+ const done = this.async();
38
+ const { project } = this._compiler;
39
+ const { appJSON = {}, miniprogramDir = '' } = project || {};
40
+ const shortPath = (0, common_1.getShortPath)(miniprogramDir, this.resourcePath).replace(new RegExp(`\\.${(0, xhs_mp_compiler_utils_1.getCssSuffixName)()}$`), '');
41
+ const index = (_c = (_b = (_a = appJSON === null || appJSON === void 0 ? void 0 : appJSON.componentsMap) === null || _a === void 0 ? void 0 : _a[shortPath]) === null || _b === void 0 ? void 0 : _b.index) !== null && _c !== void 0 ? _c : null;
42
+ const styleIsolation = (_e = (_d = appJSON === null || appJSON === void 0 ? void 0 : appJSON.componentsMap) === null || _d === void 0 ? void 0 : _d[shortPath]) === null || _e === void 0 ? void 0 : _e.styleIsolation;
43
+ const selectorIndex = styleIsolation === 'shared' ? 0 : index || 0;
44
+ // js / json 的配置会影响样式
45
+ const extReg = new RegExp(`${(0, xhs_mp_compiler_utils_1.getCssSuffixName)()}$`);
46
+ this.addDependency(this.resourcePath.replace(extReg, 'js'));
47
+ this.addDependency(this.resourcePath.replace(extReg, 'json'));
48
+ (0, postcss_1.default)()
49
+ // @ts-ignore
50
+ .use((0, postcss_import_1.default)({ root: miniprogramDir }))
51
+ .use((0, postcss_prefix_selector_1.default)({
52
+ prefix: 'xhs',
53
+ transform(prefix, selector) {
54
+ // 支持 host 选择器 https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html
55
+ if (selector === ':host') {
56
+ return `[is="${shortPath}"]`;
57
+ }
58
+ /**
59
+ * 替换所有类选择器,用于做样式隔离 wiki: https://wiki.xiaohongshu.com/pages/viewpage.action?pageId=181017177
60
+ * .app -> .xhs_0_app
61
+ */
62
+ selector = selector.replace(/\.(\w)/g, `.xhs_${selectorIndex}_$1`);
63
+ // 为内置组件加上 xhs 前缀
64
+ if (selector.match(labelReg)) {
65
+ selector = selector.replace(labelReg, `$1${prefix}-$2`);
66
+ }
67
+ return selector;
68
+ },
69
+ }))
70
+ .process(source, {
71
+ from: this.resourcePath,
72
+ })
73
+ .then(result => {
74
+ result.messages.forEach(({ file, type }) => {
75
+ if (type === 'dependency') {
76
+ this.addDependency(file);
77
+ }
78
+ });
79
+ done(null, result.css);
80
+ })
81
+ .catch(error => {
82
+ done(error.name === 'CssSyntaxError' ? new CssSyntaxError_1.default(error) : error);
69
83
  });
70
- done(null, result.css);
71
- })
72
- .catch(error => {
73
- done(error.name === 'CssSyntaxError' ? new CssSyntaxError_1.default(error) : error);
74
84
  });
75
- });
76
- }
77
- module.exports = wxssLoader;
85
+ }
86
+ module.exports = wxssLoader;
87
+ });
@@ -1,15 +1,25 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InjectorPlugin = void 0;
4
- class InjectorPlugin {
5
- constructor(options) {
6
- this.options = options;
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;
7
5
  }
8
- apply(compiler) {
9
- const { project, packSetting, reporter } = this.options;
10
- compiler.project = project;
11
- compiler.packSetting = packSetting;
12
- compiler.reporter = reporter;
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
13
8
  }
14
- }
15
- exports.InjectorPlugin = InjectorPlugin;
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.InjectorPlugin = void 0;
13
+ class InjectorPlugin {
14
+ constructor(options) {
15
+ this.options = options;
16
+ }
17
+ apply(compiler) {
18
+ const { project, packSetting, reporter } = this.options;
19
+ compiler.project = project;
20
+ compiler.packSetting = packSetting;
21
+ compiler.reporter = reporter;
22
+ }
23
+ }
24
+ exports.InjectorPlugin = InjectorPlugin;
25
+ });
@@ -0,0 +1 @@
1
+ export declare const getSourceMapDevtoolPlugin: (packMode: any) => any;
@@ -0,0 +1,23 @@
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;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "../../config/constant.config"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getSourceMapDevtoolPlugin = void 0;
13
+ const constant_config_1 = require("../../config/constant.config");
14
+ const getSourceMapDevtoolPlugin = (packMode) => {
15
+ if (packMode === constant_config_1.PACK_MODE.WEBPACK) {
16
+ const { SourceMapDevToolPlugin } = require('webpack');
17
+ return SourceMapDevToolPlugin;
18
+ }
19
+ const { SourceMapDevToolPlugin } = require('xhs-mp-pack');
20
+ return SourceMapDevToolPlugin;
21
+ };
22
+ exports.getSourceMapDevtoolPlugin = getSourceMapDevtoolPlugin;
23
+ });