ionote / .github

0 stars 0 forks source link

Vue 3.2.37 源码解析 #7

Open banli17 opened 4 months ago

banli17 commented 4 months ago
  1. git clone 源码
  2. npm run build 会在 packages/vue/dist 下生成打包后的 js
  3. 在 examples 里编写测试 html,通过 live-server 打开
  4. npm run build -s 可以打开 sourcemap,scripts/build.js 文件中通过 minimist 解析参数, -s 或 -sourcemap
const args = require('minimist')(process.argv.slice(2))
const targets = args._
const formats = args.formats || args.f
const devOnly = args.devOnly || args.d
const prodOnly = !devOnly && (args.prodOnly || args.p)
const sourceMap = args.sourcemap || args.s

await execa(
    'rollup',
    [
      '-c',
      '--environment',
      [
        `COMMIT:${commit}`,
        `NODE_ENV:${env}`,
        `TARGET:${target}`,
        formats ? `FORMATS:${formats}` : ``,
        buildTypes ? `TYPES:true` : ``,
        prodOnly ? `PROD_ONLY:true` : ``,
        sourceMap ? `SOURCE_MAP:true` : ``
      ]
        .filter(Boolean)
        .join(',')
    ],
    { stdio: 'inherit' }
  )
banli17 commented 4 months ago

阅读源码准则:

  1. 摈弃边缘情况
  2. 跟随一条主线

即跟着主逻辑,没有涉及到的分支情况忽略。