chenzhutian / hexo-all-minifier

A plugin for Hexo that optimizes HTML, CSS, JS and imagages, and it can optionally deploys your blog.
MIT License
277 stars 30 forks source link

UglifyJS dosen't work for me #30

Closed cmpute closed 7 years ago

cmpute commented 7 years ago

当执行hexo clean & hexo g时,html和css压缩没问题,但是js全都压缩不了。下面是一部分的报错:

INFO  Cannot minify the js of D:\Blog\Hexo\hexo\themes\next\source\js\src\affix.js
INFO  Cannot minify the js of D:\Blog\Hexo\hexo\themes\next\source\js\src\algolia-search.js
INFO  Cannot minify the js of D:\Blog\Hexo\hexo\themes\next\source\js\src\bootstrap.js
INFO  Cannot minify the js of D:\Blog\Hexo\hexo\themes\next\source\js\src\hook-duoshuo.js
INFO  Cannot minify the js of D:\Blog\Hexo\hexo\themes\next\source\js\src\exturl.js
INFO  Cannot minify the js of D:\Blog\Hexo\hexo\themes\next\source\js\src\motion.js
INFO  Cannot minify the js of D:\Blog\Hexo\hexo\themes\next\source\js\src\post-details.js
INFO  Cannot minify the js of D:\Blog\Hexo\hexo\themes\next\source\js\src\js.cookie.js
INFO  Cannot minify the js of D:\Blog\Hexo\hexo\themes\next\source\js\src\scroll-cookie.js
INFO  Cannot minify the js of D:\Blog\Hexo\hexo\themes\next\source\js\src\scrollspy.js
INFO  Cannot minify the js of D:\Blog\Hexo\hexo\themes\next\source\js\src\utils.js
INFO  Cannot minify the js of D:\Blog\Hexo\hexo\themes\next\source\lib\canvas-nest\canvas-nest.min.js
INFO  Cannot minify the js of D:\Blog\Hexo\hexo\themes\next\source\lib\canvas-ribbon\canvas-ribbon.js

我把这行代码改成了log.log('Cannot minify the js of ${path}' + result.error);,最后得到的报错信息全部都是TypeError: Cannot read property 'ast' of null。。。求帮助!

此外上面的报错还发现*.min.js的文件并没有被跳过?

主题是 NexT.Muse,以下是设置:

html_minifier:
  enable: true
  ignore_error: false
  exclude:
  minifyCSS: true
  minifyJS: true

css_minifier:
  enable: true
  exclude: 
    - '*.min.css'

js_minifier:
  enable: true
  mangle: true
  output:
  compress:
  exclude: 
    - '*.min.js'

image_minifier:
  enable: false

Nodejs版本是最新的6.10

chenzhutian commented 7 years ago

请问你能给个可以复现错误的最小repo给我么? 因为我在我自己的blog上跑没法重现错误... 还是说直接用next.muse就能复现这个bug了?

cmpute commented 7 years ago

@chenzhutian 我试了一下,直接新建一个hexo+next.muse的博客,然后把我上面那一段配置文件插入到hexo的_config.yml中theme选项之后就能复现。

chenzhutian commented 7 years ago

ok, 我试试

chenzhutian commented 7 years ago

@cmpute fix了,output这个选项不能留空,这个在新的uglifyjs里会被当作null而不是undefined。 所以如果想要留空的话就直接在yml里去掉这个选项就好了,我更新了readme了。 另外*.min.js的匹配问题也解决了 试试0.2.5的看看能不能工作

cmpute commented 7 years ago

完美,现在可以了! 此外,在optimizeCSS里面也有不识别*.min.css的现象,忘了说明了,可以也fix一下。

chenzhutian commented 7 years ago

好的,多谢啦,我close issue了