当前位置:  开发笔记 > 编程语言 > 正文

无法使用bootstrap-sass与webpack一起工作

如何解决《无法使用bootstrap-sass与webpack一起工作》经验,为你挑选了1个好方法。

我遵循bootstrap-sass-loader页面上的instrtuctions

在我的package.json我得到了

"bootstrap-sass": "^3.3.6",
"bootstrap-sass-loader": "^1.0.9"

这是我的webpack.config.js

module.exports = {
  entry: ['./app.js'],
  output: {
    publicPath: 'http://localhost:8080/',
    filename: 'build/bundle.js'
  },
  devtool: 'eval',
  module: {
    /* used on code before it's transformed */
    preLoaders: [
      {
        test: /\.jsx?$/,
        exclude: /(node_modules)/,
        loader: 'source-map'
      }
    ],
    /* used to modify code */
    loaders: [

      {test: /bootstrap\/js\//, loader: 'imports?jQuery=jquery'},
      {test: /\.obj|\.mtl|\.html|\.dae|\.txt/, loader: "raw"},
      {test: /\.jsx?$/, exclude: /(node_modules)/, loader: 'babel'},
      {test: /\.css$/, loader: 'style-loader!css-loader'},
      {test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file"},
      {test: /\.(woff|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: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=image/svg+xml"},
      {
        test: /\.scss$/,
        /* order from bottom to top, so first sass, autoprefix, css and finally style */
        loaders: ['style', 'css', 'autoprefixer?browsers=last 3 versions', 'sass?output]
      },
      {
        test: /\.(jpe?g|png|gif|svg)$/i,
        loaders: ['url?limit=8192', 'img']
      },
      {
        test: /\.jsx?$/,
        exclude: /(node_modules)/,
        loader: 'babel'
      }
    ],
    /* used to modify generated code */
    postLoader: []
  }
};

据我所知,我只需要使用

require("bootstrap-sass-loader");

在我app.js和完成.但我不能使用任何bootstrap样式.我在这里想念的是什么?



1> cortopy..:

这不是直截了当的,但它可以工作,而不必做json.

首先在main.js/ts中导入boostrap-sass(通过npm安装)

require("bootstrap-sass");

或者,如果您使用的是ts/ES6:

import "bootstrap-sass";

然后只需在组件的样式中导入这两个样式(Angular 2中的内联或外部sass/scss文件):

@import "~bootstrap-sass/assets/stylesheets/bootstrap-sprockets"
@import "../styles/bootstrap/bootstrap"

然后,您需要有一个文件夹../styles/bootstrap,其中包含以下内容:

variables.scss:只需复制并node_modules定制/自举SASS /资产/样式表/引导/ _variables.scss

bootstrap.scss:这是主引导文件的"webpack-ified"版本:

//

  @import "variables"; //this is the key to easy customisation
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/mixins";
  @import "~bootstrap-sass/assets/stylesheets/~bootstrap-sass/assets/stylesheets/bootstrap/normalize";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/print";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/glyphicons";

  // Core CSS
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/scaffolding";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/type";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/code";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/grid";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/tables";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/forms";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/buttons";

  // Components
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/component-animations";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/dropdowns";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/button-groups";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/input-groups";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/navs";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/navbar";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/breadcrumbs";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/pagination";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/pager";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/labels";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/badges";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/jumbotron";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/thumbnails";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/alerts";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/progress-bars";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/media";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/list-group";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/panels";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/responsive-embed";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/wells";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/close";

  // Components w/ JavaScript
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/modals";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/tooltip";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/popovers";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/carousel";

  // Utility classes
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/utilities";
  @import "~bootstrap-sass/assets/stylesheets/bootstrap/responsive-utilities";

最后,webpack配置位.这可能是装载机:

{
      test: /\.(sass|scss)$/,
      loader: "file?name=[path][name].css!sass-loader"
    }

这是一种加载jquery的方法:

new webpack.ProvidePlugin({
  $: "jquery",
  jQuery: "jquery"
})

推荐阅读
手机用户2402852387
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有