Git Product home page Git Product logo

keep-being-curious's People

Contributors

cvsoldier avatar dependabot[bot] avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

aboycdog

keep-being-curious's Issues

《蔚蓝》关卡难度计算优化

before:同一个关卡内多个挑战相加的和 / 挑战数
after:(同一个关卡内多个挑战相加的和 + ((挑战数 - 1) / 2) * 挑战数) / 挑战数

vue-cli4升5踩坑

升级原因:webpack5 的 cache 太太太香了

1、npm run build 执行两遍打包

vue-cli5 默认会为现代浏览器额外打一个 <script type="module"> 里面使用的包,在cli定义build命令的代码里可以看到:

api.registerCommand('build', {
   description: 'build for production',
    usage: 'vue-cli-service build [options] [entry|pattern]',
    options: {
      // ...
      '--no-module': `build app without generating <script type="module"> chunks for modern browsers`,
      // ...
    }
  }, () => {})

所以package中build命令改为 vue-cli-service build --mode production --no-module 即可。

2、hard-source-webpack-plugin

直接删掉就可以了,webpack5 的强大缓存,可以保证开发环境的二次构建速度直接起飞🛫️。

3、prerender-spa-plugin

这个错误是webpack5的 filesystem 重构导致的:“mkdirp is no longer expected to be a function on the output file system”。
同时 prerender-spa-plugin 代码是依赖 mkdirp 这个api的:

// es6/index.js
const compilerFS = compiler.outputFileSystem

const mkdirp = function (dir, opts) {
  return new Promise((resolve, reject) => {
    compilerFS.mkdirp(dir, opts, (err, made) => err === null ? resolve(made) : reject(err))
  })
}

所以就报错了,compilerFS 这个对象上已经没有 mkdirp 了,联系上下文这个函数的作用是递归创建目录,因为一般情况下,webpack的 compiler.outputFileSystem 就是 node 的fs,所以可以替换为 compilerFS.mkdir()

compilerFS.mkdir === fs.mkdir // true

需要注意的是 fs.mkdir 默认不能递归创建目录,需要携带 { recursive: true } 选项,来实现类似 mkdir('/不存在的目录1/不存在的目录2', opts, () => {}) 的调用。
又因为 prerender-spa-plugin 这个库已经没人维护了,所以只能用patch-package去修改node_modules,修改后的代码:

const mkdirp = function (dir, opts = { recursive: true }) {
  return new Promise((resolve, reject) => {
    compilerFS.mkdir(dir, opts, (err, made) => err === null ? resolve(made) : reject(err))
  })
}

4、prerender-spa-plugin

cli5去掉了preload插件,有issue要打开,但是不知道为啥没开。(小声bb:虽然vue-cli的README标明了项目处于维护模式,但是到目前(10月12号)为止最近的一次提交还是9月4号,我寻思这也妹维护啊)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.