> For the complete documentation index, see [llms.txt](https://azr.gitbook.io/webpack/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://azr.gitbook.io/webpack/zhun-bei-kai-shi/dan-ge-js-wen-jian.md).

# 单个JS文件

## 安装开始Dome

```javascript
$  mkdir webpack-demo && cd webpack-demo
$  npm i webpack webpack-cli -g
```

## 目录&结构

entry.js&#x20;

```javascript
document.write('I am entry.js');
```

### 命令

> webpack|v4.x以后需要添加--mode，production模式下会对代码进行压缩，development模式不会对代码进行压缩。

```javascript
基本格式：$  webpack-cli [options] --entry <entry> --output <output>
$ webpack entry.js  -o  bundle.js --mode=development
```

显示以下，即是打包成功。

```javascript
Hash: a5aee4f6f417a17019e8
Version: webpack 4.26.1
Time: 99ms
Built at: 2018-11-28 10:12:17
    Asset      Size  Chunks             Chunk Names
bundle.js  3.78 KiB    main  [emitted]  main
Entrypoint main = bundle.js
[./entry.js] 32 bytes {main} [built]
```

执行命令之后会多出来一个文件，即 `bundle.js`

### 运行

新建`index.html`文件来进行运行，页面会显示`I am entry`。

```javascript
<!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>weepack-dome</title>
  // 引用bundle.js
  <script src="./bundle.js"></script>
</head>
<body>
  
</body>
</html>
```
