久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  1. <tfoot id='3KoUs'></tfoot>
    1. <i id='3KoUs'><tr id='3KoUs'><dt id='3KoUs'><q id='3KoUs'><span id='3KoUs'><b id='3KoUs'><form id='3KoUs'><ins id='3KoUs'></ins><ul id='3KoUs'></ul><sub id='3KoUs'></sub></form><legend id='3KoUs'></legend><bdo id='3KoUs'><pre id='3KoUs'><center id='3KoUs'></center></pre></bdo></b><th id='3KoUs'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='3KoUs'><tfoot id='3KoUs'></tfoot><dl id='3KoUs'><fieldset id='3KoUs'></fieldset></dl></div>
      • <bdo id='3KoUs'></bdo><ul id='3KoUs'></ul>
      <legend id='3KoUs'><style id='3KoUs'><dir id='3KoUs'><q id='3KoUs'></q></dir></style></legend>

      <small id='3KoUs'></small><noframes id='3KoUs'>

      使用 Gulp 編譯 JavaScript 并解決依賴關系(單獨的文

      Compile JavaScripts with Gulp and Resolve Dependencies (separate files)(使用 Gulp 編譯 JavaScript 并解決依賴關系(單獨的文件))
        <tbody id='phzhi'></tbody>

    2. <tfoot id='phzhi'></tfoot>
      <legend id='phzhi'><style id='phzhi'><dir id='phzhi'><q id='phzhi'></q></dir></style></legend>

          <bdo id='phzhi'></bdo><ul id='phzhi'></ul>
        • <small id='phzhi'></small><noframes id='phzhi'>

          1. <i id='phzhi'><tr id='phzhi'><dt id='phzhi'><q id='phzhi'><span id='phzhi'><b id='phzhi'><form id='phzhi'><ins id='phzhi'></ins><ul id='phzhi'></ul><sub id='phzhi'></sub></form><legend id='phzhi'></legend><bdo id='phzhi'><pre id='phzhi'><center id='phzhi'></center></pre></bdo></b><th id='phzhi'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='phzhi'><tfoot id='phzhi'></tfoot><dl id='phzhi'><fieldset id='phzhi'></fieldset></dl></div>
              1. 本文介紹了使用 Gulp 編譯 JavaScript 并解決依賴關系(單獨的文件)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                我想用 Gulp 編譯 JavaScript 文件.

                I want to compile JavaScript files with Gulp.

                我有一個 src 目錄,其中所有腳本都帶有 .js 擴展名.我希望將所有腳本單獨編譯并放置到與原始文件名相同的目標目錄(dist)中.

                I have a src directory where all scripts are present with .js extension. I want all scripts to be compiled separately and placed into a destination directory (dist) with the same filename as the original.

                考慮這個例子:

                src/jquery.js:

                /**
                 * @require ../../vendor/jquery/dist/jquery.js
                 */
                

                src/application.js:

                /**
                 * @require ../../vendor/angular/angular.js
                 * @require ../../vendor/ngprogress-lite/ngprogress-lite.js
                 * @require ../../vendor/restangular/dist/restangular.js
                 * @require ../../vendor/lodash/dist/lodash.underscore.js
                 * @require ../../vendor/angular-input-locker/dist/angular-input-locker.js
                 * @require ../../vendor/angular-route/angular-route.js
                 */
                
                (function(document, angular) {
                
                    'use strict';
                
                    var moduleName = 'waApp';
                
                    angular.module(moduleName, [
                        // Some more code here.
                    ;
                
                    // Bootstrapping application when DOM is ready.
                    angular.element(document).ready(function() {
                        angular.bootstrap(document, [moduleName]);
                    });
                
                })(document, angular);
                

                我正在使用 gulp-resolve-dependencies 來解決在每個源 JavaScript 文件的標頭.

                I'm using gulp-resolve-dependencies to resolve dependencies specified in the header of each source JavaScript file.

                我的 gulpfile.js 看起來像這樣:

                My gulpfile.js is looking like this:

                //==============//
                // Dependencies //
                //==============//
                
                var gulp = require('gulp');
                var pathModule = require('path');
                var resolveDependencies = require('gulp-resolve-dependencies');
                var concat = require('gulp-concat');
                var uglify = require('gulp-uglify');
                
                //=======//
                // TASKS //
                //=======//
                
                gulp.task('build:scripts', function(callback) {
                
                    return gulp.src('scripts/*.js')
                        .pipe(resolveDependencies({
                            pattern: /* @require [s-]*(.*?.js)/g,
                            log: true
                        }))
                        .pipe(concat('all.js'))
                        .pipe(uglify())
                        .pipe(gulp.dest('js/'))
                    ;
                });
                

                為了合并由 resolveDependencies 解析的腳本,我必須使用 concat,但 concat 需要一個文件名并且不僅合并原始文件和為它解析了依賴項,但所有 JavaScript 文件都是通過 glob 模式指定的.

                In order to merge scripts resolved by resolveDependencies I have to use concat, but concat requires a filename and merges not only original file and dependencies resolved for it, but all JavaScript files specified via glob pattern.

                那么,如何獲取單個 JavaScript 文件作為輸出? 像這樣:

                dist/jquery.js:
                    src/jquery.js
                    vendor/jquery.js
                
                dist/application.js:
                    src/application.js
                    vendor/angular.js
                    vendor/ngprogress-lite.js
                    ...
                

                我現在有這個解決方法:

                I have this workaround for now:

                gulp.task('build:scripts', function(callback) {
                
                    var compileScript = function(stream, filename) {
                        return stream
                            .pipe(resolveDependencies({
                                pattern: /* @require [s-]*(.*?.js)/g,
                                log: true
                            }))
                            .pipe(concat(filename))
                            .pipe(uglify())
                            .pipe(gulp.dest('dist/'))
                        ;
                    };
                
                    var scripts = getListOfFiles('src/', 'js');
                    for (key in scripts) {
                        var filename = scripts[key];
                        var stream = gulp.src(pathModule.join('src/', filename));
                        compileScript(stream, filename);
                    }
                
                    callback(null);
                });
                
                //===================//
                // FUNCTIONS & UTILS //
                //===================//
                
                /**
                 * Returns list of files in the specified directory
                 * with the specified extension.
                 *
                 * @param {string} path
                 * @param {string} extension
                 * @returns {string[]}
                 */
                function getListOfFiles(path, extension) {
                
                    var list = [];
                    var files = fs.readdirSync(path);
                    var pattern = new RegExp('.' + extension + '$');
                
                    for (var key in files) {
                        var filename = files[key];
                        if (filename.match(pattern)) {
                            list.push(filename);
                        }
                    }
                
                    return list;
                }
                

                但它看起來很老套,我找不到一個很好的方法讓它與 gulp-觀看.

                But it looks hackish and I can't find a good way to make it work with gulp-watch.

                有沒有更好更簡單的方法來解決這個問題并達到預期的效果?

                Is there a better and simpler way to solve this problem and achieve desired result?

                推薦答案

                如何獲取單個 JavaScript 文件作為輸出?

                How do I get individual JavaScript files as the output?

                在這里查看我對類似問題的回答:將隨機值傳遞給 gulp 管道模板

                Check an answer I gave to a similar problem here: Pass random value to gulp pipe template

                使用這個 gulp 插件:https://github.com/adam-lynch/球形到乙烯基

                Using this gulp plugin: https://github.com/adam-lynch/glob-to-vinyl

                您可以訪問單個文件.

                這是怎么做的(假設使用這個插件):

                This is how (assuming the use of this plugin):

                function compileScript(file) {
                  gulp
                    .src('file')
                    .pipe(resolveDependencies({
                      pattern: /* @require [s-]*(.*?.js)/g,
                      log: true
                    }))
                    .pipe(concat())
                    .pipe(uglify())
                    .pipe(gulp.dest('dist/'))
                  ;
                };
                
                gulp.task('build:scripts', function() {
                  globToVinyl('src/**/*.js', function(err, files){
                    for (var file in files) {
                      compileScript(files[file].path);
                    }
                  });
                });
                

                這篇關于使用 Gulp 編譯 JavaScript 并解決依賴關系(單獨的文件)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Browserify, Babel 6, Gulp - Unexpected token on spread operator(Browserify,Babel 6,Gulp - 傳播運算符上的意外令牌)
                Is it possible to pass a flag to Gulp to have it run tasks in different ways?(是否可以將標志傳遞給 Gulp 以使其以不同的方式運行任務?)
                Why do we need to install gulp globally and locally?(為什么我們需要在全局和本地安裝 gulp?)
                How to run Gulp tasks sequentially one after the other(如何一個接一個地依次運行 Gulp 任務)
                Visual Studio 2015 crashes when opening Javascript files(打開 Javascript 文件時 Visual Studio 2015 崩潰)
                Detect FLASH plugin crashes(檢測 FLASH 插件崩潰)

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

                <small id='1qa6s'></small><noframes id='1qa6s'>

                  <legend id='1qa6s'><style id='1qa6s'><dir id='1qa6s'><q id='1qa6s'></q></dir></style></legend>

                      <tbody id='1qa6s'></tbody>
                      <bdo id='1qa6s'></bdo><ul id='1qa6s'></ul>
                        • 主站蜘蛛池模板: 成人a视频片观看免费 | 久久久久一区 | 日韩毛片免费看 | 亚洲精品电影 | 欧美日韩中文国产一区发布 | 日韩视频区 | 亚洲成人一区二区 | 成人影院在线 | 久久国产亚洲 | 宅男伊人 | 亚洲综合视频 | 一级毛片色一级 | 日本在线免费视频 | 久草.com| 中文字幕国产精品 | av中文字幕在线播放 | 五月天婷婷狠狠 | www.xxxx欧美 | 日韩中文电影 | 插插插干干干 | 亚洲一区二区三区久久久 | 性一交一乱一伦视频免费观看 | 精品成人av | 久久久久国产 | 亚洲网站观看 | 国产精品成人一区二区三区夜夜夜 | 国产午夜精品视频 | 91精品国产91久久综合桃花 | 日韩欧美中文字幕在线视频 | 新av在线| 亚洲精品免费在线观看 | 日本羞羞影院 | 黄视频免费在线 | 日韩三级在线观看 | 高清一区二区 | 亚洲a视频 | 成人影院免费视频 | 精品国产一区二区三区久久久蜜月 | 嫩草懂你的影院入口 | 在线观看国产h | 在线视频中文字幕 |