在webpack中缺少svg的上下文

我的webpack配置

module:{
    rules:[{
        loader: 'babel-loader',
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        test: /\.jsx?$/,
        exclude: /node_modules/,
    }, {
        test: /\.s?css$/,
        use: [
            'style-loader',
            'css-loader',
            'sass-loader'
        ],
    }, { 
        test: /\.(png|woff|woff2|eot|ttf|svg)$/, 
        loader: 'url-loader?limit=100000' 
    }]
}

我有这个错误 .

./node_modules/bootstrap/dist/fonts/glyphicons-halflings-regular.svg中的错误 . 模块构建失败(来自./node_modules/url-loader/index.js):TypeError:无法在Object处读取未定义的属性“context” Object.module.exports上的.loader(G:\ SCM-New \ pms-front-end-new \ node_modules \ file-loader \ dist \ index.js:34:49)(G:\ SCM-New \ pms- front-end-new \ node_modules \ url-loader \ index.js:37:25)@ ./node_modules/bootstrap/dist/css/bootstrap.min.css(./node_modules/css-loader!./node_modules/sass -loader / lib / loader.js!./ node_modules / bootstrap / dist / css / bootstrap.min.css)7:4746-4798

我甚至尝试使用 file-loader 而不是 url-loader 但是这将为 eot|ttf|woff|woff2 带来更多错误 .

配置如下

{test: /\.(eot|svg|ttf|woff|woff2)$/, loader: 'file-loader'}

回答(0)