webpack入门(五)webpack CLI

webpack的CLI安装和命令html

Installation

$ npm install webpack -g

The webpack command is now available globally.    执行完上面命令,webpack命令在全局可用node

Pure CLI

webpack <entry> <output>

entry

Pass a file or a request string. You can pass multiple entries (every entry is loaded on startup).   传入一个文件或者请求字符串,你能够传递多个entries(每一个entry都会在初始的时候加载)webpack

If you pass a pair in the form <name>=<request> you can create an additional entry point.   若是传一个一对值,你就能够建立额外的entrygit

It will be mapped to the configuration option entry.   会被映射到配置的entry选项github

output

Pass a path to a file.    传入一个文件路径web

It will be mapped to the configuration options output.path andoutput.filename. 会被映射到配置选项的output.path 和output.filename.npm

Configuration options

Many configuration options are mapped from CLI options. I. e. --debugmaps to debug: true, or --output-library-target to output.libraryTarget.json

You see a list of all options, if you don’t pass any option.  许多配置选项是从cli选项映射来的。 --debug对象debug:true,--output和 --output-library-target对应output.libraryTarget.若是你不传参数,你就会看到全部选项的列表api

Plugins

Some plugins are mapped to CLI options. I. e. --define <string>=<string> maps to the DefinePlugin.app

You see a list of all options, if you don’t pass any option.  一些插件也对应CLI的选项,--define <string>=<string> 对应 DefinePlugin.若是你不传参数,你就会看到全部选项的列表

Development shortcut -d

Equals to --debug --devtool source-map --output-pathinfo  等同于--debug --devtool source-map --output-pathinfo

Production shortcut -p

Equals to --optimize-minimize --optimize-occurence-order

Watch mode --watch

Watches all dependencies and recompile on change.   观测全部依赖,若有变更,从新编译。(经常使用的选项)

Configuration file --config example.config.js

Specifies a different configuration file to pick up. Use this if you want to specify something different than webpack.config.js, which is the default.

选择不一样配置的文件,当你想指向别的配置文件而不是默认的webpack.config.js的时候用。(经常使用的选项)

Display options

--progress

Display a compilation progress to stderr.   在stderr中显示编译进度。

--json

Write JSON to stdout instead of a human readable format.    输出JSON格式而不是人类可读的格式

Hint: Try to put the result into the analyse tool.  

--no-color

Disable colors to display the statistics.   展现统计信息的时候禁用颜色。

--sort-modules-by--sort-chunks-by--sort-assets-by

Sort the modules/chunks/assets list by a column. 按列排序模块/块/assets列表。

--display-chunks

Display the separation of the modules into chunks. 展现分离为chunks的模块

--display-reasons

Show more information about the reasons why a module is included.  展现一些为啥这个模块被包含的信息。

--display-error-details

Show more information about the errors. I. e. this shows which paths are tried while resolving a module. 展现更多的错误信息。好比展现解析模块时尝试的路径

--display-modules

Show hidden modules. Modules are hidden from output by default when they live inside directories called["node_modules", "bower_components", "jam", "components"]  显示隐藏模块,当他们在["node_modules", "bower_components", "jam", "components"]中被调用时,模块默认被隐藏。

Profiling

If you wish to have a more in-depth idea of what is taking how long, you can use the --profile switch. This will cause WebPack to display more detailed timing informations. Combine this with the switches above to get a very detailed message and information set, which will contain the timings of your modules. 若是你但愿有一个什么是多久的想法,你能够用--profile来选择,他会让webpack展现更多的时间信息。结合以上的选择,会获得一个详尽的信息,包含你模块的耗时。

The timing “keys”

  • factory: The time it took to build the module information.构建模块信息的时间。
  • building: The time that was spent building the module (loaders, for example).构建模块的时间(好比loaders)
  • dependencies: The time that was spent gathering and connecting the dependencies. 整合和链接模块依赖的时间。

Additional configuration options

When using the CLI it’s possible to have the following options in the configuration file. They passed in other ways when using the node.js API.

当使用CLI,可能会用到下面配置文件中的选项,当用nodejs API的时候会以其余方式被传入。

watch

Enter watch mode, which rebuilds on file change.  进入观察模式,文件改变触发从新构建

watchOptions.aggregateTimeout

Delay the rebuilt after the first change. Value is a time in ms.  第一次改变后延迟重建的时间,值是时间毫秒数。

Default: 300

watchOptions.poll

true: use polling 

number: use polling with specified  interval   在指定区间使用轮询

Default: undefined

stats

Display options. See node.js API Stats.toString() for more details. 

相关文章
相关标签/搜索