webpack.02-How to pack

Posted May 27, 20201 min read

Initialize in empty folder:CMD

npm init -y

\ -y means all yes

cnpm install -D webpack webpack-cli

File structure

src(folder) ---> index.js

console.log('hello webpack')

test(folder) ---> main.js

console.log('hello webpack2')

package.json

add build:webpack inside scripts
webpack defaults to packing index.js under src which can be customized, such as: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"
  }
}

Package:CMD

npm run build
npm run build2