webpack打包
Webpack入门教程
npm init -y cnpm install --save-dev webpack cnpm install --save-dev webpack-cli
$ cat app.js alert(1);
node_modules/.bin/webpack-cli app.js --output build.js
页面中加载多个JS时,可能出现依赖顺序的问题,webpack将它们打包成一个文件,也解决了这个问题
$ cat aa.js alert(123);
$ cat app.js require('./aa.js');
$ cat index.html <html> <head> <meta charset="utf-8"> </head> <body> <script type="text/javascript" src="build.js" charset="utf-8"></script> </body> </html>
$ node_modules/.bin/webpack-cli app.js --output build.js Hash: f572aa7e487691c5dd50 Version: webpack 4.44.2 Time: 528ms Built at: 28/09/2020 10:31:57 pm Asset Size Chunks Chunk Names build.js 962 bytes 0 [emitted] main Entrypoint main = build.js [0] ./app.js 22 bytes {0} [built] [1] ./aa.js 12 bytes {0} [built] WARNING in configuration The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment. You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/