【问题标题】:Syntax clarification: What does the $ mean in webpack config?语法说明:webpack 配置中的 $ 是什么意思?
【发布时间】:2021-07-21 05:04:12
【问题描述】:

我想知道这个特殊符号在 webpack(或其他配置文件)中做了什么。

module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: "babel-loader",
                    options: {
                        cacheDirectory: true,
                        cacheCompression: false,
                        envName: "development"
                    }
                }
            },
...

在 rules.test 中,有 "/.js$/" 。 $ 符号是什么意思?

【问题讨论】:

标签: javascript webpack syntax babeljs


【解决方案1】:

这里的 $ 符号是正则表达式 (regex) end of line anchor,它断言只有在行尾找到的模式才匹配。

在这种情况下,/\.js$/ 模式匹配文件路径末尾的 .js 文件扩展名。

【讨论】:

  • FWIW,如果未指定 m 标志,则它匹配字符串的结尾。
猜你喜欢
  • 2014-12-24
  • 1970-01-01
  • 2013-11-02
  • 2015-09-30
  • 1970-01-01
  • 2010-11-03
  • 2012-01-05
  • 2016-07-12
  • 1970-01-01
相关资源
最近更新 更多