0

我可以postcss-import用于导入 Bootstrap 吗?

这是我的 webpack 配置的一部分:

{
  test: /\.css$/,
  loaders: [
    {
      loader: 'style-loader',
    },
    {
      loader: 'css-loader',
      options: {
        importLoaders: 1,
        modules: true,
        localIdentName: '[folder]__[local]___[hash:base64:5]',
      },
    },
    {
      loader: 'postcss-loader',
    },
  ],
},

我正在尝试导入使用 npm 安装的 Bootstap:

@import 'bootstrap/dist/css/bootstrap.css';

我有一个错误:

./~/css-loader?{"importLoaders":1,"modules":true,"localIdentName":"[folder]__[local]___[hash:base64:5]"}!./~/postcss-loader/lib!./src/css/app.css
Module not found: Error: Can't resolve '../fonts/glyphicons-halflings-regular.eot' in '/home/entry/Dev/project/src/css'
@ ./~/css-loader?{"importLoaders":1,"modules":true,"localIdentName":"[folder]__[local]___[hash:base64:5]"}!./~/postcss-loader/lib!./src/css/app.css 6:4601-4653 6:4676-4728
@ ./src/css/app.css
@ ./src/js/backoffice/index.js
@ ./src/main.js
@ multi ./scripts/config/polyfills.js ./src/main.js

./~/css-loader?{"importLoaders":1,"modules":true,"localIdentName":"[folder]__[local]___[hash:base64:5]"}!./~/postcss-loader/lib!./src/css/app.css
Module not found: Error: Can't resolve '../fonts/glyphicons-halflings-regular.woff2' in '/home/entry/Dev/project/src/css'
@ ./~/css-loader?{"importLoaders":1,"modules":true,"localIdentName":"[folder]__[local]___[hash:base64:5]"}!./~/postcss-loader/lib!./src/css/app.css 6:4778-4832
@ ./src/css/app.css
@ ./src/js/backoffice/index.js
@ ./src/main.js
@ multi ./scripts/config/polyfills.js ./src/main.js

........

我也url-loader用作默认加载程序

{
    exclude: [
      /\.html$/,
      /\.js$/,
      /\.css$/,
      /\.json$/,
    ],
    loader: 'url-loader',
    options: {
      limit: 10000,
      name: 'static/media/[name].[hash:8].[ext]',
    },
  },

我正在使用webpack v.2.1.3、postcss-loader v.2.0.6、postcss-import v.11.0.0

4

1 回答 1

0

您应该添加ident: 'postcss',到您的postcss-loader配置中以使其正常工作:

{
  loader: 'postcss-loader',
  options: {
    ident: 'postcss',
  }
},

您可以阅读有关此问题的更多信息:https ://github.com/facebookincubator/create-react-app/issues/2677

于 2017-09-25T01:08:56.807 回答