简体   繁体   English

如何在webpack.config.dev.js文件中为React-FlexBox-Grid添加加载器

[英]How to add loader for React-FlexBox-Grid in webpack.config.dev.js file

Using basic web-pack configurations created by create-react-app 使用由create-react-app创建的基本Web Pack配置

{
   test: /\.css$/,        
   loader: 'style!css?importLoaders=1!postcss'      
}

Installed React-FlexBox-Grid using following npm command 使用以下npm命令安装React-FlexBox-Grid

npm i -S react-flexbox-grid

Installed the following dependencies 安装了以下依赖项

npm i -D npm style-loader css-loader

It seams React-FlexBox-Grid is not picked by the web-pack loader. 它表明Web-pack加载程序未选择React-FlexBox-Grid。 My question here is how to add React-FlexBox-Grid to the existing css loader configuration. 我的问题是如何将React-FlexBox-Grid添加到现有的CSS加载器配置中。 From the React-FlexBox-Grid document https://github.com/roylee0704/react-flexbox-grid suggested two settings I am not sure how to 从React-FlexBox-Grid文档https://github.com/roylee0704/react-flexbox-grid建议了两个设置,我不确定如何

1) 1)

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

2) 2)

 {
  test: /\.css$/,
  loader: 'style!css!postcss',
  include: path.join(__dirname, 'node_modules'), // oops, this also includes flexboxgrid
  exclude: /flexboxgrid/, // so we have to exclude it
 }

Not sure how to add the loader without breaking the existing working configurations. 不知道如何在不破坏现有工作配置的情况下添加加载程序。

if you already have a css loader in your webpack config I would suggest you add it as follows. 如果您的webpack配置中已经有css加载器,我建议您如下添加它。

assuming your css loader looks something like this: 假设您的CSS加载程序看起来像这样:

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

then try adding the flexbox grid loader as such: 然后尝试像这样添加flexbox网格加载器:

{test: /(\.css)$/, loaders: ['style', 'css', 'style!css?modules'], include: /flexboxgrid/}

I do hope you find this useful. 我希望您觉得这有用。

Try like this one 像这样尝试

{   test: /\.css$/,
            loader: "style-loader!css-loader",
            exclude: __dirname + './node_modules/react-flexbox-grid',
},
{
            test: /(\.scss|\.css)$/,
            loader: 'style!css?modules!sass',
            include: __dirname + './node_modules/react-flexbox-grid',
            exclude: /(node_modules)/
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM