xhs-mp-compiler-cli 1.9.6 → 1.9.7

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.
@@ -22,7 +22,8 @@ export interface ForkWebpackOption {
22
22
  }
23
23
  export interface ICheckOptions {
24
24
  compilePkgs?: string[];
25
- compressJs: boolean;
25
+ compressCss?: boolean;
26
+ compressJs?: boolean;
26
27
  enableV2?: boolean;
27
28
  enableV1?: boolean;
28
29
  }
package/dist/compiler.js CHANGED
@@ -91,9 +91,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
91
91
  }
92
92
  }
93
93
  kill() {
94
- // if (this.pool) {
95
- // this.pool.terminate(true)
96
- // }
94
+ if (this.pool) {
95
+ this.pool.terminate(true);
96
+ this.pool = null;
97
+ }
97
98
  }
98
99
  }
99
100
  exports.AbstractCompiler = AbstractCompiler;
@@ -346,7 +347,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
346
347
  }
347
348
  finally {
348
349
  // 进程不退出,手动kill下
349
- this.kill();
350
+ // this.kill()
350
351
  }
351
352
  });
352
353
  }
package/dist/index.d.ts CHANGED
@@ -21,8 +21,10 @@ export type ICompilerProps = ({
21
21
  project: Project;
22
22
  }) & ICompileOpts;
23
23
  interface ICompileBaseConfig {
24
- compressJs: boolean;
25
- enableSourcemap: boolean;
24
+ compressCss?: boolean;
25
+ compressJs?: boolean;
26
+ enableSourcemap?: boolean;
27
+ appendSourcemapComment?: boolean;
26
28
  enableV2: boolean;
27
29
  enableV1: boolean;
28
30
  enableVDom: boolean;
package/dist/index.js CHANGED
@@ -142,7 +142,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
142
142
  enableV2 = supportV2 && settings.enableV2;
143
143
  // 开启v2不编译vdom
144
144
  enableVDom = !enableV2 && supportVDom && settings.enableVDom;
145
- // enableVDom = !enableV2 && settings.enableVDom
146
145
  enableV1 = !enableV2;
147
146
  }
