【问题标题】:Unable to load/require any css files in Node无法在 Node 中加载/需要任何 css 文件
【发布时间】:2017-02-28 07:06:19
【问题描述】:

我有一个基于 boilerplate 的 ReactJS 应用程序。

我只是想加载和requireimport 一个css 文件(嵌入在<style> 标记中,而不是css 链接)。以下是我尝试过的两种方法,但从来没有同时尝试过。

方法一:在Webpack中配置loader

这些是我尝试过的所有加载器配置,但仍然导致此错误:[require-hacker] Trying to load "something.css" as a "*.js"

dev.config.js

module: {
    loaders: [
      // loaders in here
    ]
 }
  1. { test: /\.css$/, loader: "style!css" }
  2. { test: /\.css$/, loader: 'style-loader!css-loader'} 来自here
  3. { test: /\.css$/, loader: 'style!css!postcss' }
  4. { test: /\.css$/, loader: 'style!css?modules&localIdentName=[name]---[local]---[hash:base64:5]!postcss' }
  5. { test: /\.css$/, use: [ { loader: 'css-loader', options: { modules: true, localIdentName: '[path][name]__[local]--[hash:base64:5]' } } ] }
  6. { test: /\.css$/, loader: 'style!css?modules&importLoaders=2&sourceMap&localIdentName=[local]___[hash:base64:5]!autoprefixer?browsers=last 2 version!sass?outputStyle=expanded&sourceMap' },

方法二:直接使用loader

如果我完全删除 css 加载器,而是调用 require('style!css!./something.css'),我会收到以下错误:

Error: Cannot find module 'style!css!./something.css'

---- # 注意: ----

我能够正确地require 我的.scss 文件,它的 webpack 加载器配置如下。但由于某种原因,我的 css 文件也不想那样播放。

    { test: /\.scss$/, 
      loader: 'style!css?modules&importLoaders=2&sourceMap&localIdentName=[local]___[hash:base64:5]!autoprefixer?browsers=last 2 version!sass?outputStyle=expanded&sourceMap' }

【问题讨论】:

    标签: javascript node.js reactjs webpack


    【解决方案1】:

    将扩展名:['less','scss'] 更改为扩展名:['less','scss','css'] in webpack-isomorphic-tools.js at line 65.for more details you can see @ 987654321@

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-02
      • 2017-05-27
      • 2013-02-28
      • 1970-01-01
      • 1970-01-01
      • 2014-09-29
      • 1970-01-01
      相关资源
      最近更新 更多