From 80d348b7aee64b7de602a63cfa1f3ecfe8345297 Mon Sep 17 00:00:00 2001 From: xiazeyu_2011 Date: Fri, 9 Feb 2018 19:04:40 +0800 Subject: [PATCH] feat: add UglifyJS --- index.js | 7 +++++-- package-lock.json | 19 +++++++++++++++++++ package.json | 3 ++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 6162e7c..62ab89c 100755 --- a/index.js +++ b/index.js @@ -9,6 +9,7 @@ const fs = require('hexo-fs'), path = require('path'), url = require('url'), _ = require('lodash'), + UglifyJS = require("uglify-js"), onSiteRootPath = '/live2dw/' onSiteJsPath = onSiteRootPath + 'lib/', onSiteModelPath = onSiteRootPath + 'assets/', @@ -154,8 +155,10 @@ hexo.extend.helper.register('live2d', function(){ // injector borrowed form here: // https://github.com/Troy-Yang/hexo-lazyload-image/blob/master/lib/addscripts.js hexo.extend.filter.register('after_render:html', function(htmlContent){ - let launcherScript = `L2Dwidget.init(${JSON.stringify(config)});`; - let injectExtraScript = `` + let launcherScript =` +L2Dwidget.init(${JSON.stringify(config)}); +`; + let injectExtraScript = `` if(/<\/body>/gi.test(htmlContent)){ let lastIndex = htmlContent.lastIndexOf(''); htmlContent = htmlContent.substring(0, lastIndex) + injectExtraScript + htmlContent.substring(lastIndex, htmlContent.length); diff --git a/package-lock.json b/package-lock.json index 254a4c5..8e588e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -146,6 +146,11 @@ "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", "dev": true }, + "commander": { + "version": "2.14.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.14.1.tgz", + "integrity": "sha512-+YR16o3rK53SmWHU3rEM3tPAh2rwb1yPcQX5irVn7mb0gXbwuCCrnkbV5+PBfETdfg1vui07nM6PCG1zndcjQw==" + }, "commitizen": { "version": "2.9.6", "resolved": "https://registry.npmjs.org/commitizen/-/commitizen-2.9.6.tgz", @@ -1086,6 +1091,11 @@ "rechoir": "0.6.2" } }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" + }, "spawn-sync": { "version": "1.0.15", "resolved": "https://registry.npmjs.org/spawn-sync/-/spawn-sync-1.0.15.tgz", @@ -1157,6 +1167,15 @@ "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", "dev": true }, + "uglify-js": { + "version": "3.3.10", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.3.10.tgz", + "integrity": "sha512-dNib7aUDNZFJNTXFyq0CDmLRVOsnY1F+IQgt2FAOdZFx2+LvKVLbbIb/fL+BYKCv3YH3bPCE/6M/JaxChtQLHQ==", + "requires": { + "commander": "2.14.1", + "source-map": "0.6.1" + } + }, "util": { "version": "0.10.3", "resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz", diff --git a/package.json b/package.json index 52274b0..0d56b84 100755 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "hexo-fs": "^0.2.2", "live2d-widget": "3.x", "lodash": "^4.17.4", - "path": "^0.12.7" + "path": "^0.12.7", + "uglify-js": "^3.3.10" }, "scripts": { "test": "echo \"Sayly, there's nothing here. ToT\" && exit 1",