webpack使用css-loader时为什么不需要引入?

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [ 'style-loader', 'css-loader' ]
      }
    ]
  }
}

在webpack的配置文件中 直接就是用了css-loader
而没有使用require或者import去引入
这是为什么呢?

阅读 2.9k
3 个回答

你并没有直接用啊,你只是告诉webpack要用这个东西,怎么用是它的机制。

Referencing loaders By convention, though not required, loaders are
usually named as XXX-loader, where XXX is the context name. For
example, json-loader.

You may reference loaders by its full (actual) name (e.g.
json-loader), or by its shorthand name (e.g. json).

The loader name convention and precedence search order is defined by
resolveLoader.moduleTemplates within the webpack configuration API.

Loader name conventions may be useful, especially when referencing
them within require() statements; see usage below.

方档里有解释啊

loader 和你的 import xxx 不是一个东西。

loader实际上是webpack本身会去调用或者应用的函数而已,本质上,webpack 调用loader的方法是 loader-runner 也就是说,当你在webpack中配置了loader之后,它自身会在需要的地方加载你的loader,加载的方式就是:https://github.com/webpack/lo...

看你说没有啥文档,在loader-api里面就有说明:

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题