webpack.config 之外的 Webpack css 加载器配置?

Webpack css loader configuration outside of webpack.config?

我将 webpack 和 css-loader 与 React 应用程序一起使用,运行 在我编写它的原始目录中的 webpack 开发服务器上很好。但是,在推送到 git 并克隆存储库后,克隆版本不会加载 css(详情如下)。

除了webpack.config.js、package.json、package-lock.json之外,还有哪些地方可以配置webpack loader?或者,关于为什么应用程序副本中的行为会有所不同的任何想法?我在没有 .gitignore 的情况下尝试了此操作,以确保我没有剥离任何内容,因此所有文件都应该相同。

编辑:现在在 运行 开发服务器上的副本之后,原始副本也无法正常工作,所以我正在寻找缓存的内容。


更多详情:

克隆后我发现我使用了不正确的加载程序语法,因为 webpack.config.js 现在需要“-loader”。出于某种原因,它在原始副本中有效,但两个实例都在 webpack 3.8.1 和 css-loader 0.28.7 上。 (而且由于 package.json、package-lock.json 和 / node_modules 都在 git 中,所有内容应该是相同的版本 - 对吗?)

这在我的原始存储库中有效:

webpack.config.js:
(...)
{
    test: /\.css$/,
    loader: 'css?modules&importLoaders=1&localIdentName=[path]___[name]__[local]___[hash:base64:5]'
},

但在克隆目录中导致此错误:

BREAKING CHANGE: It's no longer allowed to omit the '-loader' suffix when using loaders.
             You need to specify 'css-loader' instead of 'css',
             see https://webpack.js.org/guides/migrating/#automatic-loader-module-name-extension-removed
 @ ./app/components/GroupTable.js 3:0-37
 @ ./app/components/MainView.js
 @ ./app/components/App.js
 @ ./app/index.js
 @ multi (webpack)-dev-server/client?http://localhost:8081 ./app/index.js

所以我将其更新为:

webpack.config.js
(...)
{
        test: /\.css$/,
        loader: 'css-loader?modules&importLoaders=1&localIdentName=[path]___[name]__[local]___[hash:base64:5]'
    },

当我添加“-loader”webpack.config.js 时,css 没有像以前那样加载。 webpack.config 中没有其他测试对 .css 个文件评估为真。

我知道的配置文件 (webpack.config.js, package.json, package-lock.json) 在两个副本之间是相同的,所以我想找出答案还有什么可能导致行为差异。

万一有人发现这个问题,看起来 不是 在上面列出的文件之外的配置。我认为问题是我在更改 css 加载程序后没有从 webpack 重建,所以没有意识到我已经破坏了它。我 运行 在 git 的副本中构建,因此它使用收到的配置,但已损坏。

这解决了是否存在隐藏配置的问题,但似乎没有。我仍然不确定为什么这个加载器不起作用:

loader: 'css?modules&importLoaders=1&localIdentName=[path]___[name]__[local]___[hash:base64:5]'

但与此同时:

{
    test: /\.css$/,
    loader: "style-loader!css-loader"
},