theme-next / hexo-theme-next

Elegant and powerful theme for Hexo.
https://theme-next.org
Other
8.15k stars 2.05k forks source link

Uncaught RangeError: Maximum call stack size exceeded #870

Closed asdf2014 closed 5 years ago

asdf2014 commented 5 years ago

I agree and want to create new issue


Expected behavior

正常打开网页

Actual behavior

image

Steps to reproduce the behavior

访问 https://yuzhouwan.com/posts/666/

Node.js and NPM Information

v11.6.0
6.9.0

Package dependencies Information

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "hexo": {
    "version": "3.8.0"
  },
  "dependencies": {
    "@babel/core": "^7.4.4",
    "browser-sync": "^2.26.5",
    "gulp": "^4.0.2",
    "gulp-htmlclean": "^2.7.22",
    "gulp-htmlmin": "^5.0.1",
    "gulp-imagemin": "^5.0.3",
    "gulp-install": "^1.1.0",
    "gulp-minify-css": "^1.2.4",
    "gulp-uglify": "^3.0.2",
    "hexo": "^3.8.0",
    "hexo-abbrlink": "^2.0.5",
    "hexo-autonofollow": "^1.0.1",
    "hexo-deployer-git": "^1.0.0",
    "hexo-filter-flowchart": "^1.0.4",
    "hexo-filter-mermaid-diagrams": "^1.0.5",
    "hexo-fs": "^1.0.2",
    "hexo-generator-archive": "^0.1.5",
    "hexo-generator-category": "^0.1.3",
    "hexo-generator-feed": "^1.2.2",
    "hexo-generator-index": "^0.2.1",
    "hexo-generator-searchdb": "^1.0.8",
    "hexo-generator-sitemap": "^1.1.2",
    "hexo-generator-tag": "^0.2.0",
    "hexo-inject": "^1.0.0",
    "hexo-related-popular-posts": "^3.0.5",
    "hexo-renderer-ejs": "^0.3.1",
    "hexo-renderer-kramed": "^0.1.4",
    "hexo-renderer-stylus": "^0.3.3",
    "hexo-server": "^0.3.3",
    "hexo-tag-mermaid": "^1.0.0",
    "mermaid": "^8.0.0",
    "natives": "^1.1.6",
    "phantomjs": "^2.1.7"
  },
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-preset-env": "^1.7.0",
    "gulp-babel": "^8.0.0",
    "hexo-util": "^0.6.3"
  }
}

Hexo Information

Hexo version

hexo: 3.8.0
hexo-cli: 1.1.0
os: Darwin 18.5.0 darwin x64
node: 11.6.0
v8: 7.0.276.38-node.13
uv: 1.24.1
zlib: 1.2.11
ares: 1.15.0
modules: 67
nghttp2: 1.34.0
napi: 3
llhttp: 1.0.1
http_parser: 2.8.0
openssl: 1.1.0j
icu: 63.1
unicode: 11.0
cldr: 34.0
tz: 2018e

NexT Information

NexT Version:

NexT Scheme:

asdf2014 commented 5 years ago

是 gulp4 的 js 压缩存在问题,去掉了 minify-js 就可以了,,但是不知道本质原因是什么?

var gulp = require('gulp');
var minifycss = require('gulp-minify-css');
var uglify = require('gulp-uglify');
var htmlmin = require('gulp-htmlmin');
var htmlclean = require('gulp-htmlclean');
var imagemin = require('gulp-imagemin');
var babel = require('gulp-babel');

gulp.task('minify-html', function() {
    return gulp.src('./public/**/*.html')
        .pipe(htmlclean())
        .pipe(htmlmin({
            removeComments: true,
            collapseWhitespace: true,
            collapseBooleanAttributes: true,
            removeEmptyAttributes: true,
            removeScriptTypeAttributes: true,
            removeStyleLinkTypeAttributes: true,
            minifyJS: true,
            minifyCSS: true
        }))
        .on('error', function(err) {
            console.log('html Error!', err.message);
            this.end();
        })
        .pipe(gulp.dest('./public'))
});
gulp.task('minify-css', function() {
    return gulp.src('./public/**/*.css')
        .pipe(minifycss())
        .pipe(gulp.dest('./public'));
});
gulp.task('minify-js', function() {
    return gulp.src(['./public/js/**/*.js', '!./public/js/**/*.{min,mini}.js', '!./public/js/MathJax/**/*.js'])
        .pipe(babel())
        .pipe(uglify())
        .pipe(gulp.dest('./public/js'));
});
gulp.task('minify-images', function() {
    return gulp.src('./public/images/*.*')
        .pipe(imagemin(
        [imagemin.gifsicle({'optimizationLevel': 3}),
        imagemin.jpegtran({'progressive': true}),
        imagemin.optipng({'optimizationLevel': 8}),
        imagemin.svgo()],
        {'verbose': true}))
        .pipe(gulp.dest('./public/images'))
});
// ,'minify-js' 会导致 https://github.com/theme-next/hexo-theme-next/issues/870
gulp.task('default', gulp.parallel('minify-html','minify-css','minify-images', function(done){
    done();
}));
ivan-nginx commented 5 years ago

