@itera-web/cli 1.1.63 → 1.1.65

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.
package/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  支持构建`React TS公共组件`、`项目的本地调试`、`打包发布`
4
4
 
5
+ - 1.1.65 => 引入排序加入 `iteraWeb` 包
5
6
  - 1.1.56 => 多页应用名字修改
6
7
  - 1.1.55 => 添加 rem 适配相关包
7
8
  - 1.1.54 => `itera-cli update-projects` 多任务并发部署可视化选择 UI可拖拽
@@ -4,56 +4,59 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var cheerio_1 = __importDefault(require("cheerio"));
7
- var webpack_1 = require("webpack");
8
- var log_1 = require("../public/log");
7
+ var fs_1 = __importDefault(require("fs"));
8
+ var path_1 = __importDefault(require("path"));
9
+ var Console = require('../public/log').Console;
9
10
  var SortScriptTagPlugin = (function () {
10
11
  function SortScriptTagPlugin() {
11
12
  }
12
13
  SortScriptTagPlugin.prototype.apply = function (compiler) {
13
- compiler.hooks.thisCompilation.tap('SortScriptTagPlugin', function (compilation) {
14
- compilation.hooks.processAssets.tap({
15
- name: 'SortScriptTagPlugin',
16
- stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
17
- }, function (assets) {
18
- log_1.Console.cyan('开始排序引用');
19
- var htmlName = 'index.html';
20
- var asset = compilation.getAsset(htmlName);
21
- if (!asset)
22
- return;
23
- var html = asset.source.source().toString();
24
- var $ = cheerio_1.default.load(html, { decodeEntities: false });
25
- var srcTag = $('script');
14
+ compiler.hooks.done.tap('SortScriptTagPlugin', function (stats) {
15
+ Console.success('构建完毕');
16
+ var outputPath = compiler.options.output.path;
17
+ var baseHtmlPath = path_1.default.join(outputPath, 'index.html');
18
+ if (fs_1.default.existsSync(baseHtmlPath)) {
19
+ Console.cyan('开始引入排序');
20
+ var baseHtmlContent = fs_1.default.readFileSync(baseHtmlPath, 'utf8');
21
+ var $_1 = cheerio_1.default.load(baseHtmlContent, { decodeEntities: false });
22
+ var srcTag = $_1('script');
26
23
  var scripts = srcTag.toArray().reverse();
27
- var priorityList = ['react', 'main'];
28
- var priorityScripts = {};
29
- priorityList.forEach(function (k) { return (priorityScripts[k] = null); });
30
- var otherScripts = [];
24
+ var priorityList_1 = ['react', 'main', 'iteraWeb'];
25
+ var priorityScripts_1 = {};
26
+ priorityList_1.forEach(function (key) {
27
+ priorityScripts_1[key] = null;
28
+ });
29
+ var otherScripts_1 = [];
31
30
  scripts.forEach(function (script) {
32
- var src = $(script).attr('src') || '';
31
+ var src = $_1(script).attr('src') || '';
33
32
  var matched = false;
34
- for (var _i = 0, priorityList_1 = priorityList; _i < priorityList_1.length; _i++) {
35
- var key = priorityList_1[_i];
36
- if (src.includes("js/".concat(key, ".")) && !priorityScripts[key]) {
37
- priorityScripts[key] = script;
33
+ for (var _i = 0, priorityList_2 = priorityList_1; _i < priorityList_2.length; _i++) {
34
+ var key = priorityList_2[_i];
35
+ if (src.includes("js/".concat(key, ".")) && !priorityScripts_1[key]) {
36
+ priorityScripts_1[key] = script;
38
37
  matched = true;
39
38
  break;
40
39
  }
41
40
  }
42
41
  if (!matched)
43
- otherScripts.push(script);
42
+ otherScripts_1.push(script);
44
43
  });
45
44
  srcTag.remove();
46
- priorityList.forEach(function (key) {
47
- if (priorityScripts[key])
48
- $('body').append(priorityScripts[key]);
45
+ priorityList_1.forEach(function (key) {
46
+ if (priorityScripts_1[key]) {
47
+ $_1('body').append(priorityScripts_1[key]);
48
+ }
49
49
  });
50
- otherScripts.forEach(function (script) {
51
- $('body').append(script);
50
+ otherScripts_1.forEach(function (script) {
51
+ $_1('body').append(script);
52
52
  });
53
- var newHtml = $.html();
54
- compilation.updateAsset(htmlName, new webpack_1.sources.RawSource(newHtml));
55
- log_1.Console.success('引用排序完毕');
56
- });
53
+ var modifiedHtml = $_1.html();
54
+ fs_1.default.writeFileSync(baseHtmlPath, modifiedHtml, 'utf8');
55
+ Console.success('引入排序完毕');
56
+ }
57
+ });
58
+ compiler.hooks.failed.tap('SortScriptTagPlugin', function (err) {
59
+ Console.error('构建失败:', err);
57
60
  });
58
61
  };
59
62
  return SortScriptTagPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itera-web/cli",
3
- "version": "1.1.63",
3
+ "version": "1.1.65",
4
4
  "bin": {
5
5
  "itera-cli": "./bin/index.js"
6
6
  },