require('jquery') vs require('semantic-ui-css'),只有一个适用于使用 webpack 进行反应编程

require('jquery') vs require('semantic-ui-css'), only one works in react programming with webpack

在使用 React 和(我使用 webpack)编程时,我注意到

require('jquery')

npm install jquery --save

之后有效
require('semantic-ui-css')

不在npm install semantic-ui-css --save之后。

webpack 是如何做到 jquery 可以像那样导入,而 semantic-ui-css 不能。

换句话说,webpack 如何将给定名称解析为要加载的模块?

查看各自的 package.json 文件 - the jQuery one has the main property set to dist/jquery.js, whereas the semantic-ui-css one does not have it at all. Whatever file is set there is what Node/Webpack will provide when you import the package. If it's not there, you can't import the package by name - you either have to specify a particular file (e.g. semantic-ui-css/semantic.css) or use Webpack's module aliasing functionality.