【问题标题】:Cannot find an Appropriate Loader for FlexboxGrid [ReactJS]找不到适合 FlexboxGrid [ReactJS] 的加载器
【发布时间】:2016-06-17 06:10:21
【问题描述】:

我目前正在尝试将此库 http://roylee0704.github.io/react-flexbox-grid/ 与我的 react JS 应用程序一起使用。

我目前已经完成了 webpack 设置,并按照 flexbox-grid 的 Github 上的说明进行操作。

但是,每次我尝试运行我的应用程序时,都会发现我没有合适的加载程序来处理这种文件类型。我也已经安装了 webpack css-loader,所以我不确定我还缺少什么。

webpack.config.js

var webpack = require('webpack');
var path = require('path');

var BUILD_DIR = path.resolve(__dirname, 'src/client/public');
var APP_DIR = path.resolve(__dirname, 'src/client/app');

var config = {
  entry: APP_DIR + '/App.jsx', 
  output: {
    path: BUILD_DIR,
    filename: 'bundle.js'
  },
  module : {
    loaders : [
      {
        test : /\.jsx?/,
        include : APP_DIR,
        loader : 'babel'
      },
      {
        test: /\.css$/,
        loader: 'style!css!postcss',
        include: path.join(__dirname, 'node_modules'), // this also includes flexboxgrid
        exclude: /flexboxgrid/, // so we are excluding it
      }
    ]
  }
};

module.exports = config;

这是我的 package.json

{
  "name": "PokerSiteMaterial",
  "version": "1.0.0",
  "description": "Poker Site",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "webpack -d --watch",
    "build": "webpack -p"
  },
  "author": "Kai Mou",
  "license": "ISC",
  "dependencies": {
    "babel-core": "^6.9.1",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.9.0",
    "babel-preset-react": "^6.5.0",
    "react": "^15.1.0",
    "react-dom": "^15.1.0",
    "webpack": "^1.13.1"
  },
  "devDependencies": {
    "css-loader": "^0.23.1"
  }
}

【问题讨论】:

    标签: reactjs webpack flexbox


    【解决方案1】:

    尝试将它添加到您的 webpack 配置中,除了您当前的 css 规则,如 react-flexbox-grid README 中所述...

    {
      test: /\.css$/,
      loader: 'style!css?modules',
      include: /flexboxgrid/,
    }
    

    您只完成了流程的第 1 部分。您告诉使用 postcss 并因此与 flexboxgrid 不兼容的 css 加载程序忽略 flexboxgrid,但您没有为它创建新的加载程序。

    基本上,flexboxgrid 需要 css 加载器加载。由于您使用的是postcss,因此您需要告诉您的主要 css 规则忽略它并添加上述规则来处理它

    【讨论】:

      猜你喜欢
      • 2014-12-29
      • 2018-03-24
      • 2019-10-30
      • 2017-05-29
      • 1970-01-01
      • 2018-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多