Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 在react应用程序的网页包配置中查询预设与加载程序_Reactjs_Webpack_Babeljs - Fatal编程技术网

Reactjs 在react应用程序的网页包配置中查询预设与加载程序

Reactjs 在react应用程序的网页包配置中查询预设与加载程序,reactjs,webpack,babeljs,Reactjs,Webpack,Babeljs,现在我尝试使用react with webpack将其包含到应用程序中。 这是我的一个网页配置: module: { loaders: [{ test: [/\.jsx$/, /\.js$/], exclude: /(node_modules|bower_components)/, loader: 'babel', query: {presets: ['react', 'es2015']} }, { test: /(\.scss|\.css)

现在我尝试使用react with webpack将其包含到应用程序中。 这是我的一个网页配置:

module: {
  loaders: [{
    test: [/\.jsx$/,  /\.js$/],
    exclude: /(node_modules|bower_components)/,
    loader: 'babel',
    query: {presets: ['react', 'es2015']}
  },
  {
    test: /(\.scss|\.css)$/,
    loader: ExtractTextPlugin.extract('style', 'css?sourceMap&modules&importLoaders=1&localIdentName=[local]_[hash:base64:5]!postcss?sourceMap!sass!toolbox')
  },
  {
    test: /\.(png|jpg)$/,
    loader: 'url-loader?limit=8192'
  }]}
但在库的描述中,有另一种方式包含模块:

module: {
loaders: [{
  test:[/\.jsx$/,  /\.js$/],
  loaders: ['react-hot', 'babel?stage=0&loose[]=es6.modules'],
  include: [
    path.resolve(__dirname, "src"),
    path.resolve(__dirname, "node_modules/flash-notification-react-redux")
  ],
}, {
  test: [/\.scss$/, /\.css$/],
  loader: 'css?localIdentName=[path]!postcss-loader!sass',
}],},};
我们看不到“查询”,但看到的是“加载器”,而不是“加载器”。我应该如何在配置中包含库


谢谢。

在应用程序中包含库的最简单方法是请求或导入库

如果您使用的是commonjs语法,请执行以下操作:

var React = require('react');
如果您使用的是ES6语法:

import React from 'react';
通过这样做,当webpack捆绑您的文件时,依赖项将捆绑在一起

加载器和加载器之间的区别在于,对于加载器,只有一个加载器将处理您的文件,当使用加载器时,您可以让不同的加载器像管道一样处理文件。请注意,加载程序是从右向左执行的

查询是将参数传递给加载程序的一种方法。不能定义查询参数和多个加载程序

如果需要将参数传递给加载程序,并且需要对同一文件类型使用多个加载程序,则可以通过对每个对象使用一个加载程序来实现,如下所示:

module: {
    loaders: [
      {
        test: /\.css$/,
        loader: 'style',
        query: {}
      },
      {
        test: /\.css$/,
        loader: 'css',
        query: {}
      }
    ]
  }
相同文件类型的加载程序从下到上执行,因此上述示例与此示例相同:

module: {
    loaders: [
      {
        test: /\.css$/,
        loaders: ['style',  'css']
      }
    ]
  }