javascript - Webpack configuration in Gatsby, naming conventions
问题描述
I'm using Gatsby in one of my projects, and due to its configs, in the server side, Node doesn't have the window
loader. All that being said I found the guides in Gatsby docs for a previous package on how to avoid having these errors:
exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
if (stage === 'build-html' || stage === 'develop-html') {
actions.setWebpackConfig({
module: {
rules: [
{
test: /enter-package-name/,
use: loaders.null(),
},
],
},
});
}
};
Recently I've encountered the same error, and in part fault due to my lack of knowledge of Webpack and its naming conventions that are used, I couldn't use the same configuration for this package:
rules: [
{
test: /@brainhubeu/react-carousel/
}
]
I believe the slashes are used to locate the package, and due to the naming of my package having one in between the two words, its throwing an error due to not expecting something after the middle slash.
Any ideas on how I would do this either regex wise or Webpack. Materials and docs about said issue are welcomed.
P.S - Apologies if this question might be very basic, but I couldn't find the proper documentation on my own.
解决方案
You hit the nail. As you guess, test
is a regular expression (hence the slashes, /
) and it tests a folder location inside node_modules
. In your case, you may need to scape the middle slash with something like:
exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
if (stage === 'build-html' || stage === 'develop-html') {
actions.setWebpackConfig({
module: {
rules: [
{
test: /@brainhubeu\/react-carousel/,
use: loaders.null(),
},
],
},
});
}
};
推荐阅读
- sql - EXECUTE IMMEDIATE DROP FUNCTION 导致 Oracle SQL Developer 挂起
- node.js - Loopback 3 顺序、偏移量和限制。操作顺序
- java - 为什么停止 SwingWorker 会立即停止它?
- amazon-web-services - 在 AWS Ubuntu EC2 上部署 Dockerized MERN 应用程序。我需要 NGINX 或类似技术吗?
- java - 无法在 Java 中使用 OpenCV 读取图像,涉及 unicode 路径
- mysql - MySQL 查询返回不同的结果
- excel - VBA中的Linest函数
- c# - BFS 和 DFS 使用邻接矩阵 C#
- r - 求解 R 中餐厅顾客类型的百分比
- r - 如果发生某些情况,请更改图表上的数字