【问题标题】:grunt js is not compressing all scss files in to one cssgrunt js 没有将所有 scss 文件压缩成一个 css
【发布时间】:2017-11-23 10:16:23
【问题描述】:

我是 grunt 的新手,我试图在 grunt js 的帮助下将 scss 文件编译为 css。我的项目文件夹结构如下-

public
|  |_css
|  |
|  |_sass
|    |_style.scss
|
gruntfile.js
package.json

我的 grunt 文件是。

// Load Grunt
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

// Tasks
sass: { // Begin Sass Plugin
dist: {
files: {
'public/sass/**/*.scss': 'public/css/style.css'
}
}
},

watch: { // Compile everything into one task with Watch Plugin
css: {
files: './public/sass/**/*.scss',
tasks: ['sass']
},

}
});
// Load Grunt plugins
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-watch');

// Register Grunt tasks
grunt.registerTask('default', ['watch']);
};

当我运行 grunt 命令时,我没有创建任何已编译的 css 文件。

【问题讨论】:

    标签: sass gruntjs


    【解决方案1】:

    您在 grunt-contrib-sass 任务上的语法是错误的。它应该是 'destination' : 'src'

    来自

    'public/sass/**/*.scss': 'public/css/style.css'
    

    'public/css/style.css': 'public/sass/**/*.scss'
    

    参考 - 示例 https://github.com/gruntjs/grunt-contrib-sass

    更新:

    您不应该在 _style.scss 之前添加下划线,以 _ 开头的文件不会生成到输出中。这是为了避免 sass 生成导入文件。将 _style.scss 重命名为 style.scss

    【讨论】:

    • 修改后,style.css 文件没有创建。我的日志是。 **正在运行“监视”任务等待... >> 文件“public/sass/_style.scss”已更改。运行“sass:dist”(sass)任务完成。 2017 年 6 月 22 日星期四 15:07:45 GMT+0530 (IST) 在 0.633 秒内完成 - 等待... **
    • @MAKAM :您不应该在 _style.scss 之前添加下划线,以 _ 开头的文件不会生成到输出中。这是为了避免sass生成导入文件
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-17
    • 2016-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多