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

          <bdo id='iXhOy'></bdo><ul id='iXhOy'></ul>
      1. <small id='iXhOy'></small><noframes id='iXhOy'>

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

      3. <tfoot id='iXhOy'></tfoot>

        在 gulpfile.js 中设置工作目录?

        时间:2023-05-28
            <tbody id='otcky'></tbody>
          <legend id='otcky'><style id='otcky'><dir id='otcky'><q id='otcky'></q></dir></style></legend>

              <tfoot id='otcky'></tfoot>

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

                • 本文介绍了在 gulpfile.js 中设置工作目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  有没有办法在 gulpfile 中设置 Gulp 的工作目录,这样我就可以从子目录运行 gulp 命令而不会遇到任何问题?我对此进行了搜索,但没有找到我要查找的内容.

                  Is there a way to set the working directory for Gulp within a gulpfile, so that I can run a gulp command from a subdirectory without running into any issues? I ran a search for this and didn't find what I was looking for.

                  为了澄清,我知道为我正在使用的文件添加前缀.然而,而不是这个 -

                  To clarify, I'm aware of adding a prefix to the files I'm using. However, instead of this -

                  var gulp = require('gulp');
                  var jshint = require('gulp-jshint');
                  ...
                  
                  var paths = {
                      js: [__dirname + 'app/*/*.js', __dirname + '!app/lib/**'],
                      css: __dirname + 'app/*/*.styl',
                      img: __dirname + 'app/img/*',
                      index: __dirname + '*.html',
                      dist: __dirname + 'dist'
                  };
                  

                  我想做这样的事情:

                  var gulp = require('gulp');
                  var jshint = require('gulp-jshint');
                  ...
                  
                  gulp.cwd(__dirname); // This would be much easier to understand, and would make future edits a bit safer.
                  
                  var paths = {
                      js: ['app/*/*.js', '!app/lib/**'],
                      css: 'app/*/*.styl',
                      img: 'app/img/*',
                      index: '*.html',
                      dist: 'dist'
                  };
                  

                  我想知道 Gulp 是否公开了这个功能.也许节点本身允许这样做.

                  I'm wondering if Gulp exposes this functionality. Perhaps node itself allows this.

                  (我意识到当我运行命令时可能有一种方法可以自己执行命令行,但我想将它包含在 gulp 文件中,特别是出于分发目的.我希望 gulp 的工作目录与gulpfile 所在的目录.)

                  (I realize that there is likely a way to do command line itself when I run the command, but I would like to include it in the gulp file, especially for distribution purposes. I want the working directory for gulp to match the directory in which the gulpfile resides.)

                  谢谢!

                  推荐答案

                  你应该使用 path.join 因为它会处理正确的斜线,并且按照该路径您可以添加一个快捷方式:

                  Instead of concatenating strings by yourself, you should be using path.join since it will take care of the proper slash, and following that path you can add a shorcut:

                  var path = require('path'),
                      p    = function () {
                  
                      Array
                          .prototype
                          .unshift
                          .call(arguments, __dirname);
                  
                      return path.join.apply(path, arguments);
                  };
                  
                  console.log(p('a', 'b', 'c'));
                  

                  或者,你可以:

                  gulp.src(..., {cwd: __dirname})
                  gulp.dest(..., {cwd: __dirname})
                  

                  类似:

                  var src = function (globs, options) {
                  
                      options = options || {};
                      options.cwd = __dirname;
                  
                      return gulp.src(globs, options);
                  };
                  
                  var dest = function (folder, options) {
                  
                      options = options || {};
                      options.cwd = __dirname;
                  
                      return gulp.dest(folder, options);
                  };
                  

                  看这里和这里.

                  这篇关于在 gulpfile.js 中设置工作目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 nodejs gulp 在 Less 中导入 .css 文件 下一篇:使用 TypeScript 和 Babel 的 Gulp 源图

                  相关文章

                  最新文章

                  <tfoot id='bMr8X'></tfoot>
                    • <bdo id='bMr8X'></bdo><ul id='bMr8X'></ul>

                  1. <small id='bMr8X'></small><noframes id='bMr8X'>

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

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