【问题标题】:How to override Bootstrap variables in Vue workflow ( Vanilla Bootstrap )?如何在 Vue 工作流程(Vanilla Bootstrap)中覆盖 Bootstrap 变量?
【发布时间】:2019-02-22 14:53:38
【问题描述】:

官方推荐的自定义/主题引导的方法是使用 sass 覆盖引导变量。但是我该怎么做,或者更确切地说,如何将这部分流程添加到 Vue webpack 工作流程中?

谷歌搜索导致尝试编辑 vue.config.js 文件以将 scss 加载程序添加到 webpack 中,但我找不到所需的文件。

This is the directory structure

我已经使用 vue-cli v3.4 来设置项目。

我使用的是 vanilla bootstrap,而不是 bootstrap-vue 组件。

【问题讨论】:

  • 我认为这可以帮助您入门。看起来@Ohgodwhy 的回答与此一致。 getbootstrap.com/docs/4.0/getting-started/theming/…
  • 是的,我已经阅读了引导文档的这一部分,但我想将其包含在我的 vue 项目中,我需要为此配置 webpack。这就是我要找的

标签: javascript vue.js webpack


【解决方案1】:

创建一个名为custom.scss 的文件。进入node_modules/bootstrap/scss 目录并从_variables.scss 复制所有内容。将这些粘贴到您的custom.scss。

在您的style.scss 中导入您的custom.scss,然后再导入bootstrap.scss。

现在在你的main.js 中导入@/assets/style.scss。

您需要从您希望在custom.scss 中覆盖的任何变量中删除!default 标志,以使它们也生效。

【讨论】:

  • 但问题是我需要配置 webpack 来设置 scss 加载器和编译器。不知道在哪里可以找到放置这些配置设置的文件。
  • @KaustabhKakoty 不,你没有。你说你使用vue-cli,没有必要用我的方法添加那个加载器。 vue-cli 默认为您包含此加载程序。还有很多很多。运行vue-cli-serve inspect,你会看到这个。
  • 是的,这种方法有效。刚刚将 sass 加载器添加到开发依赖项中,并按照答案中的方法进行操作。完美运行。非常感谢。
【解决方案2】:

创建一个文件/css/bootstrap-custom.scss,内容如下:

// your variable overrides
// modify theme colors map
$theme-colors: (
    "primary":#42b883,
    //...other variables, you can find them in node_modules/bootstrap/scss/_variables.scss
);

// import to set changes
@import "~bootstrap/scss/bootstrap";

在main 脚本中,导入添加的文件,而不是当前导入的引导 css 文件:

// import '../node_modules/bootstrap/dist/css/bootstrap.css';
import '@/css/bootstrap-custom.scss'; 

参考:Bootstrap, Variable defaults

【讨论】:

    猜你喜欢
    • 2013-12-24
    • 2015-09-28
    • 2019-07-17
    • 2019-01-25
    • 2020-06-14
    • 2020-07-15
    • 2018-06-06
    • 2016-04-18
    • 1970-01-01
    相关资源
    最近更新 更多