webpack.02-如何打包

在空文件夹初始化:CMD

npm init -y

-y意思是全部yes

cnpm install -D webpack webpack-cli

文件结构

src(文件夹)--->index.js 
console.log('hello webpack')
test(文件夹)--->main.js   
console.log('hello webpack2')

package.json

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"
  }
}

打包:CMD

npm run build
npm run build2

你可能感兴趣的:(webpack,npm,javascript,前端)