无法为FlexboxGrid找到合适的加载器[ReactJS]

时间:2016-06-16 21:41:46

标签: reactjs webpack flexbox

我目前正在尝试将此库http://roylee0704.github.io/react-flexbox-grid/与我的反应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"
  }
}

1 个答案:

答案 0 :(得分:2)

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

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

你只做过程的第1部分。你告诉你的css加载器,它使用postcss,因此与flexboxgrid不兼容,忽略flexboxgrid,但你没有为它创建一个新的加载器。

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