webpack - 使用 webpack 导入外部 bootstrap-sass 库时出错

标签 webpack bootstrap-sass webpack-style-loader

我正在使用 React、Webpack 和 Bootstrap-Sass 创建客户端应用程序。我正在尝试导入外部 Bootstrap-sass 库,但在终端中不断收到以下错误:

 "File to import not found or unreadable: bootstrap-sass/assets/stylesheets/bootstrap/variables"

我的 webpack.config.js 中的 scss 加载器似乎无法正确读取 bootstrap-sass 中的变量文件;但是,我尝试使用/创建几个不同的 scss 加载器,但它们都无法解决此问题。

这是我的 webpack.config.js 文件:

 var StaticSiteGeneratorPlugin = require('static-site-generator-    webpack-plugin');
 var data = require('./data');
 var path = require('path');


 module.exports = {
     entry: './entry.jsx',

output: {
    filename: 'bundle.js',
    path:  __dirname,
    libraryTarget: 'umd'
},

module: {
    loaders: [
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader' },
{ test: /\.jsx$/, exclude: /node_modules/, loader: 'babel-loader' },
{ test: /\.css$/, loaders: [ 'css' ] },
{ test: /bootstrap-sass\/assets\/javascripts\//, loader: 'imports?jQuery=jquery' },
{ test: /\.scss$/, loader: "css!sass?includePaths[]=" + 
    path.resolve(__dirname, "./bower_components/bootstrap-sass/assets/stylesheets/")},
{ test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/font-woff" },
{ test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/font-woff" },
{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/octet-stream" },
{ test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file" },
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=image/svg+xml" }
    ]
},

   plugins: [
 new StaticSiteGeneratorPlugin('bundle.js', data.routes, data)
   ],
 }

base.scss 文件:

 // include bootstrap stylesheets
 $icon-font-path: "../node_modules/bootstrap-   sass/assets/fonts/bootstrap/";  
 @import "../node_modules/bootstrap-   sass/assets/stylesheets/_bootstrap.scss";
 @import "../node_modules/bootstrap-sass/assets/stylesheets/_bootstrap-compass.scss";
 @import "../node_modules/bootstrap-sass/assets/stylesheets/bootstrap/_variables.scss";
 @import"index.scss";

 // include omni stylesheets
 @import "../bower_components/omni-bootstrap/assets/stylesheets/omni";

非常感谢任何帮助或建议!

最佳答案

更改以下行:

@import "../bower_components/omni-bootstrap/assets/stylesheets/omni";

至:

@import "../../bower_components/omni-bootstrap/assets/stylesheets/omni";

关于webpack - 使用 webpack 导入外部 bootstrap-sass 库时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34302888/

相关文章:

ruby-on-rails - rails bootstrap-sass Assets 编译错误 - undefined variable 警报填充

webpack - 为什么我无法使用 Webpack 编译 SASS?

html - Webpack:使用组件特定的 css 在 html 中呈现不同?

webpack - 我可以在 webpack 4 中使用模式为 ="staging"的 NODE_ENV ="production"吗?

javascript - Aurelia JS webpack 骨架相对资源路径

css - Bootstrap-Sass:使用另一个变量覆盖变量

css - 将 bootstrap 主题导入 ruby​​ on rails 应用程序时出现问题

javascript - 为什么我的产品包中包含 style-loader?

Angular 4 : "Cannot find name ' require'

webpack - 如何使用 webpack 5 处理 SharedWorker 代码升级?