4040 docker ps
4141```
42423 . 执行构建
43- ```
43+
44+ ``` bash
4445 docker exec -it -w /home/webpack4-cli b7c2b83ed900 /bin/bash
4546```
46- 4 . 导出build后文件
47- ```
47+
48+ 1 . 导出build后文件
49+
50+ ``` bash
4851 docker cp b7c2b83ed900:/home/webpack4-cli/dist ./
4952```
53+
5054## 快速使用
55+
5156* 下载依赖(建议yarn)
52- ``` base
57+
58+ ``` bash
5359 yarn install
5460```
61+
5562or
56- ``` base
63+
64+ ``` bash
5765 npm install
5866```
67+
5968* 开发模式
69+
6070``` bash
6171 npm run dev
6272```
73+
6374* 生产模式
75+
6476``` bash
6577 npm run build
6678```
79+
6780* bundle分析
81+
6882``` bash
6983 npm run analyze
7084```
85+
7186## 在实际工作中使用 & 自定义 HTML
87+
7288cli将会根据pageDir路径,动态生成webpack entry,在源码中,一个页面就是一个文件夹。
7389首先介绍一个html文件夹下可以存放的三个文件:
90+
7491* entry.js 为本页面的资源入口(无论使用哪种方式定制HTML,此文件都必须存在)
7592* param.js 为默认模板传递参数(如果你想快速定制HTML,这是个不错的选择)
7693* page.html 用于重写HTML,若此文件存在,cli将会将page.html的优先级提至最高,用以替代默认模板。
7794
7895你可以通过以下两种方式自定义HTML:
79- 1 . ### 使用param.js 和 entry.js
96+
97+ ### 使用param.js 和 entry.js
98+
8099如果param.js存在,cli则会将param.js中的参数与pug引擎模板结合产出对应HTML,entry.js中引入的资源(js,css)将会被通过标签插入至对应HTML中。
100+
81101* param.js 中的配置项如下,你也可以通过快速查看demo中的代码例子 来快速上手:
82102 | Name | Type | Default | Description |
83103 | :---:| :---:| :---:| :---:|
@@ -93,6 +113,7 @@ cli将会根据pageDir路径,动态生成webpack entry,在源码中,一个
93113 | vueInit.entrance | String | undefined | vue根实例的入口组件,可详见vue-demo |
94114 | reactInit | Object | {} | 初始化react根节点 |
95115 | reactInit.el | String | undefined | react根实例的el值,如”#root“ 可详见react-demo |
116+
96117``` js
97118 // for detai code, you can view vueDemo in dev mode
98119 module .exports = {
@@ -120,6 +141,7 @@ cli将会根据pageDir路径,动态生成webpack entry,在源码中,一个
120141 }
121142 }
122143```
144+
123145``` html
124146 <!doctype html>
125147 <html lang =" en" >
@@ -144,11 +166,13 @@ cli将会根据pageDir路径,动态生成webpack entry,在源码中,一个
144166
145167 </html >
146168```
147- 2 . ### 使用 page.html 和 entry.js
148- 使用page.html 意味着,完全的定制化,你需要完全重写HTML
149169
170+ ### 使用 page.html 和 entry.js
171+
172+ 使用page.html 意味着,完全的定制化,你需要完全重写HTML
150173
151174## 在实际工作中使用 & 自定义env
175+
152176在根路径的 cli-config.js 文件中自定义env,详细选项如下:
153177 | Name | Type | Default | Description |
154178 | :---:| :---:| :---:| :---:|
@@ -158,9 +182,11 @@ cli将会根据pageDir路径,动态生成webpack entry,在源码中,一个
158182 | build.htmlAssetsAbsolutePath | Boolean\| String | false | 控制build环境下,编译后HTML中资源标签的根路径,一般以此来修改为服务器资源基础url或cdn-url |
159183
160184## 提醒
185+
1611861 . 你可以自定义你的page目录,可根据业务模块嵌套等等。并且输出的html目录也会动态变化。以下有个例子可以帮助您理解,您也可以在cli中尝试
162- ```
163- Root
187+
188+ ``` bash
189+ Root
164190 └───src
165191 │———node_modules
166192 | ———page // html dir
@@ -180,8 +206,10 @@ cli将会根据pageDir路径,动态生成webpack entry,在源码中,一个
180206 | | └———entry.js
181207
182208```
209+
183210输出路径也会自动变化(包括html和静态资源)
184- ```
211+
212+ ``` bash
185213 Root
186214 | ———dist // output root
187215 | | ——— js
@@ -203,22 +231,23 @@ cli将会根据pageDir路径,动态生成webpack entry,在源码中,一个
203231 | | | ——— ... // css dir is the same as js
204232 | | ...
205233```
234+
2062351 . src/assets路径用以存放静态文件,例如txt文档等,此路径下的文件将不会被打包,并会原样输出至dist下。
2072362 . 你可以在gulpfile下手动选择压缩插件,通常默认选项就可满足需要。
2082373 . 你可以再 postcss.config.js中自定义, 现在, autoprefixer 已被配置.
2092384 . 注意你的环境版本, ![ webpack-versioin] ( https://img.shields.io/badge/webpack-4.0.0+-green ) ![ node-versioin] ( https://img.shields.io/badge/node-v10.8.0-green ) ![ npm-versioin] ( https://img.shields.io/badge/npm-v6.2.0-green )
2102395 . 建议使用yarn安装模块包,这将会让你在多人项目中减少因版本不一致带来的问题。
211240
212241## 核心插件
242+
213243希望在以下插件中得到更多支持,欢迎给星:
214- 1 . <a href =" https://github.com/pomelott/html-inline-entry-chunk-plugin " >html-inline-entry-chunk-plugin</a >
215- 2 . <a href =" https://github.com/jantimon/html-webpack-plugin " >html-webpack-plugin</a >
216- 3 . <a href =" https://github.com/webpack-contrib/extract-text-webpack-plugin " >extract-text-webpack-plugin</a >
217244
245+ * [ html-inline-entry-chunk-plugin] ( https://github.com/pomelott/html-inline-entry-chunk-plugin )
246+ * [ html-webpack-plugin] ( https://github.com/jantimon/html-webpack-plugin )
247+ * [ extract-text-webpack-plugin] ( https://github.com/webpack-contrib/extract-text-webpack-plugin )
218248
219249## 友情链接
220- 1 . <a href =" https://www.cnblogs.com/pomelott/p/9030208.html " >the split-chunk-plugin Doc</a >
221- 2 . <a href =" https://www.cnblogs.com/pomelott/p/6974167.html " >webpack 1.x help Doc</a >
222- 3 . <a href =" https://www.cnblogs.com/pomelott/p/8977092.html " >webpack 4.x help Doc</a >
223-
224250
251+ * [ the split-chunk-plugin Doc] ( https://www.cnblogs.com/pomelott/p/9030208.htm )
252+ * [ webpack 1.x help Doc] ( https://www.cnblogs.com/pomelott/p/6974167.html )
253+ * [ webpack 4.x help Doc] ( https://www.cnblogs.com/pomelott/p/8977092.html )
0 commit comments