如何为节点模块路径编写regEx



我的node_modules文件夹中有以下库C:myProjectnode_modules@ng-selectng-option-highlight

我需要写regex,它将指向这个文件路径(webpack需要regex)

所以我现在所做的就是这个

/node_modules/@ng-select/,

这是我从其他地方找到的代码,我不知道它是否正确现在,如果我试图添加ng选项高亮显示,我会从webpack 中得到错误

An unhandled exception occurred: Invalid regular expression flags

/node_modules/@ng选择/ng选项高亮显示

如何在此处编辑此regex文件路径?

这是我的webpack配置文件

const webpack = require('webpack');
const TerserPlugin = require("terser-webpack-plugin");
const linkerPlugin = require("@angular/compiler-cli/linker/babel");
const path = require('path');
module.exports = {
/**
* Remove all unused MomentJS locales
* The problem is described in this article
* https://medium.jonasbandi.net/angular-cli-and-moment-js-a-recipe-for-disaster-and-how-to-fix-it-163a79180173
*/
plugins: [
new webpack.ContextReplacementPlugin(/moment[/\]locale$/, /de|en|fr|it/),
],
module: {
rules: [
{
include: /node_modules/,
test: /.mjs$/,
type: 'javascript/auto'
}
]
},
plugins: [
new webpack.DefinePlugin({
ngDevMode: true,
}),
new webpack.LoaderOptionsPlugin({
options: {
rules: [
{
test: /.*.d.ts$/,
include: /node_modules/@ng-select/,
use: {
loader: 'babel-loader',
options: {
configFile: false,
plugins: [linkerPlugin],
}
}
}
]
}
})
],
}

为了指示某个东西是正则表达式,正则表达式用斜杠括起来,比如:/<regex>/。在这种特定的情况下,这相当令人困惑,因为路径通常也以斜杠开始和结束。要在正则表达式中写入路径,我们需要用斜杠将其括起来,并使用反斜杠转义内部斜杠,以免混淆解析器。因此,新路径的值将为/node_modules/@ng-select/ng-option-highlight/

最新更新