pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  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="ftrxvth" 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 并解決依賴(lài)關(guān)系(單獨(dú)的文

      Compile JavaScripts with Gulp and Resolve Dependencies (separate files)(使用 Gulp 編譯 JavaScript 并解決依賴(lài)關(guān)系(單獨(dú)的文件))
        <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="5hx7tl7" id='phzhi'><tfoot id='phzhi'></tfoot><dl id='phzhi'><fieldset id='phzhi'></fieldset></dl></div>
              1. 本文介紹了使用 Gulp 編譯 JavaScript 并解決依賴(lài)關(guān)系(單獨(dú)的文件)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                問(wèn)題描述

                限時(shí)送ChatGPT賬號(hào)..

                我想用 Gulp 編譯 JavaScript 文件.

                I want to compile JavaScript files with Gulp.

                我有一個(gè) src 目錄,其中所有腳本都帶有 .js 擴(kuò)展名.我希望將所有腳本單獨(dú)編譯并放置到與原始文件名相同的目標(biāo)目錄(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.

                考慮這個(gè)例子:

                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 來(lái)解決在每個(gè)源 JavaScript 文件的標(biāo)頭.

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

                我的 gulpfile.js 看起來(lái)像這樣:

                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 需要一個(gè)文件名并且不僅合并原始文件和為它解析了依賴(lài)項(xiàng),但所有 JavaScript 文件都是通過(guò) 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.

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

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

                我現(xiàn)在有這個(gè)解決方法:

                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;
                }
                

                但它看起來(lái)很老套,我找不到一個(gè)很好的方法讓它與 gulp-觀看.

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

                有沒(méi)有更好更簡(jiǎn)單的方法來(lái)解決這個(gè)問(wèn)題并達(dá)到預(yù)期的效果?

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

                推薦答案

                如何獲取單個(gè) JavaScript 文件作為輸出?

                How do I get individual JavaScript files as the output?

                在這里查看我對(duì)類(lèi)似問(wèn)題的回答:將隨機(jī)值傳遞給 gulp 管道模板

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

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

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

                您可以訪問(wèn)單個(gè)文件.

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

                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);
                    }
                  });
                });
                

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

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

                相關(guān)文檔推薦

                Browserify, Babel 6, Gulp - Unexpected token on spread operator(Browserify,Babel 6,Gulp - 傳播運(yùn)算符上的意外令牌)
                Is it possible to pass a flag to Gulp to have it run tasks in different ways?(是否可以將標(biāo)志傳遞給 Gulp 以使其以不同的方式運(yùn)行任務(wù)?)
                Why do we need to install gulp globally and locally?(為什么我們需要在全局和本地安裝 gulp?)
                How to run Gulp tasks sequentially one after the other(如何一個(gè)接一個(gè)地依次運(yùn)行 Gulp 任務(wù))
                Visual Studio 2015 crashes when opening Javascript files(打開(kāi) Javascript 文件時(shí) Visual Studio 2015 崩潰)
                Detect FLASH plugin crashes(檢測(cè) 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="fbb7znl" 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>
                        • 主站蜘蛛池模板: 杭州代理记账多少钱-注册公司代办-公司注销流程及费用-杭州福道财务管理咨询有限公司 | 语料库-提供经典范文,文案句子,常用文书,您的写作得力助手 | 冷却塔减速机器_冷却塔皮带箱维修厂家_凉水塔风机电机更换-广东康明冷却塔厂家 | 充气膜专家-气膜馆-PTFE膜结构-ETFE膜结构-商业街膜结构-奥克金鼎 | 首页-恒温恒湿试验箱_恒温恒湿箱_高低温试验箱_高低温交变湿热试验箱_苏州正合 | 海外仓系统|国际货代系统|退货换标系统|WMS仓储系统|海豚云 | 沈阳缠绕包装机厂家直销-沈阳海鹞托盘缠绕包装机价格 | 搪瓷反应釜厂家,淄博搪瓷反应釜-淄博卓耀 | 安徽千住锡膏_安徽阿尔法锡膏锡条_安徽唯特偶锡膏_卡夫特胶水-芜湖荣亮电子科技有限公司 | 太空舱_民宿太空舱厂家_移动房屋太空舱价格-豪品建筑 | 南京欧陆电气股份有限公司-风力发电机官网 | 自恢复保险丝_贴片保险丝_力特保险丝_Littelfuse_可恢复保险丝供应商-秦晋电子 | 冷凝水循环试验箱-冷凝水试验箱-可编程高低温试验箱厂家-上海巨为(www.juweigroup.com) | 【德信自动化】点胶机_全自动点胶机_自动点胶机厂家_塑料热压机_自动螺丝机-深圳市德信自动化设备有限公司 | 短信通106短信接口验证码接口群发平台_国际短信接口验证码接口群发平台-速度网络有限公司 | 紫外线老化试验箱_uv紫外线老化试验箱价格|型号|厂家-正航仪器设备 | 东莞市海宝机械有限公司-不锈钢分选机-硅胶橡胶-生活垃圾-涡电流-静电-金属-矿石分选机 | 伶俐嫂培训学校_月嫂培训班在哪里报名学费是多少_月嫂免费政府培训中心推荐 | 食药成分检测_调料配方还原_洗涤剂化学成分分析_饲料_百检信息科技有限公司 | 工业PH计|工业ph酸度计|在线PH计价格-合肥卓尔仪器仪表有限公司 济南画室培训-美术高考培训-山东艺霖艺术培训画室 | 道达尔润滑油-食品级润滑油-道达尔导热油-合成导热油,深圳道达尔代理商合-深圳浩方正大官网 | 缓蚀除垢剂_循环水阻垢剂_反渗透锅炉阻垢剂_有机硫化物-郑州威大水处理材料有限公司 | 青岛球场围网,青岛车间隔离网,青岛机器人围栏,青岛水源地围网,青岛围网,青岛隔离栅-青岛晟腾金属制品有限公司 | 招商帮-一站式网络营销服务|互联网整合营销|网络推广代运营|信息流推广|招商帮企业招商好帮手|搜索营销推广|短视视频营销推广 | 地源热泵一体机,地源热泵厂家-淄博汇能环保设备有限公司 | 400电话_400电话申请_866元/年_【400电话官方业务办理】-俏号网 3dmax渲染-效果图渲染-影视动画渲染-北京快渲科技有限公司 | 北京浩云律师事务所-法律顾问_企业法务_律师顾问_公司顾问 | 蚂蚁分类信息系统 - PHP同城分类信息系统 - MayiCMS | 伶俐嫂培训学校_月嫂培训班在哪里报名学费是多少_月嫂免费政府培训中心推荐 | 国际线缆连接网 - 连接器_线缆线束加工行业门户网站 | 巨野电机维修-水泵维修-巨野县飞宇机电维修有限公司 | 保镖公司-私人保镖-深圳保镖公司【环宇兄弟保镖】 | 防腐储罐_塑料储罐_PE储罐厂家_淄博富邦滚塑防腐设备科技有限公司 | 冷凝锅炉_燃气锅炉_工业燃气锅炉改造厂家-北京科诺锅炉 | 防爆暖风机_防爆电暖器_防爆电暖风机_防爆电热油汀_南阳市中通智能科技集团有限公司 | 客服外包专业服务商_客服外包中心_网萌科技 | 硬质合金模具_硬质合金非标定制_硬面加工「生产厂家」-西迪技术股份有限公司 | 电动卫生级调节阀,电动防爆球阀,电动软密封蝶阀,气动高压球阀,气动对夹蝶阀,气动V型调节球阀-上海川沪阀门有限公司 | 一体式钢筋扫描仪-楼板测厚仪-裂缝检测仪-泰仕特(北京) | 等离子表面处理机-等离子表面活化机-真空等离子清洗机-深圳市东信高科自动化设备有限公司 | 许昌奥仕达自动化设备有限公司 |