webpack 2.7不会加载blueprintjs核心css

时间:2017-12-10 18:42:57

标签: css reactjs webpack-2 blueprintjs

我正在尝试使用blueprintjs,当我导入其CSS时。我认为我在webpack配置中出错了所以我看到了这个错误enter image description here

有我的webpack配置

const ExtractTextPlugin = require('extract-text-webpack-plugin');
var webpack = require("webpack");
var path = require("path");

module.exports={
    entry: './src/index.js',
    output:{
        path: __dirname + "/public",
        filename:'bundle.js',
        publicPath: "/public/"
    },
    devServer: {
        inline: true,
        contentBase: './public',
        port: 3000
    },
    module:{
        rules: [
            {
            test: /\.js$/,
            exclude: /(node_modules)/,
            loader: "babel-loader",
            query: {
                presets: ['es2015', 'react', 'stage-0'],

            }
        }, 
        {
             test: /\.s(a|c)ss$/, 
                loader: ExtractTextPlugin.extract({loader: ['css-loader', 'sass-loader', 'style-loader']})
              },
              {
                test: /\.css$/,
                use: [
                  {
                    loader: 'style-loader',
                  },
                  {
                    loader: 'css-loader',
                  },
                ],
              },
              {
                test: /\.(|gif||svg|woff|woff2|eot|ttf)(\?v=[0-9]\.[0-9]\.[0-9])?$/, 
                loader: 'file-loader', options: {name: '[name].[ext]'}
              },  {
                test: /\.(png|jpg|)$/,
                loader: 'url-loader?limit=200000'
              },
        ] 
    },
    plugins: [
        new ExtractTextPlugin("styles.css"),
      ]

}

我正在使用“webpack”:“^ 2.7.0”,“@ blueprintjs / core”:“^ 1.34.1”和许多装载程序

我试图像这样导入我的CSS

require('!css-loader!./index.css');

就像这样

import styles from './index.css'

结果是相同的

经过额外几个小时的工作后,我收到了这个错误

enter image description here 在这一点上,我不确定我的webpack有什么问题,以及如何解决它 欢迎任何建议

2 个答案:

答案 0 :(得分:0)

您可以将您的webpack配置与Blueprint monorepo中的配置进行比较:https://github.com/palantir/blueprint/tree/develop/packages/webpack-build-scripts

尝试按照基本配置中的相同顺序应用加载器:java.lang.IllegalStateException: Failed to load ApplicationContext Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '...repository.OrderRepository#0': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [...repository.OrderRepository]: Specified class is an interface ...

答案 1 :(得分:0)

尝试使用NPM包中blueprint.css的完整路径。屏幕截图中的webpack错误清楚地显示了css-loader尝试加载esm/index.js这个JS文件,当然它失败了。

尝试:@import "~@blueprintjs/core/lib/css/blueprint.css";