148
147
  else {
@@ -246,17 +245,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
246
245
  return __awaiter(this, void 0, void 0, function* () {
247
246
  var _a, _b, _c;
248
247
  try {
249
- const { entryType, compressJs, enableSourcemap, enableV2, enableV1, enableVDom, mpUploadOptions } = config;
248
+ const { entryType, compressCss, compressJs, enableSourcemap, appendSourcemapComment, enableV2, enableV1, enableVDom, mpUploadOptions } = config;
250
249
  this.emit('compile-project-start');
251
250
  (_a = this.logger) === null || _a === void 0 ? void 0 : _a.log('Compile project...');
252
251
  const compilerImpl = this.getComilerImpl(entryType);
253
252
  yield compilerImpl.build({
253
+ compressCss,
254
254
  compressJs,
255
255
  enableSourcemap,
256
+ appendSourcemapComment,
256
257
  enableV2,
257
258
  enableV1,
258
259
  enableVDom,
259
- mpUploadOptions,
260
+ mpUploadOptions
260
261
  });
261
262
  this.emit('compile-project-done');
262
263
  (_b = this.logger) === null || _b === void 0 ? void 0 : _b.log('Compile project done');
@@ -278,6 +279,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
278
279
  }
279
280
  compileAndZip(opts) {
280
281
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
282
+ var _a;
281
283
  const { can_upload_ext_json, upload_app_id, entryType } = opts;
282
284
  try {
283
285
  const appJsonContent = this.project.appJsonContent;
@@ -288,18 +290,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
288
290
  this.project.appMode === constant_config_1.MiniMode.miniprogram ? subPackages : formatGameAppJSON(subPackages);
289
291
  const { enableV2, enableV1, enableVDom } = yield this.getUsingPackageType(entryType);
290
292
  let compressJs = false;
293
+ let compressCss = false;
291
294
  let enableSourcemap = true;
292
- if (entryType === constant_config_1.COMPILE_ENTRY.upload || entryType === constant_config_1.COMPILE_ENTRY.preview) {
295
+ let appendSourcemapComment = true;
296
+ if (entryType === constant_config_1.COMPILE_ENTRY.preview) {
297
+ compressCss = true;
293
298
  compressJs = true;
294
- enableSourcemap = false;
295
299
  }
296
- else if (settings.hasOwnProperty('minified')) {
297
- compressJs = settings.minified;
300
+ else if (entryType === constant_config_1.COMPILE_ENTRY.upload) {
301
+ compressCss = true;
302
+ compressJs = true;
303
+ enableSourcemap = true;
304
+ appendSourcemapComment = false;
305
+ }
306
+ else {
307
+ compressCss = false;
308
+ compressJs = (_a = settings.minified) !== null && _a !== void 0 ? _a : false;
309
+ enableSourcemap = true;
310
+ appendSourcemapComment = true;
298
311
  }
299
312
  const buildConfig = {
300
313
  entryType,
314
+ compressCss,
301
315
  compressJs,
302
316
  enableSourcemap,
317
+ appendSourcemapComment,
303
318
  enableV2,
304
319
  enableV1,
305
320
  enableVDom,
@@ -19,7 +19,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
19
19
  const apm_1 = require("../../utils/apm");
20
20
  const constant_config_1 = require("../../config/constant.config");
21
21
  const createCompiler = (startConfig) => {
22
- // const {action, enableDevServer} = startConfig
23
22
  const mppack = new xhs_mp_pack_1.MPPack(startConfig);
24
23
  const compilerOptions = {
25
24
  project: mppack.project,
@@ -42,7 +42,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
42
42
  };
43
43
  };
44
44
  const formatCompilerConfig = startConfig => {
45
- const { projectPath, action, tsConfigPath, platform, extJsonPath, compressJs = false, enableSourcemap = false, mpUploadOptions = false } = startConfig;
45
+ const { projectPath, action, tsConfigPath, platform, extJsonPath, compressCss = false, compressJs = false, enableSourcemap = false, appendSourcemapComment = false, mpUploadOptions = false } = startConfig;
46
46
  const { enableV1, enableV2, enableVDom } = handleVersion(startConfig);
47
47
  const distDir = startConfig.distDir || path_1.default.join(process.cwd(), 'dist');
48
48
  process.env.__platform = platform;
@@ -67,8 +67,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
67
67
  env: action === 'dev' ? types_1.ENV.development : types_1.ENV.production,
68
68
  tsConfigPath: tsConfigPath || (0, common_1.getTsConfigPath)(projectPath),
69
69
  cacheDirectory: startConfig.cacheDirectory,
70
+ compressCss,
70
71
  compressJs,
71
72
  enableSourcemap,
73
+ appendSourcemapComment,
72
74
  enableV1,
73
75
  enableV2,
74
76
  enableVDom,
@@ -77,7 +79,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
77
79
  return config;
78
80
  };
79
81
  const createPacker = (startConfig) => {
80
- const { projectPath, action, enableDevServer } = startConfig;
82
+ const { projectPath } = startConfig;
81
83
  startConfig = formatCompilerConfig(startConfig);
82
84
  const project = new xhs_mp_project_1.Project({
83
85
  projectPath,
@@ -15,7 +15,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
15
15
  const path_1 = __importDefault(require("path"));
16
16
  const presetCommon = (chain, options) => {
17
17
  const { packSetting, project } = options;
18
- const { env, watch, enableSourcemap, cacheDirectory } = packSetting;
18
+ const { action, enableSourcemap } = packSetting;
19
19
  chain.merge({
20
20
  stats: 'errors-only',
21
21
  output: {
@@ -35,24 +35,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
35
  extensions: ['.js', '.ts'],
36
36
  },
37
37
  });
38
- chain.watch(!!watch);
38
+ chain.watch(action === 'dev');
39
39
  chain.mode('development');
40
40
  chain.devtool(enableSourcemap ? 'source-map' : false);
41
41
  // @ts-ignore
42
42
  chain.target(['web', 'es5']);
43
- // chain.cache(
44
- // env === ENV.production
45
- // ? false
46
- // : {
47
- // type: 'filesystem',
48
- // cacheDirectory:
49
- // cacheDirectory || path.join(__dirname, '../../node_modules/.cache'),
50
- // version: project.miniprogramDir,
51
- // buildDependencies: {
52
- // config: [path.join(project.miniprogramDir, 'app.json')],
53
- // },
54
- // },
55
- // )
56
43
  };
57
44
  exports.default = presetCommon;
58
45
  });
@@ -7,7 +7,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7
7
  if (v !== undefined) module.exports = v;
8
8
  }
9
9
  else if (typeof define === "function" && define.amd) {
10
- define(["require", "exports", "path", "./serviceEntryPlugin", "./serviceChunkPlugin", "./resolveLimitPlugin", "../../../plugins/InjectorPlugin", "../../../../utils/cache"], factory);
10
+ define(["require", "exports", "path", "./serviceEntryPlugin", "./serviceChunkPlugin", "./resolveLimitPlugin", "../../../plugins/InjectorPlugin", "../../../plugins/SourceMapDevToolPlugin", "../../../../utils/cache"], factory);
11
11
  }
12
12
  })(function (require, exports) {
13
13
  "use strict";
@@ -18,10 +18,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  const serviceChunkPlugin_1 = __importDefault(require("./serviceChunkPlugin"));
19
19
  const resolveLimitPlugin_1 = __importDefault(require("./resolveLimitPlugin"));
20
20
  const InjectorPlugin_1 = require("../../../plugins/InjectorPlugin");
21
+ const SourceMapDevToolPlugin_1 = require("../../../plugins/SourceMapDevToolPlugin");
21
22
  const cache_1 = require("../../../../utils/cache");
22
23
  const presetService = (chain, options) => {
23
24
  const { packSetting } = options;
24
- const { distDir, cacheDirectory } = packSetting;
25
+ const { distDir, cacheDirectory, enableSourcemap, appendSourcemapComment } = packSetting;
25
26
  const absCacheDirectory = path_1.default.join(cacheDirectory, 'service');
26
27
  chain.merge(Object.assign(Object.assign({}, (0, cache_1.getCacheConfig)(absCacheDirectory, options)), { output: {
27
28
  path: distDir,
@@ -30,6 +31,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
30
31
  chain.plugin('InjectorPlugin').use(InjectorPlugin_1.InjectorPlugin, [options]);
31
32
  chain.plugin('ServiceEntryPlugin').use(serviceEntryPlugin_1.default, [options]);
32
33
  chain.plugin('ServiceChunkPlugin').use(serviceChunkPlugin_1.default, [options]);
34
+ if (enableSourcemap && !appendSourcemapComment) {
35
+ const SourceMapDevToolPlugin = (0, SourceMapDevToolPlugin_1.getSourceMapDevtoolPlugin)(options.packMode);
36
+ chain.plugin('SourceMapDevToolPlugin').use(SourceMapDevToolPlugin, [{
37
+ filename: '[file].map',
38
+ append: false
39
+ }]);
40
+ }
33
41
  chain.resolve.plugin('ResolveLimitPlugin').use(resolveLimitPlugin_1.default, [options]);
34
42
  chain.optimization
35
43
  .runtimeChunk({
@@ -7,7 +7,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7
7
  if (v !== undefined) module.exports = v;
8
8
  }
9
9
  else if (typeof define === "function" && define.amd) {
10
- define(["require", "exports", "../../../../utils/css", "../../../../utils/getSuffixName", "./sjsEntryPlugin", "./render", "./component", "./renderChunkPlugin", "../../../../types", "../../../plugins/InjectorPlugin", "../../../../utils/cache", "path"], factory);
10
+ define(["require", "exports", "../../../../utils/css", "../../../../utils/getSuffixName", "./sjsEntryPlugin", "./render", "./component", "./renderChunkPlugin", "../../../../types", "../../../plugins/InjectorPlugin", "../../../plugins/SourceMapDevToolPlugin", "../../../../utils/cache", "path"], factory);
11
11
  }
12
12
  })(function (require, exports) {
13
13
  "use strict";
@@ -21,6 +21,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
21
21
  const renderChunkPlugin_1 = __importDefault(require("./renderChunkPlugin"));
22
22
  const types_1 = require("../../../../types");
23
23
  const InjectorPlugin_1 = require("../../../plugins/InjectorPlugin");
24
+ const SourceMapDevToolPlugin_1 = require("../../../plugins/SourceMapDevToolPlugin");
24
25
  const cache_1 = require("../../../../utils/cache");
25
26
  const path_1 = __importDefault(require("path"));
26
27
  const getRenderEntry = (options) => () => {
@@ -30,7 +31,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
30
31
  exports.getRenderEntry = getRenderEntry;
31
32
  const presetRender = (chain, options) => {
32
33
  const { packSetting } = options;
33
- const { enableVDom, env, distDir, cacheDirectory } = packSetting;
34
+ const { enableVDom, env, distDir, cacheDirectory, enableSourcemap, appendSourcemapComment } = packSetting;
34
35
  const mlReg = new RegExp(`.${(0, getSuffixName_1.getMlSuffixName)()}$`);
35
36
  const cssReg = new RegExp(`.${(0, getSuffixName_1.getCssSuffixName)()}$`);
36
37
  const isProd = env === types_1.ENV.production;
@@ -77,6 +78,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
77
78
  chain.plugin('InjectorPlugin').use(InjectorPlugin_1.InjectorPlugin, [options]);
78
79
  chain.plugin('SjsEntryPlugin').use(sjsEntryPlugin_1.default, [options]);
79
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
+ }
80
88
  };
81
89
  exports.presetRender = presetRender;
82
90
  });
@@ -12,12 +12,13 @@
12
12
  const packs_1 = require("../../../../packs");
13
13
  const injectCSS = `
14
14
  globalThis.__XHS_IS_WEBVIEW = (globalThis.localStorage && globalThis.document && globalThis.document.querySelectorAll)
15
- globalThis.__XHS_APPEND_CSS = function(cssText){
15
+ globalThis.__XHS_APPEND_CSS = function(cssText, src){
16
16
  if (!globalThis.__XHS_IS_WEBVIEW) return;
17
17
  var headTags = document.getElementsByTagName('head')
18
18
  var head = document.head || (headTags && headTags[0])
19
19
  var cssTextNode = document.createTextNode(String(cssText))
20
20
  var styleNode = document.createElement('style')
21
+ styleNode.setAttribute('xhs:path', src)
21
22
  styleNode.appendChild(cssTextNode)
22
23
  head.appendChild(styleNode)
23
24
  };
@@ -7,7 +7,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7
7
  if (v !== undefined) module.exports = v;
8
8
  }
9
9
  else if (typeof define === "function" && define.amd) {
10
- define(["require", "exports", "path", "xhs-mp-pack", "./serviceChunkPlugin", "../../../plugins/InjectorPlugin", "../../../../utils/cache"], factory);
10
+ define(["require", "exports", "path", "xhs-mp-pack", "./serviceChunkPlugin", "../../../plugins/InjectorPlugin", "../../../plugins/SourceMapDevToolPlugin", "../../../../utils/cache"], factory);
11
11
  }
12
12
  })(function (require, exports) {
13
13
  "use strict";
@@ -17,6 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  const xhs_mp_pack_1 = require("xhs-mp-pack");
18
18
  const serviceChunkPlugin_1 = __importDefault(require("./serviceChunkPlugin"));
19
19
  const InjectorPlugin_1 = require("../../../plugins/InjectorPlugin");
20
+ const SourceMapDevToolPlugin_1 = require("../../../plugins/SourceMapDevToolPlugin");
20
21
  const cache_1 = require("../../../../utils/cache");
21
22
  const getServiceEntry = options => () => {
22
23
  const entries = {};
@@ -52,7 +53,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
52
53
  };
53
54
  const presetService = (chain, options) => {
54
55
  const { packSetting } = options;
55
- const { env, distDir, cacheDirectory } = packSetting;
56
+ const { env, distDir, cacheDirectory, enableSourcemap, appendSourcemapComment } = packSetting;
56
57
  const absCacheDirectory = path_1.default.join(cacheDirectory, 'service');
57
58
  chain.merge(Object.assign({
58
59
  // target: 'webworker',
@@ -64,6 +65,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
64
65
  } }, (0, cache_1.getCacheConfig)(absCacheDirectory, options)));
65
66
  chain.plugin('InjectorPlugin').use(InjectorPlugin_1.InjectorPlugin, [options]);
66
67
  chain.plugin('ServiceChunkPlugin').use(serviceChunkPlugin_1.default, [options]);
68
+ if (enableSourcemap && !appendSourcemapComment) {
69
+ const SourceMapDevToolPlugin = (0, SourceMapDevToolPlugin_1.getSourceMapDevtoolPlugin)(options.packMode);
70
+ chain.plugin('SourceMapDevToolPlugin').use(SourceMapDevToolPlugin, [{
71
+ filename: '[file].map',
72
+ append: false
73
+ }]);
74
+ }
67
75
  chain.optimization.runtimeChunk({
68
76
  name: 'runtime'
69
77
  });
@@ -50,33 +50,41 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
50
50
  var _a;
51
51
  const callback = this.async();
52
52
  const { resourcePath } = this;
53
- // const {miniprogramDir, enableVDom, enableV1, enableV2, independent} = this.getOptions() as any
54
53
  const { project, packSetting, independent } = this.getOptions();
55
54
  const { miniprogramDir } = project;
56
55
  const { enableVDom, enableV1, enableV2 } = packSetting;
57
56
  const shortPath = (0, common_1.getShortPath)(miniprogramDir, resourcePath).replace(/\.wxss$/, '.css');
58
57
  source = (_a = source === null || source === void 0 ? void 0 : source.trim) === null || _a === void 0 ? void 0 : _a.call(source);
59
- function result(code) {
58
+ const emitFiles = (code) => {
59
+ // vdom架构下emit出一份css文件
60
+ if ((independent || enableVDom) && code) {
61
+ enableV1 && this.emitFile(`v1/${shortPath}`, code);
62
+ enableV2 && this.emitFile(`v2/${shortPath}`, code);
63
+ }
64
+ };
65
+ const result = (code) => {
60
66
  if (!code) {
61
67
  return `export default void 0;`;
62
68
  }
63
69
  // 判断浏览器环境,注入css添加逻辑
64
- return new packs_1.RawSource(`globalThis.__XHS_IS_WEBVIEW && globalThis.__XHS_APPEND_CSS(${JSON.stringify(code)});` +
70
+ return new packs_1.RawSource(`globalThis.__XHS_IS_WEBVIEW && globalThis.__XHS_APPEND_CSS(${JSON.stringify(code)}, '${shortPath}');` +
65
71
  `export default ${JSON.stringify(shortPath)};`).source();
72
+ };
73
+ if (packSetting.compressCss) {
74
+ // 压缩css
75
+ minify(source, shortPath)
76
+ .then(({ code, warnings }) => {
77
+ emitFiles(code);
78
+ callback(null, result(code));
79
+ })
80
+ .catch(error => {
81
+ callback(error);
82
+ });
83
+ }
84
+ else {
85
+ emitFiles(source);
86
+ callback(null, result(source));
66
87
  }
67
- // 压缩css
68
- minify(source, shortPath)
69
- .then(({ code, warnings }) => {
70
- // vdom架构下emit出一份css文件
71
- if ((independent || enableVDom) && code) {
72
- enableV1 && this.emitFile(`v1/${shortPath}`, code);
73
- enableV2 && this.emitFile(`v2/${shortPath}`, code);
74
- }
75
- callback(null, result(code));
76
- })
77
- .catch(error => {
78
- callback(error);
79
- });
80
88
  }
81
89
  module.exports = miniStyleLoader;
82
90
  });
@@ -21,6 +21,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
21
21
  __setModuleDefault(result, mod);
22
22
  return result;
23
23
  };
24
+ var __importDefault = (this && this.__importDefault) || function (mod) {
25
+ return (mod && mod.__esModule) ? mod : { "default": mod };
26
+ };
24
27
  (function (factory) {
25
28
  if (typeof module === "object" && typeof module.exports === "object") {
26
29
  var v = factory(require, exports);
@@ -32,12 +35,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
32
35
  })(function (require, exports) {
33
36
  "use strict";
34
37
  Object.defineProperty(exports, "__esModule", { value: true });
35
- const fs_extra_1 = __importStar(require("fs-extra"));
38
+ const fs_extra_1 = __importDefault(require("fs-extra"));
36
39
  const path_1 = __importStar(require("path"));
37
40
  const xhs_mp_pack_1 = require("xhs-mp-pack");
38
41
  const loader_utils_1 = require("../../utils/loader-utils");
39
42
  const getSuffixName_1 = require("../../utils/getSuffixName");
40
- function genComponentLoaderScript(project, context, opts) {
43
+ function genComponentLoaderScript(project, packSetting, context, opts) {
41
44
  const { pkg, root, mode, compPath } = opts;
42
45
  const { projectMiniprogramPath, jsonDependencies = [] } = project;
43
46
  const componentsMap = project.getComponentsMap();
@@ -74,23 +77,24 @@ var __importStar = (this && this.__importStar) || function (mod) {
74
77
  ;${entries.join('\n ')}
75
78
  `;
76
79
  }
77
- const genRenderLoaderScript = (project, context, opts) => {
80
+ const genRenderLoaderScript = (project, packSetting, context, opts) => {
78
81
  const { projectMiniprogramPath, appJSON, jsonDependencies } = project;
82
+ const { enableVDom } = packSetting;
79
83
  const { pkg, mode } = opts;
80
84
  const isFull = pkg === 'full';
85
+ const appCssPath = (0, path_1.resolve)(projectMiniprogramPath, 'app.css');
81
86
  for (const file of jsonDependencies) {
82
87
  context.addDependency(file);
83
88
  }
84
- const appCssPath = (0, path_1.resolve)(projectMiniprogramPath, 'app.css');
85
- const appCssExist = (0, fs_extra_1.existsSync)(appCssPath);
86
89
  const resourcePath = (0, loader_utils_1.formatPath)(context.resourcePath);
87
90
  const path = (0, loader_utils_1.formatPath)(resourcePath.replace(`${projectMiniprogramPath}/`, '').replace(`.${(0, getSuffixName_1.getMlSuffixName)()}`, ''));
88
91
  const subPackage = (appJSON.subPackages || []).find(subPack => !!subPack.pages.find(page => page.path === path));
89
92
  const enableLazyCodeLoading = mode === 'v2';
90
93
  // 资源文件
91
- const resources = (0, loader_utils_1.getResourceUris)({
92
- appCssExist,
94
+ const { resourceList, appCssCode } = (0, loader_utils_1.getResourceUris)({
95
+ appCssPath,
93
96
  subPackage,
97
+ enableVDom,
94
98
  enableLazyCodeLoading
95
99
  });
96
100
  // 开启了按需注入,注入依赖组件
@@ -108,16 +112,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
108
112
  depends.push(uri);
109
113
  }
110
114
  return `
115
+ ${appCssCode};
111
116
  import Component from '${resourcePath}';
112
- globalThis.__render.mount(Component, '${path}', ${JSON.stringify(resources)}, ${JSON.stringify(depends)})
117
+ globalThis.__render.mount(Component, '${path}', ${JSON.stringify(resourceList)}, ${JSON.stringify(depends)})
113
118
  `;
114
119
  }
115
120
  return `
121
+ ${appCssCode}
116
122
  import Component from '${resourcePath}';
117
- globalThis.__render.mount(Component, '${path}', ${JSON.stringify(resources)})
123
+ globalThis.__render.mount(Component, '${path}', ${JSON.stringify(resourceList)})
118
124
  `;
119
125
  };
120
- function genServiceLoderScript(project, context, opts) {
126
+ function genServiceLoderScript(project, packSetting, context, opts) {
121
127
  const { appJSON, legacyAppJSON, projectMiniprogramPath, jsonDependencies } = project;
122
128
  const { pkg, root } = opts;
123
129
  const modules = [];
@@ -199,7 +205,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
199
205
  if (!handler) {
200
206
  throw new Error(`not found loader handler of ${type}`);
201
207
  }
202
- return handler(this._compiler.project, this, options);
208
+ return handler(this._compiler.project, this._compiler.packSetting, this, options);
203
209
  }
204
210
  module.exports = entryLoader;
205
211
  });
@@ -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
+ });
@@ -53,42 +53,42 @@ export interface ICompilerConfig {
53
53
  */
54
54
  projectPath: string;
55
55
  miniprogramDir: string;
56
- /**
57
- * 构建产物目录
58
- */
59
- distDir?: string;
56
+ tsConfigPath?: string;
57
+ extJsonPath?: string;
60
58
  action: "dev" | "build";
61
- watch?: boolean;
62
59
  env: ENV;
63
- tsConfigPath?: string;
64
60
  /**
65
- * ext json path
61
+ * 构建产物目录
66
62
  */
67
- extJsonPath?: string;
63
+ distDir?: string;
68
64
  enablePersistCache?: boolean;
69
65
  cacheDirectory?: string;
66
+ /**
67
+ * 是否开启 CSS 编译压缩
68
+ * 默认true
69
+ */
70
+ compressCss?: boolean;
70
71
  /**
71
72
  * 是否开启 Js 编译压缩
73
+ * 默认true
72
74
  */
73
75
  compressJs?: boolean;
74
76
  /**
75
77
  * 打包是否包含 js 文件
76
78
  */
77
79
  noJs?: boolean;
78
- /**
79
- * dev 模式是否开启 sourcemap,默认开启
80
- */
81
80
  enableSourcemap?: boolean;
82
- /**
83
- * 服务端口
84
- */
85
- port?: number;
81
+ appendSourcemapComment?: boolean;
86
82
  enableV1?: boolean;
87
83
  enableV2?: boolean;
88
84
  enableVDom?: boolean;
89
85
  mpUploadOptions?: any;
86
+ /**
87
+ * 服务端口
88
+ */
89
+ port?: number;
90
90
  }
91
- type CliPick = 'projectPath' | 'distDir' | 'watch' | 'tsConfigPath' | 'extJsonPath' | 'cacheDirectory' | 'compressJs' | 'enableSourcemap' | 'enableV1' | 'enableV2' | 'enableVDom' | 'mpUploadOptions';
91
+ type CliPick = 'projectPath' | 'distDir' | 'tsConfigPath' | 'extJsonPath' | 'cacheDirectory' | 'compressCss' | 'compressJs' | 'enableSourcemap' | 'appendSourcemapComment' | 'enableV1' | 'enableV2' | 'enableVDom' | 'mpUploadOptions';
92
92
  export interface IStart extends Pick<ICompilerConfig, CliPick> {
93
93
  packMode?: 'webpack' | 'mp-pack';
94
94
  /**
@@ -4,10 +4,14 @@ export declare const getShortPath: (projectMiniprogramPath: string, rootContext:
4
4
  * 根据是否分包获取资源路径
5
5
  */
6
6
  export declare const getResourceUris: (options: {
7
- appCssExist: boolean;
7
+ appCssPath: string;
8
+ enableVDom: boolean;
8
9
  enableLazyCodeLoading: boolean;
9
10
  subPackage: any;
10
- }) => string[];
11
+ }) => {
12
+ appCssCode: string;
13
+ resourceList: string[];
14
+ };
11
15
  /**
12
16
  * @NOTE
13
17
  * Create a request and handle the conversion of esModule modules
@@ -7,7 +7,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7
7
  if (v !== undefined) module.exports = v;
8
8
  }
9
9
  else if (typeof define === "function" && define.amd) {
10
- define(["require", "exports", "path", "./common", "./getSuffixName"], factory);
10
+ define(["require", "exports", "path", "./common", "./getSuffixName", "fs-extra"], factory);
11
11
  }
12
12
  })(function (require, exports) {
13
13
  "use strict";
@@ -17,6 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  const path_1 = __importDefault(require("path"));
18
18
  const common_1 = require("./common");
19
19
  const getSuffixName_1 = require("./getSuffixName");
20
+ const fs_extra_1 = __importDefault(require("fs-extra"));
20
21
  const formatPath = (pathStr = '') => pathStr.split(path_1.default.sep).join(path_1.default.posix.sep);
21
22
  exports.formatPath = formatPath;
22
23
  const getShortPath = (projectMiniprogramPath, rootContext) => {
@@ -34,12 +35,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
34
35
  */
35
36
  const getResourceUris = (options) => {
36
37
  const resourceList = [];
37
- const { appCssExist, enableLazyCodeLoading, subPackage } = options;
38
+ const { appCssPath, enableVDom, enableLazyCodeLoading, subPackage } = options;
39
+ const appCssExist = fs_extra_1.default.existsSync(appCssPath);
38
40
  // sjs 无法识别是否引用 所以一律push
39
- // 加载顺序 app.css 主包sjs 分包sjs 主包components.js 分包components.js
41
+ // 加载顺序 主包sjs 分包sjs 主包components.js 分包components.js
42
+ let appCssCode = '';
43
+ const genAppCss = () => {
44
+ if (appCssExist) {
45
+ // 运行时v2架构下,还是传递给运行时控制
46
+ if (enableVDom) {
47
+ resourceList.push(`app.css`);
48
+ }
49
+ else {
50
+ // 运行时v1架构下,需要放在appCssCode,避免页面样式优先级高于app.css
51
+ appCssCode = `import '${appCssPath}'`;
52
+ }
53
+ }
54
+ };
40
55
  if (!subPackage) {
41
56
  // 主包
42
- appCssExist && resourceList.push(`app.css`);
57
+ genAppCss();
43
58
  resourceList.push('sjs.js');
44
59
  !enableLazyCodeLoading && resourceList.push(`components.js`);
45
60
  }
@@ -49,14 +64,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
49
64
  !enableLazyCodeLoading && resourceList.push(`${subPackage === null || subPackage === void 0 ? void 0 : subPackage.root}/components.js`);
50
65
  }
51
66
  else if (subPackage) {
52
- // 普通分包, 自己的components.js,主包components.js app.css
53
- appCssExist && resourceList.push(`app.css`);
67
+ // 普通分包, 自己的components.js,主包components.js
68
+ genAppCss();
54
69
  resourceList.push('sjs.js');
55
70
  resourceList.push(`${subPackage === null || subPackage === void 0 ? void 0 : subPackage.root}/sjs.js`);
56
71
  !enableLazyCodeLoading && resourceList.push(`components.js`);
57
72
  !enableLazyCodeLoading && resourceList.push(`${subPackage === null || subPackage === void 0 ? void 0 : subPackage.root}/components.js`);
58
73
  }
59
- return resourceList;
74
+ return { appCssCode, resourceList };
60
75
  };
61
76
  exports.getResourceUris = getResourceUris;
62
77
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xhs-mp-compiler-cli",
3
- "version": "1.9.6",
3
+ "version": "1.9.7",
4
4
  "description": "xhs mp command tool.",
5
5
  "preferGlobal": true,
6
6
  "category": "esm",
@@ -94,13 +94,13 @@
94
94
  "webpack-chain": "^6.5.1",
95
95
  "webpack-sources": "^3.2.2",
96
96
  "xhs-mp-workerpool": "^9.1.3",
97
- "xhs-mp-compiler-ml-loader": "3.0.6",
98
- "xhs-mp-compiler-utils": "1.9.6",
99
- "xhs-mp-pack": "1.9.6",
100
- "xhs-mp-project": "1.9.6",
101
- "xhs-mp-utils": "1.9.6",
102
- "xhs-mp-shared-fs": "1.4.6",
103
- "xhs-mp-compiler-sjs-loader": "1.9.6",
97
+ "xhs-mp-compiler-ml-loader": "3.0.7",
98
+ "xhs-mp-compiler-utils": "1.9.7",
99
+ "xhs-mp-pack": "1.9.7",
100
+ "xhs-mp-project": "1.9.7",
101
+ "xhs-mp-utils": "1.9.7",
102
+ "xhs-mp-shared-fs": "1.4.7",
103
+ "xhs-mp-compiler-sjs-loader": "1.9.7",
104
104
  "yauzl": "^2.10.0"
105
105
  },
106
106
  "devDependencies": {