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

时间:2015-05-12 11:17:18

标签: gruntjs visual-studio-2015

我试图在我的ASP项目中使用grunt,但无论出于何种原因,都会从Visual Studio中获得一条愚蠢的警告消息。 如何看清楚,凉亭任务已被执行,但是没有任务和更少的任务。 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");




1 个答案:

答案 0 :(得分:3)

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

较少的步骤似乎是正确的,但它找不到您尝试编译的文件较少。你确定site.less存在于less文件夹中吗?

这是我刚刚编写的grunt文件的较少部分,并且它似乎运行良好,虽然获取源图实际生成仍然是一个问题。这几乎完全等同于安装了Web Essentials的VS 2013。使用我们支持的浏览器的autoprefix编译内容文件夹中的所有较少文件,并将.css放回内容文件夹。它不会编译任何以_开头的文件,因为它们只是包含/变量。

    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'
            }]
        }
    },