简体   繁体   中英

How can I import imported files with postcss-import and Webpack 2?

Can I use postcss-import for importing Bootstrap?

Here is a part of my webpack config:

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

And I'm trying to import Bootstap installed with npm:

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

And I have an error:

./~/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

........

Also I'm using url-loader as default loader

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

I'm using webpack v.2.1.3, postcss-loader v.2.0.6, postcss-import v.11.0.0

You should add ident: 'postcss', to your postcss-loader config to make it works:

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

You can read more about this issue: https://github.com/facebookincubator/create-react-app/issues/2677

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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