日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

八十八、Webpack打包工具

發布時間:2024/10/8 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 八十八、Webpack打包工具 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

@Author:Runsen

微信原文;你知道那些長長的js怎么來的嗎?

今天不知道寫啥東西,隨便寫了點,好水啊

大家知不知道每次用js逆向時,發現那些長長的js代碼,那可不是人寫的。那到底是怎么來的,前端的人應該都知道用框架生成的,沒錯就是webpack

webpack

Webpack 是當下最熱門的前端資源模塊化管理和打包工具,它可以將許多松散耦合的模塊按照依賴和規則打包成符合生產環境部署的前端資源。

安裝 nvm

https://github.com/nvm-sh/nvm

通過 curl 安裝:curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

通過 wget 安裝:wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

安裝 Node.js 和 NPM

·nvm install v10.15.3
·檢查是否安裝成功:node -v, npm -v

安裝 webpack 和 webpack-cli

創建空?目錄和 package.json ·

mkdir my-project cd my-project · npm init -y

創建webpack.config.js

webpack.config.js

// 加載path const path = require('path');module.exports = {entry: './src/index.js',output: {path: path.join(__dirname, 'dist'),filename: 'bundle.js'},mode: 'production' }; entry打包的js output輸出的js

創建src/index.js

// 導入helloworld.js import { helloworld } from './helloworld';document.write(helloworld());

創建src/helloworld.js

// export 導入 export function helloworld() {return 'Hello webpack'; }

這樣通過打包index.js輸出到dist文件夾中的bundle.js,執行npm run build將其打包

這是bundle.js就是你看不懂的js代碼

!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";r.r(t),document.write("Hello webpack")}]);

這段代碼就是打印Hello webpack一樣的意思,只不過通過js生成的

新建./dist/index.html 導入

<body><script src="./bundle.js"></script> </body>

這該就是你zaijs慢慢扣的代碼來源

總結

以上是生活随笔為你收集整理的八十八、Webpack打包工具的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。