css - 无法使用 grunt 编译 Bootstrap css

标签 css twitter-bootstrap gruntjs less

网上有很多这方面的教程,但经过两天的努力 - 我必须得到一些帮助。 我正在尝试向 Bootstrap 添加命名空间,以便我可以在 Salesforce 中使用它而不会干扰 Salesforce 的样式表。 我的目标是用 .bs{} 包装 bootstrap.less,这样我就可以在我的页面上将其作为资源引用。 似乎无论如何,bootstrap.css 都没有编译。

Bootstrap Test v2
├───bootstrap-3.3.7
    ├───Gruntfile.js
    |───dist
    |     |───css
    |          |───bootstrap.css
    |───less
          |───bootstrap.less

重现步骤:

1)修改bootstrap.less(用.bs{}包裹内容)

2) 导航到 Bootstrap 测试 V2

3) 运行命令'grunt dist'

输出:

C:\Users\json\Desktop\Bootstrap\Bootstrap Test v2>grunt dist
(node:8444) ExperimentalWarning: The http2 module is an experimental API.
Running "clean:dist" (clean) task
>> 1 path cleaned.

Running "less:compileCore" (less) task
>> 1 stylesheet created.
>> 1 sourcemap created.

Running "less:compileTheme" (less) task
>> 1 stylesheet created.
>> 1 sourcemap created.

Running "autoprefixer:core" (autoprefixer) task
>> 1 autoprefixed stylesheet created.
>> 1 sourcemap created.

Running "autoprefixer:theme" (autoprefixer) task
>> 1 autoprefixed stylesheet created.
>> 1 sourcemap created.

Running "csscomb:dist" (csscomb) task
>> Using custom config file "less/.csscomb.json"...
>> Sorting file "dist/css/bootstrap-theme.css"...
>> Sorting file "dist/css/bootstrap.css"...

Running "cssmin:minifyCore" (cssmin) task
>> 1 sourcemap created.
>> 1 file created. 146.01 kB → 121.2 kB

Running "cssmin:minifyTheme" (cssmin) task
>> 1 sourcemap created.
>> 1 file created. 26.13 kB → 23.41 kB

Running "copy:fonts" (copy) task
Created 1 directory, copied 5 files

Running "concat:bootstrap" (concat) task

Running "uglify:core" (uglify) task
File dist/js/bootstrap.min.js created: 69.71 kB → 37.05 kB
>> 1 file created.

Running "commonjs" task
File dist/js/npm.js created.

Done.


Execution Time (2018-05-23 23:58:31 UTC+3)
clean:dist           77ms  █ 2%
less:compileCore    994ms  ███████████ 25%
less:compileTheme   146ms  ██ 4%
autoprefixer:core   538ms  ██████ 14%
autoprefixer:theme   90ms  █ 2%
csscomb:dist         1.1s  ████████████ 28%
cssmin:minifyCore   421ms  █████ 11%
cssmin:minifyTheme   53ms  █ 1%
copy:fonts           48ms  █ 1%
uglify:core         427ms  █████ 11%
Total 3.9s

咕噜文件:

module.exports = function(grunt) {
  require('jit-grunt')(grunt);

  grunt.initConfig({
    less: {
      development: {
        options: {
          compress: true,
          yuicompress: true,
          optimization: 2
        },
        files: {
          "dist/css/bootstraptest.css": "less/bootstrap.less" // destination file and source file
        }
      }
    },
    watch: {
      styles: {
        files: ['less/**/*.less'], // which files to watch
        tasks: ['less'],
        options: {
          nospawn: true
        }
      }
    }
  });

  grunt.registerTask('default', ['less', 'watch']);
};

     module.exports = function(grunt) {
         grunt.initConfig({

             less: {
                 development: {
                     options: {
                         paths: ["assets/css"]
                     },
                     files: {"dist/css/bootstrap.css": "less/bootstrap.less"}
                 },
                 production: {
                     options: {
                         paths: ["assets/css"],
                         cleancss: true
                     },
                     files: {"dist/css/bootstrap.css": "less/bootstrap.less"}
                 }
             }
         });
         grunt.loadNpmTasks('grunt-contrib-less');
         grunt.registerTask('default', ['less']);
     };

注意事项: 1) 使用“grunt”命令对我不起作用,它会抛出错误“运行“jekyll:docs”(jekyll)任务”并建议下载我已经安装的 jekyll。我在网上读到“grunt dist”应该足够了 - 它正确吗?

最佳答案

使用“node js 命令行”而不是常规命令行对我有用。

Windows:开始 > Node.js 命令提示符

我遵循了 this 中的步骤文章,它终于奏效了。

关于css - 无法使用 grunt 编译 Bootstrap css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50497476/

相关文章:

css - 表格中的标签/输入固定流体布局

css - Bootstrap 没有垂直间隙

javascript - Bootstrap 4 可折叠卡片 - 断断续续的动画

gruntjs - 列出 grunt.js 任务

javascript - 使用一个文件集成整个 Yeoman、AngularJS 项目

javascript - Css 文本动画问题

html - Bootstrap 3 轮播不工作

css - 无法找到一种方法来自动化/咕噜 CSS Sprite 创建,支持 PNG 源文件的悬停效果

css - 居中对齐 Bootstrap 中的导航栏内容

javascript - Bootstrap 工具提示不考虑数据放置参数