https://github.com/theme-next/hexo-theme-next/blob/d78a4008c7b97612cea0c49ee20d6730b82c32ff/source/js/js.cookie.js#L1-L7

https://yuzhouwan.com/js/js.cookie.js

/*!
 * JavaScript Cookie v2.2.0
 * https://github.com/js-cookie/js-cookie
 *
 * Copyright 2006, 2015 Klaus Hartl & Fagner Brack
 * Released under the MIT license
 */

Versions different?

asdf2014 commented 5 years ago

@ivan-nginx Yep, I originally thought the version of js.cookie.js is the reason. However, it is caused by minify-js.

ivan-nginx commented 5 years ago

So, any suggestions to resolve it?

asdf2014 commented 5 years ago

@ivan-nginx There is no idea at all. I just forbid minify-js.

1v9 commented 5 years ago

Remove gulp-htmlclean and have a try again.

asdf2014 commented 5 years ago

@1v9 Okay, I will give a try.

asdf2014 commented 5 years ago

I think gulp-htmlclean only affects ./public/**/*.html, it won't succeed.

image

asdf2014 commented 5 years ago

I removed .pipe(babel()) and it worked.

1v9 commented 5 years ago

Congrats 😁 and I have used the following configuration for a long time, basically no difference with yours.

const gulp = require('gulp');
const babel = require('gulp-babel');
const htmlmin = require('gulp-htmlmin');
const imagemin = require('gulp-imagemin');
const cleanCSS = require('gulp-clean-css');
const uglify = require('gulp-uglify');

gulp.task('minify-html', () => {
  return gulp.src('./public/**/*.html')
    .pipe(htmlmin({
      minifyJS: true,
      minifyCSS: true,
      minifyURLs: true,
      useShortDoctype: true,
      collapseWhitespace: true,
      conservativeCollapse: true,
      collapseInlineTagWhitespace: true,
      collapseBooleanAttributes: true,
      removeComments: true,
      removeEmptyAttributes: true,
      removeScriptTypeAttributes: true,
      removeStyleLinkTypeAttributes: true
    }))
    .pipe(gulp.dest('./public'));
});

gulp.task('minify-css', () => {
  return gulp.src('./public/**/*.css', '!./public/**/*.min.css')
    .pipe(cleanCSS({debug: true}, (details) => {
      console.log(`${details.name}: ${details.stats.originalSize}`);
      console.log(`${details.name}: ${details.stats.minifiedSize}`);
    }))
    .pipe(gulp.dest('./public'));
});

gulp.task('minify-js', () => {
  return gulp.src(['./public/**/*.js', '!./public/**/*.min.js', '!./public/**/*.umd.js'])
    .pipe(babel({ presets: ['@babel/env'] }))
    .pipe(uglify())
    .pipe(gulp.dest('./public'));
});

gulp.task('minify-img', () => {
  return gulp.src('./public/image/**/*.*')
    .pipe(imagemin([
      imagemin.gifsicle({interlaced: true}),
      imagemin.jpegtran({progressive: true}),
      imagemin.optipng({optimizationLevel: 5}),
      imagemin.svgo({
        plugins: [
          {removeViewBox: true},
          {cleanupIDs: false}
        ]
      })
    ]))
    .pipe(gulp.dest('./public/image'))
});

gulp.task(
  'default',
  gulp.series(
    'minify-html',
    'minify-css',
    'minify-js',
    'minify-img'
  )
);
1v9 commented 5 years ago

I just found your dependency is outdated, maybe need upgrade.

asdf2014 commented 5 years ago

@1v9 @ivan-nginx Aha, Thanks a lot. I will close this.

FYI, https://yuzhouwan.com/js/js.cookie.js

asdf2014 commented 5 years ago

@1v9 Yep, I will upgrade the @babel/core.

ivan-nginx commented 5 years ago

@1v9 @asdf2014 guys, can you create something like instructions for Gulp usage in NexT site? Basic configuration, etc., like Deploying.

stevenjoezhang commented 5 years ago

@asdf2014 js.cookie.js has been replaced with localstorage in v7.4.0 ~