webpack 用於編譯 JavaScript 模塊。一旦完成安裝,就可以通過 webpack 的 CLI 或 API 與其配合交互。 首先創建一個目錄,進入目錄中,初始化npm 然後本地安裝webpack,webpack-cli ,lodash 目錄結構: index.html webpack.c ...
webpack 用於編譯 JavaScript 模塊。一旦完成安裝,就可以通過 webpack 的 CLI 或 API 與其配合交互。
首先創建一個目錄,進入目錄中,初始化npm 然後本地安裝webpack,webpack-cli ,lodash
目錄結構:
index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <script src="bundle.js"></script> </body> </html>
webpack.config.js
const path = require('path'); module.exports = { entry: './src/index.js', output:{ filename: 'bundle.js', path: path.resolve(__dirname, 'dist') } }
package,json
{ "name": "webpack-demo", "version": "1.0.0", "description": "", "private": true, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "webpack" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { "webpack": "^4.29.6", "webpack-cli": "^3.2.3" }, "dependencies": { "lodash": "^4.17.11" } }
輸入npm run build