新建WebPack文件夹
初始化npm
PS E:\COLDDEMO\js源码示例\WebPack> npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
package name: (webpack) myproject//项目名称
version: (1.0.0)//项目版本号
description: 凌云木项目//项目描述
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to E:\COLDDEMO\js源码示例\WebPack\package.json:
{
"name": "myproject",
"version": "1.0.0",
"description": "凌云木项目",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Is this OK? (yes) yes
PS E:\COLDDEMO\js源码示例\WebPack> npm install webpack --save-dev//本地安装webpack
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN myproject@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ webpack@4.5.0
added 295 packages from 269 contributors in 59.622s
PS E:\COLDDEMO\js源码示例\WebPack> webpack list.js build.js
The CLI moved into a separate package: webpack-cli
Would you like to install webpack-cli? (That will run npm install -D webpack-cli) (yes/NO)no
It needs to be installed alongside webpack to use the CLI
****
PS E:\COLDDEMO\js源码示例\WebPack> npm uninstall webpack//卸载当前版本
npm WARN myproject@1.0.0 No repository field.
removed 295 packages in 2.864s
PS E:\COLDDEMO\js源码示例\WebPack> webpack -v//查看版本号
3.10.0
PS E:\COLDDEMO\js源码示例\WebPack> npm install --save-dev webpack@3.10.0 //安装其他4.0以下版本,4.0以上版本,打包会报错,未知。
****
uglifyjs-webpack-plugin@0.4.6 postinstall E:\COLDDEMO\js源码示例\WebPack\node_modules\uglifyjs-webpack-plugin
node lib/post_install.js
npm WARN myproject@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ webpack@3.10.0
added 336 packages from 275 contributors in 133.941s
****
PS E:\COLDDEMO\js源码示例\WebPack> webpack -v
3.10.0
PS E:\COLDDEMO\js源码示例\WebPack> webpack list.js build.js//把list.js文件打包成build.js文件
Hash: 44a3af32917d3df32683
Version: webpack 3.10.0
Time: 50ms
Asset Size Chunks Chunk Names
build.js 2.5 kB 0 [emitted] main
[0] ./list.js 22 bytes {0} [built]
PS E:\COLDDEMO\js源码示例\WebPack> webpack list.js build.js//重新打包
Hash: 78ebebcbd1f433b2bd80
Version: webpack 3.10.0
Time: 48ms
Asset Size Chunks Chunk Names
build.js 2.5 kB 0 [emitted] main
[0] ./list.js 24 bytes {0} [built]
网友评论