Skip to content
This repository was archived by the owner on Mar 22, 2019. It is now read-only.
e-cloud edited this page Jul 12, 2016 · 2 revisions

Installation

安装

$ npm install webpack -g

The webpack command is now available globally.

现在webpack命令全局可用

Pure CLI

纯CLI工作

webpack <entry> <output>

entry

entry 入口文件

Pass a file or a request string. You can pass multiple entries (every entry is loaded on startup).

传入一个文件或请求字符串。你可以传入多个入口文件(每个入口文件会在启动时加载)

If you pass a pair in the form <name>=<request> you can create an additional entry point.

如果你传入形如<name>=<request>的一对值,你可以传入一个额外的入口点。

It will be mapped to the configuration option entry.

它将被映射到配置选项entry

output

Pass a path to a file.

传入目标文件路径

It will be mapped to the configuration options output.path and output.filename.

它将被映射到配置选项output.pathoutput.filename

Configuration options

配置选项

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

许多配置选项从CLI选项映射而来。例如,--debug映射到debug: true,或--output-library-target映射为output.libraryTarget

You will see a list of all options if you don't pass any options.

如果你不传递任何选项,你会看到所有选项的列表。

Plugins

插件

某些插件被映射到CLI选项。例如,--define <string> = <string>映射到DefinePlugin

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

You will see a list of all options if you don't pass any options.

如果你不传递任何选项,你会看到所有选项的列表。

Development shortcut -d

开发时快捷选项 -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

等价于 --optimize-minimize --optimize-occurence-order

Watch mode --watch

监听模式 --watch

Watches all dependencies and recompile on change. 监视所有依赖模块,出现变化时重新编译

Configuration file --config example.config.js

配置文件--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.

显示编译进度至标准错误流。

--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. 按列分别排序 modules/chunks/assets

--display-chunks

Display the separation of the modules into 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"],输出时默认被隐藏

--display-exclude

Exclude modules in the output. 在输出信息中去除某些模块

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 information. 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).

  • dependencies: The time that was spent gathering and connecting the dependencies.

  • factory: 构建模块信息所花的时间.

  • building: 构建模块花费的时间 (例如loaders).

  • dependencies: 收集和关联依赖模块的耗时.

Additional configuration options

###其他配置选项

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

当使用CLI时,它可能具有配置文件中的下列选项。当使用node.js API时,会使用其他方式传入配置。

watch

Enter watch mode, which rebuilds on file change.

进入监听模式,文件更改重新构建。

watchOptions.aggregateTimeout

Delay the rebuild after the first change. Value is time in ms.

延迟检测到第一个文件更改信号后重新构建的发生时间。值以ms为单位

Default: 300

watchOptions.poll

true: use polling

true: 使用轮询策略

number: use polling with specified interval

number: 轮询的指定时间间隔

Default: undefined

stats

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

显示选项。参见node.js API Stats.toString()了解更多详情。

Clone this wiki locally