在空文件夹初始化:CMDhtml
npm init -ywebpack
-y意思是所有yescnpm install -D webpack webpack-cliweb
文件结构npm
src(文件夹)--->index.js
console.log('hello webpack')
test(文件夹)--->main.js
console.log('hello webpack2')
package.jsonjson
scripts里面加上build:webpack
webpack默认是打包src下面的index.js 能够自定义,如:build:webpack server/index.js
{ "name": "02", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "build": "webpack", "build2": "webpack test/main.js" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { "webpack": "^4.43.0", "webpack-cli": "^3.3.11" } }
打包:CMDsegmentfault
npm run build
npm run build2