Configuration
You may have noticed that few webpack configurations look exactly alike. This is because webpack's configuration file is a JavaScript file that exports a webpack configuration. This configuration is then processed by webpack based upon its defined properties.
你可能已经知道有些webpack的配置看起来很熟悉。这是因为webpack的配置文件是一个导出webpack配置的javascript文件。然后webpack根据基础配置来运行处理这个配置
Because it's a standard Node.js CommonJS module, you can do the following:
因为它是使用node.js CommonJs模块规范运行的,你可以做以下的事情:
- import other files via require(...)
- 通过require(...) 引入其它模块
- use utilities on npm via require(...)
- 通过require(...)在npm 上使用有用的模块
- use JavaScript control flow expressions, e.g. the ?: operator
- 使用javascript来控制流表现,例如 ?:
- use constants or variables for often used values
- write and execute functions to generate a part of the configuration
- 写并执行方法来颜色一部分配置
Use these features when appropriate.While they are technically feasible, the following practices should be avoided:
当合适时使用这些特征。当它们在技术上适合,下面的属性应该避免使用。
- Access CLI arguments, when using the webpack CLI (instead write your own CLI, or use --env)
- cli 参数入口,当使用webpack cli(代替你自己写的cli,或者使用 ---env)
- Export non-deterministic values (calling webpack twice should result in the same output files)
- 导出没有定性的值()
- Write long configurations (instead split the configuration into multiple files)
- 写长配置(应该把配置切割到多个文件中)
The most important part to take away from this document is that there are many different ways to format and style your webpack configuration. The key is to stick with something consistent that you and your team can understand and maintain.
从这文章中最重要的是要远离的是,有多种方法来序列化我们的webpack配置。关键是粘粘你的团队能够明白和理解的配置。