Webpack modules.rules所包含的数组的Rule具有的一些参数

来源:互联网 发布:linux系统数据库备份 编辑:程序博客网 时间:2024/05/20 23:07

Rule参数
Rule.options / Rule.query
Rule.options 和 Rule.query 是 Rule.use: [ { options } ] 的简写。详细请查看 Rule.use 和 UseEntry.options。

Rule.enforce
参数可能为pre或post
制定loader的分类,不对该参数做配置时表示使用normal loader。
另外支持一种inlined loader,适用于内联的import/require。
loaders按照post,inline,normal,pre顺序执行。//重点
normal类型的loader使用!前缀
normal和pre类型的loader使用-!前缀
normal“post,pre类型的loader使用!!前缀
inline loaders及!都是非独立loader,只能被loader生成的代码使用。

Rule.parser
解析选项对象。所有应用的解析选项都将合并。

解析器(parser)可以查阅这些选项,并相应地禁用或重新配置。大多数默认插件,会如下解释值:

将选项设置为 false,将禁用解析器。
将选项设置为 true,或不修改将其保留为 undefined,可以启用解析器。
然而,一些解析器(parser)插件可能不光只接收一个布尔值。例如,内部的 NodeStuffPlugin 差距,可以接收一个对象,而不是 true,来为特定的规则添加额外的选项。

示例(默认的插件解析器选项):

parser: {
amd: false, // 禁用 AMD
commonjs: false, // 禁用 CommonJS
system: false, // 禁用 SystemJS
harmony: false, // 禁用 ES2015 Harmony import/export
requireInclude: false, // 禁用 require.include
requireEnsure: false, // 禁用 require.ensure
requireContext: false, // 禁用 require.context
browserify: false, // 禁用特殊处理的 browserify bundle
requireJs: false, // 禁用 requirejs.*
node: false, // 禁用 __dirname, __filename, module, require.extensions, require.main 等。
node: {…} // 在模块级别(module level)上重新配置 node 层(layer)
}

Rule.resourceQuery
A Condition matched with the resource query. This option is used to test against the query section of a request string (i.e. from the question mark onwards). If you were to import Foo from ‘./foo.css?inline’, the following condition would match:

{
test: /.css$/,
resourceQuery: /inline/,
use: ‘url-loader’
}

条件
条件可以是这些之一:

字符串:匹配输入必须以提供的字符串开始。是的。目录绝对路径或文件绝对路径。
正则表达式:test 输入值。
函数:调用输入的函数,必须返回一个真值(truthy value)以匹配。
条件数组:至少一个匹配条件。
对象:匹配所有属性。每个属性都有一个定义行为。
{ test: Condition }:匹配特定条件。一般是提供一个正则表达式或正则表达式的数组,但这不是强制的。

{ include: Condition }:匹配特定条件。一般是提供一个字符串或者字符串数组,但这不是强制的。

{ exclude: Condition }:排除特定条件。一般是提供一个字符串或字符串数组,但这不是强制的。

{ and: [Condition] }:必须匹配数组中的所有条件

{ or: [Condition] }:匹配数组中任何一个条件

{ not: [Condition] }:必须排除这个条件

Avoid using these options as they are deprecated and will soon be removed. 避免使用这些选项,因为它们已废弃,并将很快删除。
这些选项描述了当遇到动态依赖时,创建上下文的默认设置。

例如,未知的(unknown) 动态依赖:require。

例如,表达式(expr) 动态依赖:require(expr)。

例如,包裹的(wrapped) 动态依赖:require(“./templates/” + expr)。

以下是其默认值的可用选项

module: {
exprContextCritical: true,
exprContextRecursive: true,
exprContextRegExp: false,
exprContextRequest: “.”,
unknownContextCritical: true,
unknownContextRecursive: true,
unknownContextRegExp: false,
unknownContextRequest: “.”,
wrappedContextCritical: false
wrappedContextRecursive: true,
wrappedContextRegExp: /.*/,
strictExportPresence: false // since webpack 2.3.0
}