Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Commit

Permalink
feat: add UglifyJS
Browse files Browse the repository at this point in the history
  • Loading branch information
xiazeyu committed Feb 9, 2018
1 parent 47a8aad commit 80d348b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
Expand Down Expand Up @@ -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 = `<script src="${getJsPath()}"></script><script>${launcherScript}</script>`
let launcherScript =`
L2Dwidget.init(${JSON.stringify(config)});
`;
let injectExtraScript = `<script src="${getJsPath()}"></script><script>${UglifyJS.minify(launcherScript)}</script>`
if(/<\/body>/gi.test(htmlContent)){
let lastIndex = htmlContent.lastIndexOf('</body>');
htmlContent = htmlContent.substring(0, lastIndex) + injectExtraScript + htmlContent.substring(lastIndex, htmlContent.length);
Expand Down
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 80d348b

Please sign in to comment.