Skip to content

Latest commit

 

History

History
55 lines (39 loc) · 580 Bytes

2018-01-14__rollup-tree-shaking.md

File metadata and controls

55 lines (39 loc) · 580 Bytes

笔记

tree shaking

rollup的tree shaking是自带的,无需额外配置

rollup.config.js

export default {
  input: 'src/main.js',
  output: {
    file: 'rollup.bundle.js',
    format: 'cjs'
  }
}

main.js

import { a } from './util'

a()

util.js

export function a () {
  console.log('a')
}

export function b () {
  console.log('b')
}

build

rollup -c
'use strict';

function a () {
  console.log('a');
}

a();

输出结果不会引入b函数,而且对比webpack代码更少,也能直接读懂