javascript - 忽略 node_modules 上的 React 警告
问题描述
出于某种原因,我的构建仍在捕获和处理位于 node_modules 中的代码的 React 警告。我想禁用它,但不确定它是如何读取该代码的。
我没有componentWillMount
在我自己的代码中使用任何地方。它以某种方式在 node_modules 中拾取它。
webpack.config.js
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const isProduction = process.env.NODE_ENV === 'production';
const html = () =>
new HtmlWebPackPlugin({
template: path.resolve(__dirname, 'src/client', 'index.html'),
filename: 'index.html',
hash: true,
});
const copyAllOtherDistFiles = () =>
new CopyPlugin({
patterns: [
{ from: 'src/client/assets', to: 'lib/assets' },
{ from: 'package.json', to: './' },
{ from: 'ext/ink-3.1.10/js/ink-all.min.js', to: 'lib/js' },
{ from: 'ext/ink-3.1.10/js/autoload.min.js', to: 'lib/js' },
{ from: 'ext/ink-3.1.10/css/ink-flex.min.css', to: 'lib/css' },
{ from: 'ext/js/jquery-2.2.3.min.js', to: 'lib/js' },
{ from: 'ext/ink-3.1.10/fonts', to: 'lib/css/fonts' },
{ from: 'feed.xml', to: './' },
],
});
module.exports = {
entry: './src/client/index.tsx',
output: {
filename: 'scripts/app.[hash].bundle.js',
publicPath: '/',
path: path.resolve(__dirname, 'dist'),
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
},
devtool: 'source-map',
devServer: {
open: true,
writeToDisk: false,
publicPath: '/',
compress: true,
historyApiFallback: {
index: '/',
},
stats: 'errors-only',
proxy: {
'/api': {
target: 'http://localhost:3000',
secure: false,
changeOrigin: true,
logLevel: 'debug',
},
},
},
optimization: {
splitChunks: {
cacheGroups: {
styles: {
name: 'styles',
test: /\.css$/,
chunks: 'all',
enforce: true,
},
},
},
},
module: {
rules: [
{
test: /\.(js)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.(tsx|ts)?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.html$/,
exclude: /node_modules/,
use: [
{
loader: 'html-loader',
},
],
},
{
test: /\.less$/,
exclude: /node_modules/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'less-loader'],
},
{
test: /\.css$/,
exclude: /node_modules/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '../../',
outputPath: 'lib/css',
},
},
'css-loader',
],
},
{
test: /\.(woff(2)?|ttf|eot|otf|svg)?$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
publicPath: '/lib/css/fonts', // <--resolve the path in css files
outputPath: 'lib/css/fonts', // <-- path to place font files
},
},
],
},
{
test: /\.(png|svg|jpg|gif)$/,
use: ['url-loader'],
},
],
},
plugins: isProduction
? [
new CleanWebpackPlugin(),
copyAllOtherDistFiles(),
new MiniCssExtractPlugin({
filename: 'lib/css/[name].[hash].css',
}),
html(),
]
: [
copyAllOtherDistFiles(),
new MiniCssExtractPlugin({
filename: 'lib/css/[name].[hash].css',
}),
html(),
],
};
解决方案
推荐阅读
- python - 如何提高while循环的运行时间
- python - 更快的算法来定制给定的数学表达式
- java - 如何在Java中读回一个字节?
- c++ - 重载链表中的赋值运算符
- python - 在 Python 中使用 else 函数时出现错误
- c++ - 如何使用 C++ 从 data.txt 文件中获取平均值?
- android - 如何在 Kotlin Multiplatform 项目的 iOS 模块中将字符串转换为字节数组?
- r - 无法在 R/RStudio 中使用正确的文件路径
- android - 程序类型已经存在:com.google.logging.type.HttpRequestProto [Android]
- python - Django:具有多个 fk 字段的 ManyToMany 字段