@itera-web/cli 1.1.58 → 1.1.60

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.
@@ -68,7 +68,7 @@ module.exports = {
68
68
  plugins: [
69
69
  new html_webpack_plugin_1.default({
70
70
  filename: 'index.html',
71
- template: resolve('public/base.html'),
71
+ template: resolve('public/index.html'),
72
72
  hash: true,
73
73
  minify: {
74
74
  removeAttributeQuotes: true,
@@ -4,70 +4,53 @@ 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 fs_1 = __importDefault(require("fs"));
8
- var path_1 = __importDefault(require("path"));
9
- var Console = require('../public/log').Console;
7
+ var webpack_1 = require("webpack");
10
8
  var SortScriptTagPlugin = (function () {
11
9
  function SortScriptTagPlugin() {
12
10
  }
13
11
  SortScriptTagPlugin.prototype.apply = function (compiler) {
14
- compiler.hooks.compile.tap('SortScriptTagPlugin', function () {
15
- Console.cyan('编译开始...');
16
- });
17
- compiler.hooks.emit.tapAsync('SortScriptTagPlugin', function (compilation, callback) {
18
- Console.cyan('emit 阶段开始...');
19
- callback();
20
- });
21
- compiler.hooks.afterEmit.tapAsync('SortScriptTagPlugin', function (compilation, callback) {
22
- Console.cyan('afterEmit 阶段开始...');
23
- callback();
24
- });
25
- compiler.hooks.done.tap('SortScriptTagPlugin', function (stats) {
26
- Console.success('构建完毕');
27
- var outputPath = compiler.options.output.path;
28
- var baseHtmlPath = path_1.default.join(outputPath, 'base.html');
29
- if (fs_1.default.existsSync(baseHtmlPath)) {
30
- Console.cyan('开始引入排序');
31
- var baseHtmlContent = fs_1.default.readFileSync(baseHtmlPath, 'utf8');
32
- var $_1 = cheerio_1.default.load(baseHtmlContent, { decodeEntities: false });
33
- var srcTag = $_1('script');
12
+ compiler.hooks.thisCompilation.tap('SortScriptTagPlugin', function (compilation) {
13
+ compilation.hooks.processAssets.tap({
14
+ name: 'SortScriptTagPlugin',
15
+ stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
16
+ }, function (assets) {
17
+ var htmlName = 'index.html';
18
+ var asset = compilation.getAsset(htmlName);
19
+ if (!asset)
20
+ return;
21
+ var html = asset.source.source().toString();
22
+ var $ = cheerio_1.default.load(html, { decodeEntities: false });
23
+ var srcTag = $('script');
34
24
  var scripts = srcTag.toArray().reverse();
35
- var priorityList_1 = ['react', 'main'];
36
- var priorityScripts_1 = {};
37
- priorityList_1.forEach(function (key) {
38
- priorityScripts_1[key] = null;
39
- });
40
- var otherScripts_1 = [];
25
+ var priorityList = ['react', 'main'];
26
+ var priorityScripts = {};
27
+ priorityList.forEach(function (k) { return (priorityScripts[k] = null); });
28
+ var otherScripts = [];
41
29
  scripts.forEach(function (script) {
42
- var src = $_1(script).attr('src') || '';
30
+ var src = $(script).attr('src') || '';
43
31
  var matched = false;
44
- for (var _i = 0, priorityList_2 = priorityList_1; _i < priorityList_2.length; _i++) {
45
- var key = priorityList_2[_i];
46
- if (src.includes("js/".concat(key, ".")) && !priorityScripts_1[key]) {
47
- priorityScripts_1[key] = script;
32
+ for (var _i = 0, priorityList_1 = priorityList; _i < priorityList_1.length; _i++) {
33
+ var key = priorityList_1[_i];
34
+ if (src.includes("js/".concat(key, ".")) && !priorityScripts[key]) {
35
+ priorityScripts[key] = script;
48
36
  matched = true;
49
37
  break;
50
38
  }
51
39
  }
52
40
  if (!matched)
53
- otherScripts_1.push(script);
41
+ otherScripts.push(script);
54
42
  });
55
43
  srcTag.remove();
56
- priorityList_1.forEach(function (key) {
57
- if (priorityScripts_1[key]) {
58
- $_1('body').append(priorityScripts_1[key]);
59
- }
44
+ priorityList.forEach(function (key) {
45
+ if (priorityScripts[key])
46
+ $('body').append(priorityScripts[key]);
60
47
  });
61
- otherScripts_1.forEach(function (script) {
62
- $_1('body').append(script);
48
+ otherScripts.forEach(function (script) {
49
+ $('body').append(script);
63
50
  });
64
- var modifiedHtml = $_1.html();
65
- fs_1.default.writeFileSync(baseHtmlPath, modifiedHtml, 'utf8');
66
- Console.success('引入排序完毕');
67
- }
68
- });
69
- compiler.hooks.failed.tap('SortScriptTagPlugin', function (err) {
70
- Console.error('构建失败:', err);
51
+ var newHtml = $.html();
52
+ compilation.updateAsset(htmlName, new webpack_1.sources.RawSource(newHtml));
53
+ });
71
54
  });
72
55
  };
73
56
  return SortScriptTagPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itera-web/cli",
3
- "version": "1.1.58",
3
+ "version": "1.1.60",
4
4
  "bin": {
5
5
  "itera-cli": "./bin/index.js"
6
6
  },