前端tree shaking
单页应用带来更流畅的前端体验,同时也带来了一些麻烦,比如SEO,又比如日益严重的体积问题。当然办法总比困难多,tree shaking便是优化体积问题的办法之一
概念
tree shaking,它是什么
Tree shaking is a term commonly used in the JavaScript context for dead-code elimination. It relies on the static structure of ES2015 module syntax, i.e. import and export. The name and concept have been popularized by the ES2015 module bundler rollup.
The webpack 2 release came with built-in support for ES2015 modules (alias harmony modules) as well as unused module export detection. The new webpack 4 release expands on this capability with a way to provide hints to the compiler via the “sideEffects” package.json property to denote which files in your project are “pure” and therefore safe to prune if unused.