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

    <bdo id='gqCjx'></bdo><ul id='gqCjx'></ul>

      <legend id='gqCjx'><style id='gqCjx'><dir id='gqCjx'><q id='gqCjx'></q></dir></style></legend>
      <i id='gqCjx'><tr id='gqCjx'><dt id='gqCjx'><q id='gqCjx'><span id='gqCjx'><b id='gqCjx'><form id='gqCjx'><ins id='gqCjx'></ins><ul id='gqCjx'></ul><sub id='gqCjx'></sub></form><legend id='gqCjx'></legend><bdo id='gqCjx'><pre id='gqCjx'><center id='gqCjx'></center></pre></bdo></b><th id='gqCjx'></th></span></q></dt></tr></i><div class="20kck0i" id='gqCjx'><tfoot id='gqCjx'></tfoot><dl id='gqCjx'><fieldset id='gqCjx'></fieldset></dl></div>

      <tfoot id='gqCjx'></tfoot>

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

    1. 增量 gulp 少構(gòu)建

      Incremental gulp less build(增量 gulp 少構(gòu)建)
      • <legend id='Gs5yr'><style id='Gs5yr'><dir id='Gs5yr'><q id='Gs5yr'></q></dir></style></legend>
            <tbody id='Gs5yr'></tbody>
        1. <i id='Gs5yr'><tr id='Gs5yr'><dt id='Gs5yr'><q id='Gs5yr'><span id='Gs5yr'><b id='Gs5yr'><form id='Gs5yr'><ins id='Gs5yr'></ins><ul id='Gs5yr'></ul><sub id='Gs5yr'></sub></form><legend id='Gs5yr'></legend><bdo id='Gs5yr'><pre id='Gs5yr'><center id='Gs5yr'></center></pre></bdo></b><th id='Gs5yr'></th></span></q></dt></tr></i><div class="y0e222y" id='Gs5yr'><tfoot id='Gs5yr'></tfoot><dl id='Gs5yr'><fieldset id='Gs5yr'></fieldset></dl></div>
          <tfoot id='Gs5yr'></tfoot>

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

                <bdo id='Gs5yr'></bdo><ul id='Gs5yr'></ul>
                本文介紹了增量 gulp 少構(gòu)建的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                限時(shí)送ChatGPT賬號..

                在我的辦公室里,我們正在使用 gulp 來構(gòu)建我們的 less 文件.我想改進(jìn)構(gòu)建任務(wù),因?yàn)樵谖覀冏罱鼜氖碌囊粋€(gè)大型項(xiàng)目上構(gòu)建需要花費(fèi)一秒鐘的時(shí)間.這個(gè)想法是緩存文件并只傳遞更改的文件.所以我從 google 開始,發(fā)現(xiàn) javascript 的增量構(gòu)建我認(rèn)為用更少的錢重寫它們很容易.這是我開始的一個(gè):https://github.com/gulpjs/gulp/blob/master/docs/recipes/incremental-builds-with-concatenate.md

                In my office we are using gulp to build our less files. I wanted to improve the build task as it took over a second to build on a large project we recently worked on. The idea was to cache the files and only pass the one that changed. So I started with google and found incremental builds for javascript ang thought it would be easy to rewrite them for less. Here's the one I started with: https://github.com/gulpjs/gulp/blob/master/docs/recipes/incremental-builds-with-concatenate.md

                經(jīng)過幾次不成功的嘗試后,我最終得到了以下代碼(使用最新的引導(dǎo)發(fā)行版進(jìn)行了測試):

                After a few unsuccessful tries I ended up with following code (tested with the latest bootstrap distribution):

                var gulp            = require('gulp');
                var less            = require('gulp-less');
                var concat          = require('gulp-concat');
                var remember        = require('gulp-remember');
                var cached          = require('gulp-cached');
                
                var fileGlob = [
                    './bootstrap/**/*.less',
                    '!./bootstrap/bootstrap.less',
                    '!./bootstrap/mixins.less'
                ];
                
                gulp.task('less', function () {
                    return gulp.src(fileGlob)
                        .pipe(cached('lessFiles'))
                        .pipe(remember('lessFiles'))
                        .pipe(less())
                        .pipe(gulp.dest('output'));
                });
                
                gulp.task('watch', function () {
                    var watcher = gulp.watch(fileGlob, ['less']);
                    watcher.on('change', function (e) {
                        if (e.type === 'deleted') {
                            delete cached.caches.scripts[e.path];
                            remember.forget('lessFiles', e.path);
                        }
                    });
                });
                

                但這只會(huì)傳遞更改的文件,并且由于缺少變量定義,less 編譯器會(huì)失敗.如果我在 less 任務(wù)之前通過管道連接 concat 插件,gulp 會(huì)陷入(看似)無限循環(huán).

                But this passes only the changed file and the less compiler fails because of the variable definitions missing. If I pipe the concat plugin before the less task, gulp gets stuck in a (seemingly) endless loop.

                gulp.task('less', function () {
                    return gulp.src(fileGlob)
                        .pipe(cached('lessFiles'))
                        .pipe(remember('lessFiles'))
                        .pipe(concat('main.less')
                        .pipe(less())
                        .pipe(gulp.dest('output'));
                });
                

                有沒有人使用過這些插件或設(shè)法以其他方式創(chuàng)建增量更少的構(gòu)建.這是一個(gè)用于測試的(雜亂的)github存儲(chǔ)庫:https://github.com/tuelsch/perfect-less-build

                Has anyone experience with those plugins or managed to create an incremental less build in an other way. Here is a (messy) github repository for testing: https://github.com/tuelsch/perfect-less-build

                PS:我計(jì)劃添加 linting、sourcemaps、minification、evtl.稍后緩存清除和自動(dòng)前綴.

                PS: I'm planning on adding linting, sourcemaps, minification, evtl. cache busting and autoprefixer later on.

                推薦答案

                和 Ashwell 一樣,我發(fā)現(xiàn)使用導(dǎo)入來確保我的所有 LESS 文件都可以訪問他們需要的變量和 mixin 很有用.我還使用帶有導(dǎo)入的 LESS 文件來進(jìn)行捆綁.這有幾個(gè)優(yōu)點(diǎn):

                Like Ashwell, I've found it useful to use imports to ensure that all my LESS files have access to the variables and mixins that they need. I also use a LESS file with imports for bundling purposes. This has a few advantages:

                1. 我可以利用 LESS 的功能來執(zhí)行復(fù)雜的操作,例如覆蓋變量值以生成多個(gè)主題,或者為另一個(gè) LESS 文件中的每個(gè)規(guī)則添加一個(gè)類.
                2. 不需要 concat 插件.
                3. Web Essentials for Visual Studio 等工具可以提供語法幫助和輸出預(yù)覽,因?yàn)槊總€(gè) LESS 文件都完全能夠自行呈現(xiàn).

                如果你想導(dǎo)入變量、mixins等,但又不想實(shí)際輸出另一個(gè)文件的全部內(nèi)容,你可以使用:

                Where you want to import variables, mixins, etc, but you don't want to actually output the entire contents of another file, you can use:

                @import (reference) "_colors.less";
                

                經(jīng)過幾天的努力,我終于能夠獲得一個(gè)增量構(gòu)建,它可以正確地重建依賴于我更改的 LESS 文件的所有對象.我在這里記錄了結(jié)果.這是最終的 gulpfile:

                After a few days of effort, I was finally able to get an incremental build that correctly rebuilds all the objects that depend on the LESS file I changed. I documented the results here. This is the final gulpfile:

                /*
                 * This file defines how our static resources get built.
                 * From the StaticCommon root folder, call "gulp" to compile all generated
                 * client-side resources, or call "gulp watch" to keep checking source 
                 * files, and rebuild them whenever they are changed. Call "gulp live" to 
                 * do both (build and watch).
                 */
                
                /* Dependency definitions: in order to avoid forcing everyone to have 
                 * node/npm installed on their systems, we are including all of the 
                 * necessary dependencies in the node_modules folder. To install new ones,
                 * you must install nodejs on your machine, and use the "npm install XXX" 
                 * command. */
                var gulp = require('gulp');
                var less = require('gulp-less');
                var LessPluginCleanCss = require('less-plugin-clean-css'),
                    cleanCss = new LessPluginCleanCss();
                var sourcemaps = require('gulp-sourcemaps');
                var rename = require('gulp-rename');
                var cache = require('gulp-cached');
                var progeny = require('gulp-progeny');
                var filter = require('gulp-filter');
                var plumber = require('gulp-plumber');
                var debug = require('gulp-debug');
                
                gulp.task('less', function() {
                    return gulp
                        // Even though some of our LESS files are just references, and 
                        // aren't built, we need to start by looking at all of them because 
                        // if any of them change, we may need to rebuild other less files.
                        .src(
                        ['Content/@(Theme|Areas|Css)/**/*.less'],
                        { base: 'Content' })
                        // This makes it so that errors are output to the console rather 
                        // than silently crashing the app.
                        .pipe(plumber({
                            errorHandler: function (err) {
                                console.log(err);
                                // And this makes it so "watch" can continue after an error.
                                this.emit('end');
                            }
                        }))
                        // When running in "watch" mode, the contents of these files will 
                        // be kept in an in-memory cache, and after the initial hit, we'll
                        // only rebuild when file contents change.
                        .pipe(cache('less'))
                        // This will build a dependency tree based on any @import 
                        // statements found by the given REGEX. If you change one file,
                        // we'll rebuild any other files that reference it.
                        .pipe(progeny({
                            regexp: /^s*@imports*(?:(w+)s*)?['"]([^'"]+)['"]/
                        }))
                        // Now that we've set up the dependency tree, we can filter out 
                        // any files whose
                        // file names start with an underscore (_)
                        .pipe(filter(['**/*.less', '!**/_*.less']))
                        // This will output the name of each LESS file that we're about 
                        // to rebuild.
                        .pipe(debug({ title: 'LESS' }))
                        // This starts capturing the line-numbers as we transform these 
                        // files, allowing us to output a source map for each LESS file 
                        // in the final stages.
                        // Browsers like Chrome can pick up those source maps and show you 
                        // the actual LESS source line that a given rule came from, 
                        // despite the source file's being transformed and minified.
                        .pipe(sourcemaps.init())
                        // Run the transformation from LESS to CSS
                        .pipe(less({
                            // Minify the CSS to get rid of extra space and most CSS
                            // comments.
                            plugins: [cleanCss]
                        }))
                        // We need a reliable way to indicate that the file was built
                        // with gulp, so we can ignore it in Mercurial commits.
                        // Lots of css libraries get distributed as .min.css files, so
                        // we don't want to exclude that pattern. Let's try .opt.css 
                        // instead.
                        .pipe(rename(function(path) {
                            path.extname = ".opt.css";
                        }))
                        // Now that we've captured all of our sourcemap mappings, add
                        // the source map comment at the bottom of each minified CSS 
                        // file, and output the *.css.map file to the same folder as 
                        // the original file.
                        .pipe(sourcemaps.write('.'))
                        // Write all these generated files back to the Content folder.
                        .pipe(gulp.dest('Content'));
                });
                
                // Keep an eye on any LESS files, and if they change then invoke the 
                // 'less' task.
                gulp.task('watch', function() {
                    return gulp.watch('Content/@(Theme|Areas|Css)/**/*.less', ['less']);
                });
                
                // Build things first, then keep a watch on any changed files.
                gulp.task('live', ['less', 'watch']);
                
                // This is the task that's run when you run "gulp" without any arguments.
                gulp.task('default', ['less']);
                

                我們現(xiàn)在可以簡單地運(yùn)行 gulp live 來構(gòu)建我們所有的 LESS 文件一次,然后允許每個(gè)后續(xù)更改只構(gòu)建依賴于已更改文件的那些文件.

                We can now simply run gulp live to build all our LESS files once, and then allow each subsequent change to just build those files that depend on the changed files.

                這篇關(guān)于增量 gulp 少構(gòu)建的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(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ù))
                Stylesheet not loaded because of MIME-type(由于 MIME 類型而未加載樣式表)
                Visual Studio 2015 crashes when opening Javascript files(打開 Javascript 文件時(shí) Visual Studio 2015 崩潰)
                <legend id='vcvQX'><style id='vcvQX'><dir id='vcvQX'><q id='vcvQX'></q></dir></style></legend>

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

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

                      <tfoot id='vcvQX'></tfoot>

                            <tbody id='vcvQX'></tbody>

                        • 主站蜘蛛池模板: 河南不锈钢水箱_地埋水箱_镀锌板水箱_消防水箱厂家-河南联固供水设备有限公司 | 展厅设计-展馆设计-专业企业展厅展馆设计公司-昆明华文创意 | 定制奶茶纸杯_定制豆浆杯_广东纸杯厂_[绿保佳]一家专业生产纸杯碗的厂家 | 柔软云母板-硬质-水位计云母片组件-首页-武汉长丰云母绝缘材料有限公司 | HYDAC过滤器,HYDAC滤芯,现货ATOS油泵,ATOS比例阀-东莞市广联自动化科技有限公司 | 行星齿轮减速机,减速机厂家,山东减速机-淄博兴江机械制造 | 合肥升降机-合肥升降货梯-安徽升降平台「厂家直销」-安徽鼎升自动化科技有限公司 | 无水硫酸铝,硫酸铝厂家-淄博双赢新材料科技有限公司 | 安规_综合测试仪,电器安全性能综合测试仪,低压母线槽安规综合测试仪-青岛合众电子有限公司 | 承插管件_不锈钢承插管件_锻钢高压管件-温州科正阀门管件有限公司 | 苏州西装定制-西服定制厂家-职业装定制厂家-尺品服饰西装定做公司 | 月嫂_保姆_育婴_催乳_母婴护理_产后康复_养老护理-吉祥到家家政 硫酸亚铁-聚合硫酸铁-除氟除磷剂-复合碳源-污水处理药剂厂家—长隆科技 | 交流伺服电机|直流伺服|伺服驱动器|伺服电机-深圳市华科星电气有限公司 | 一体化污水处理设备-一体化净水设备-「山东梦之洁水处理」 | CPSE安博会| 哈尔滨治「失眠/抑郁/焦虑症/精神心理」专科医院排行榜-京科脑康免费咨询 一对一诊疗 | 打孔器,打孔钳厂家【温州新星德牌五金工具】 | 不锈钢水箱厂家,不锈钢保温水箱-山东桑特供水设备 | 南京雕塑制作厂家-不锈钢雕塑制作-玻璃钢雕塑制作-先登雕塑厂 | ALC墙板_ALC轻质隔墙板_隔音防火墙板_轻质隔墙材料-湖北博悦佳 | 洁净化验室净化工程_成都实验室装修设计施工_四川华锐净化公司 | 灌装封尾机_胶水灌装机_软管灌装封尾机_无锡和博自动化机械制造有限公司 | 爆破器材运输车|烟花爆竹运输车|1-9类危险品厢式运输车|湖北江南专用特种汽车有限公司 | 天然鹅卵石滤料厂家-锰砂滤料-石英砂滤料-巩义东枫净水 | 丹佛斯变频器-丹佛斯压力开关-变送器-广州市风华机电设备有限公司 | YAGEO国巨电容|贴片电阻|电容价格|三星代理商-深圳市巨优电子有限公司 | 南京欧陆电气股份有限公司-风力发电机官网| 北京宣传片拍摄_产品宣传片拍摄_宣传片制作公司-现像传媒 | 高精度电阻回路测试仪-回路直流电阻测试仪-武汉特高压电力科技有限公司 | 车牌识别道闸_停车场收费系统_人脸识别考勤机_速通门闸机_充电桩厂家_中全清茂官网 | 防水试验机_防水测试设备_防水试验装置_淋雨试验箱-广州岳信试验设备有限公司 | 化妆品加工厂-化妆品加工-化妆品代加工-面膜加工-广东欧泉生化科技有限公司 | 智慧钢琴-电钢琴-便携钢琴-数码钢琴-深圳市特伦斯乐器有限公司 | 长沙网站建设制作「网站优化推广」-网页设计公司-速马科技官网 | 常州律师事务所_常州律所_常州律师-江苏乐天律师事务所 | 脉冲除尘器,除尘器厂家-淄博机械 | 注塑_注塑加工_注塑模具_塑胶模具_注塑加工厂家_深圳环科 | 山东led显示屏,山东led全彩显示屏,山东LED小间距屏,临沂全彩电子屏-山东亚泰视讯传媒有限公司 | 传动滚筒_厂家-淄博海恒机械制造厂 | 知网论文检测系统入口_论文查重免费查重_中国知网论文查询_学术不端检测系统 | 找培训机构_找学习课程_励普教育 |