<i id='J0IME'><tr id='J0IME'><dt id='J0IME'><q id='J0IME'><span id='J0IME'><b id='J0IME'><form id='J0IME'><ins id='J0IME'></ins><ul id='J0IME'></ul><sub id='J0IME'></sub></form><legend id='J0IME'></legend><bdo id='J0IME'><pre id='J0IME'><center id='J0IME'></center></pre></bdo></b><th id='J0IME'></th></span></q></dt></tr></i><div id='J0IME'><tfoot id='J0IME'></tfoot><dl id='J0IME'><fieldset id='J0IME'></fieldset></dl></div>

    <tfoot id='J0IME'></tfoot>
      <bdo id='J0IME'></bdo><ul id='J0IME'></ul>

  • <legend id='J0IME'><style id='J0IME'><dir id='J0IME'><q id='J0IME'></q></dir></style></legend>
    1. <small id='J0IME'></small><noframes id='J0IME'>

        Gulp less 未正确处理包含未定义的包含变量

        时间:2023-05-29

          <tbody id='t9qRC'></tbody>

          <legend id='t9qRC'><style id='t9qRC'><dir id='t9qRC'><q id='t9qRC'></q></dir></style></legend>
          • <i id='t9qRC'><tr id='t9qRC'><dt id='t9qRC'><q id='t9qRC'><span id='t9qRC'><b id='t9qRC'><form id='t9qRC'><ins id='t9qRC'></ins><ul id='t9qRC'></ul><sub id='t9qRC'></sub></form><legend id='t9qRC'></legend><bdo id='t9qRC'><pre id='t9qRC'><center id='t9qRC'></center></pre></bdo></b><th id='t9qRC'></th></span></q></dt></tr></i><div id='t9qRC'><tfoot id='t9qRC'></tfoot><dl id='t9qRC'><fieldset id='t9qRC'></fieldset></dl></div>

              <tfoot id='t9qRC'></tfoot>

                <small id='t9qRC'></small><noframes id='t9qRC'>

                  <bdo id='t9qRC'></bdo><ul id='t9qRC'></ul>
                  本文介绍了Gulp less 未正确处理包含未定义的包含变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在使用 less 和 Grunt,并且正在转向 gulp.

                  I am using less and Grunt, and am moving to gulp.

                  我的少工作.当我跑步时:

                  My less works. When I run:

                  lessc public/less/myapp.less
                  

                  我得到了没有错误的工作输出.我所有的 less,包括 include,都是 public/less,顺便说一句.这是我的 gulpfile:

                  I get working output with no errors. All my less, including includes, is in public/less, BTW. Here is my gulpfile:

                  var gulp = require('gulp');
                  var prefixer = require('gulp-autoprefixer');
                  var less = require('gulp-less');
                  
                  gulp.task('compileLess', function () {
                    gulp
                      .src('./public/less/*')
                      .pipe(less({
                        paths: ['./public/less'], // Search paths for imports
                        filename: 'myapp.less'
                      }))
                      .pipe(gulp.dest('./public/css'));
                  });
                  
                  // The default task (called when you run `gulp`)
                  gulp.task('default', function() {
                    gulp.run('compileLess');
                  
                    // Watch files and run tasks if they change
                    gulp.watch('./public/less/*.less', function(event) {
                      gulp.run('less');
                    });
                  });
                  

                  当我运行 gulp 时,我得到:

                  When I run gulp, I get:

                  ~/Documents/myapp: gulp
                  [gulp] Using file /Users/me/Documents/myapp/gulpfile.js
                  [gulp] Working directory changed to /Users/me/Documents/myapp
                  [gulp] Running 'default'...
                  [gulp] Running 'compileLess'...
                  [gulp] Finished 'compileLess' in 11 ms
                  [gulp] Finished 'default' in 41 ms
                  
                  stream.js:94
                        throw er; // Unhandled stream error in pipe.
                              ^
                  Error: variable @brightblue is undefined
                  

                  @brightblue 在 myapp.less 开始处导入的文件中定义.

                  @brightblue is defined, in a file imported at the start of myapp.less.

                  @import "./colors.less";
                  body {
                    background-color: @brightblue;
                  }
                  

                  • 为什么 gulp 不接收我的包含?为 less 指定 'paths' 选项应该可以让它工作,但它并没有修复它.
                  • 有什么好的调试方法?例如,我没有行号.
                  • 有没有办法让 gulp 工作?
                  • 推荐答案

                    不同之处在于 我正在编译:

                    The difference was what I was compiling:

                    • 当我运行 lessc myapp.less 时,我正在编译主 less 文件及其依赖项
                    • 当我使用上面的 gulpfile 运行 gulp 时,我正在单独编译每个 less 文件,因为 gulp.src 是 *.less 而不是 myapp.less.由于这些 less 文件仅从主 less 文件加载,因此它们没有 @imports 用于它们所依赖的东西(因为 myapp.less 依赖于它们).例如,在每个单独的文件中导入theme.less"而不是先在 myapp.less 中导入它是没有意义的.
                    • When I ran lessc myapp.less, I was compiling the main less file and it's dependencies
                    • When I ran gulp using the gulpfile above, I was compiling each less file individually, because gulp.src was *.less not myapp.less. Since these less files are only ever loaded from the main less file, they didn't have @imports for the things they depend on (because myapp.less depends on them). Eg, there's no point importing, say, 'theme.less' in every individual file rather than just importing it first in myapp.less.

                    这是工作版本:

                    // Run 'gulp' to do the important stuff
                    var gulp = require('gulp');
                    var prefixer = require('gulp-autoprefixer');
                    var less = require('gulp-less');
                    var path = require('path');
                    
                    gulp.task('less', function () {
                      gulp
                        .src('./public/less/myapp.less') // This was the line that needed fixing
                        .pipe(less({
                          paths: ['public/less']
                        }))
                        .pipe(prefixer('last 2 versions', 'ie 9'))
                        .pipe(gulp.dest('./public/css'));
                    });
                    
                    // The default task (called when you run `gulp`)
                    gulp.task('default', function() {
                      gulp.run('less');
                    
                      // Watch files and run tasks if they change
                      gulp.watch('./public/less/*.less', function(event) {
                        gulp.run('less');
                      });
                    });
                    

                    请参阅下面的@noducks 回答,了解适用于最新 gulp 的改进版本.

                    see @noducks answer below for an improved version that works with the latest gulp.

                    这篇关于Gulp less 未正确处理包含未定义的包含变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                      <legend id='cwd7e'><style id='cwd7e'><dir id='cwd7e'><q id='cwd7e'></q></dir></style></legend>

                      <small id='cwd7e'></small><noframes id='cwd7e'>

                        <bdo id='cwd7e'></bdo><ul id='cwd7e'></ul>
                          <tbody id='cwd7e'></tbody>

                          <tfoot id='cwd7e'></tfoot>
                        1. <i id='cwd7e'><tr id='cwd7e'><dt id='cwd7e'><q id='cwd7e'><span id='cwd7e'><b id='cwd7e'><form id='cwd7e'><ins id='cwd7e'></ins><ul id='cwd7e'></ul><sub id='cwd7e'></sub></form><legend id='cwd7e'></legend><bdo id='cwd7e'><pre id='cwd7e'><center id='cwd7e'></center></pre></bdo></b><th id='cwd7e'></th></span></q></dt></tr></i><div id='cwd7e'><tfoot id='cwd7e'></tfoot><dl id='cwd7e'><fieldset id='cwd7e'></fieldset></dl></div>