Visual Studio 2015:目标 wwwroot/css/site.css 未写入,因为未找到源文件。

Visual Studio 2015: Destination wwwroot/css/site.css not written because no source files were found.

我正尝试在我的 ASP 项目中使用 grunt,但出于某种原因,我从 Visual Studio 收到了一条愚蠢的警告消息。 怎么往下看,bower-task已经执行了,但是还没有uglify-和less-tasks。 Gruntfile.js 和文件夹 "wwwroot" 在同一个文件夹中。怎么了?

这是 Visual Studio 2015 年的控制台输出:

> cmd.exe /c grunt -b "c:\T\BW\src\BW" --gruntfile "c:\T\BW\src\BW\gruntfile.js" bower
Running "bower:install" (bower) task
>> Installed bower packages
>> Copied packages to c:\T\BW\src\BW\wwwroot\lib
Done, without errors.
Process terminated with code 0.
> cmd.exe /c grunt -b "c:\T\BW\src\BW" --gruntfile "c:\T\BW\src\BW\gruntfile.js" uglify_default
Running "uglify:uglify_target" (uglify) task
Process terminated with code 0.
>> Destination wwwroot/lib/angular/angular.js not written because src files were empty.
>> No files created.
Done, without errors.
> cmd.exe /c grunt -b "c:\T\BW\src\BW" --gruntfile "c:\T\BW\src\BW\gruntfile.js" less
Running "less:dev" (less) task
>> Destination wwwroot/css/site.css not written because no source files were found.
Done, without errors.
Process terminated with code 0.

这是我的gruntfile.js:

    grunt.initConfig({
        bower: {
            install: {
                options: {
                    targetDir: "wwwroot/lib",
                    layout: "byComponent",
                    cleanTargetDir: false
                }
            }
        },
        uglify: {
            uglify_target: {
                files: {
                    "wwwroot/lib/angular/angular.js":["src/angular.min.js"]
                }
            }
        },
        less: {
            dev: {
                files: {
                    "wwwroot/css/site.css": ["less/site.less"]
                },
                options: {
                    sourceMap: true,
                }
            }
        },
    });

    grunt.registerTask("default", ["bower:install"]);

    grunt.loadNpmTasks("grunt-bower-task");
    grunt.loadNpmTasks("grunt-contrib-uglify");
    grunt.loadNpmTasks("grunt-contrib-less");

你确定 "wwwroot/lib/angular/angular.js":["src/angular.min.js"] 你的丑化步骤是正确的吗? Uglify 用于缩小文件,因此看起来好像您将目标参数和源参数颠倒了。您还会收到消息 Destination wwwroot/lib/angular/angular.js not written because src files were empty.,这似乎也表明了这一点。

less步骤好像是对的,但是找不到你要编译的less文件。您确定 site.less 存在于 less 文件夹中吗?

这是我刚刚编写的 grunt 文件的较少部分,它似乎运行良好,尽管实际生成 sourcemap 仍然是一个问题。这几乎完全等同于安装了 Web Essentials 的 VS 2013。使用我们支持的浏览器的自动前缀编译内容文件夹中的所有 less 文件,并将 .css 放回内容文件夹。它不会编译任何以 _ 开头的 less 文件,因为它们只是 includes/variables.

    less: {
        development: {
            options: {
                paths: ["content"],
                compress: true,
                plugins: [
                        new (require('less-plugin-autoprefix'))({ browsers: ["IE >= 9, firefox > 10, last 2 Chrome versions, last 2 safari versions, last 2 ios versions"], map: { inline: false } })
                ]
            },
            files: [{
                expand: true,
                cwd: 'content',
                src: ['*.less', '!_*.less'],
                dest: 'content',
                ext: '.css'
            }]
        }
    },