【问题标题】:Incorporate custom bootstrap build into project grunt task将自定义引导构建合并到项目 grunt 任务中
【发布时间】:2023-03-26 19:15:02
【问题描述】:

我有一个这样的项目结构...

app
├── 404.html
├── coffee
│   ├── app.coffee
│   └── controllers
├── colors.json
├── components
│   ├── angular
│   ├── angular-cookies
│   ├── angular-mocks
│   ├── angular-resource
│   ├── angular-sanitize
│   ├── angular-scenario
│   ├── bootstrap
│   ├── es5-shim
│   ├── jquery
│   └── json3
├── favicon.ico
├── index.jade
├── lib
│   ├── bootstrap
│   ├── font-awesome
│   ├── jquery
│   └── slider
├── robots.txt
├── styl
│   ├── main.styl
│   └── partials
└── views
    ├── demo.jade
    └── home.jade

我正在使用 bower 安装 app/component 文件夹中的所有东西。我计划将自定义变量文件添加到引导程序并从较少的源代码构建它。在bower install 创建app/bootstrap 文件夹后,我可以轻松修改variables.less 文件,但我希望它从components 文件夹外部读取我的自定义文件,而不必修改其中的任何内容。

我如何将 bootstrap 的构建,使用由 bower 加载的自定义 variables.less 文件合并到我现有的 grunt build 任务中?

【问题讨论】:

    标签: twitter-bootstrap less gruntjs bower


    【解决方案1】:

    我花了一段时间才弄清楚 less 的变量声明和导入是如何工作的,但最后,我通过 less 导入并通过 grunt 编译来自定义构建引导程序 - 所以我的解决方案与此无关确实有 grunt,但作为 grunt 构建的一部分加入。

    我项目的main.less 文件的内容...

    // import the default bootstrap variables...
    @import "../components/bootstrap/less/variables.less";
    
    // custom variable overrides have to be loaded BEFORE bootstrap.less
    // this is useful for changing any variables that influence the way bootstrap is built
    @import "_bootstrap-variables-overrides.less";
    
    // load the main bootstrap file
    @import "../components/bootstrap/less/bootstrap.less";
    
    // components overrides have to be loaded AFTER bootstrap.less
    // this is useful for overriding bootstrap styles that are not configurable as variables
    @import "_bootstrap-components-overrides.less";
    
    // more less...
    /* ... */
    

    【讨论】:

      【解决方案2】:

      执行此操作的正确“yeoman”方法似乎是 grunt-customize-bootstrap npm 包。

      只要按照包页面的说明安装并在你的 grunt 编译过程中添加一个 grunt 任务,应该没问题!

      【讨论】:

      • 感谢这个链接,看起来很有趣。我最终通过使用less自己的@import导入更少的文件来让它工作。看我的回答...
      猜你喜欢
      • 2016-08-04
      • 2016-01-12
      • 1970-01-01
      • 2014-05-12
      • 2015-05-10
      • 1970-01-01
      • 1970-01-01
      • 2015-08-18
      • 1970-01-01
      相关资源
      最近更新 更多