学习Webpack的代码笔记整理
- webpack 4.43.0
- babel 7.10.4
- Base Config:
mode/entry/output - Html:
html-webpack-plugin - Dev Server:
webpack-dev-server - Css
- Base:
css-loaderstyle-loader - Less/Sass:
less-loadersass-loader - Seperate Css File:
mini-css-extract-plugin - Browser Prefix:
postcss-loaderautoprefixer - Compress:
optimize-css-assets-webpack-plugin
- Base:
- JS
- ES6/ES7 -> ES5:
babel-loader(presets/plugins/runtime/polyfill) - Format:
eslint-loader - Global Variable:
expose-loaderwebpack.ProvidePluginCDN(externals)
- ES6/ES7 -> ES5:
- Images
- JS/CSS:
file-loader/url-loader - HTML:
file-loader/url-loader+html-withimg-loader
- JS/CSS:
- Multiple Entries
- JS: output--filename ([name].js)
- HTML:
html-webpack-plugin(chunks)
- Little Plugins
clean-webpack-plugincopy-webpack-plugin- buidin:
webpack.BannerPlugin
- Webpack Propertis
devtool: Source MapwatchwatchOptions: Auto Rebuildresolve: Resolve Modules
- Cross Origin
proxybefore(app)(mock)webpack-dev-middleware
- Environment
- Env Variables:
webpack.DefinePlugin - Split Config:
webpack-merge
- Env Variables:
- optimization
- noParse:
noParse: /jquery|lodash/ - IgnorePlugin:
new webpack.IgnorePlugin(/\.\/locale/, /moment/) - Dll:
webpack.DllPluginwebpack.DllReferencePlugin - Multiple Threads Pack:
happypack - Buildin: tree-shaking, scope hosting
- Common Codes(Multiple Entries):
splitChunks - Lazy Load:
import('xxx').then(data => console.log(data.default)); - HMR:
webpack.HotModuleReplacementPluginwebpack.NamedModulesPluginmodule.hot.accept()
- noParse:
- tapable
- Sync:
SyncHookSyncBailHookSyncWaterfallHookSyncLoopHook - Async:
AsyncParallelHook(AsyncParallelBailHook)AsyncSeriesHook(AsyncSeriesBailHook)AsyncSeriesWaterfallHook
- Sync:
- write a simple webpack
- bin project -
my-webpack:fspathAST(babylon@babel/types@babel/traverse@babel/generator)tapableejs - test project: write loaders(
style-loaderless-loader), write plugins(tapable)
- bin project -
# bin project
npm link
# test project
npm link my-webpack
npx my-webpack