简体   繁体   中英

Gulp - publish vendors to folder

For all JS code I have I minify and uglify before build my project to production.

var config =
{
    dest: 'www',
    vendor:
    [
        './node_modules/jquery/dist/jquery.js',

        './node_modules/angular/angular.js',
        './node_modules/motion-ui/dist/motion-ui.js',
        './node_modules/angular-animate/angular-animate.js',
        './node_modules/angular-sanitize/angular-sanitize.js',
        './node_modules/angular-ui-router/release/angular-ui-router.js',
        './node_modules/angular-translate/dist/angular-translate.js',
        './node_modules/angular-translate-loader-static-files/angular-translate-loader-static-files.js',

        './src/vendors/tinymce/tinymce.js',
        './src/vendors/tinymce/ui-tinymce.js',

        './src/vendors/googleMaps/js/ui-googleMaps.js',
        './src/vendors/googleMaps/js/ui-mapUpload.js',
        './src/vendors/LocationPicker/locationpicker-jquery.js',

        './src/vendors/rzslider/rzslider.js',
        './src/vendors/cropit/jquery.cropit.js',
    ]
};

gulp.task('js', function ()
{
    streamqueue({ objectMode: true },
        gulp.src(config.vendor.js),          
      gulp.src('./src/appConfig.js').pipe(ngFilesort()),
      gulp.src('./src/features/**/*.js').pipe(ngFilesort()),
      gulp.src('./src/modules/**/*.js').pipe(ngFilesort()),
      gulp.src('./src/assets/js/**/*.js').pipe(ngFilesort())
    )
    .pipe(sourcemaps.init())
    .pipe(concat('app.js'))
    .pipe(ngAnnotate())

    .pipe(uglify())

    .pipe(rename({ suffix: '.min' }))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest(path.join(config.dest, 'js')));    
});

But I noticed some plugins are reading specific paths for their CSS and font files, like TinyMCE (tinymce.js code):

n = n ? e.documentBaseURI.toAbsolute(n) : tinymce.baseURL + "/skins/" + i, t.skinUiCss = tinymce.Env.documentMode <= 7 ? n + "/skin.ie7.min.css" : n + "/skin.min.css", e.contentCSS.push(n + "/content" + (e.inline ? ".inline" : "") + ".min.css")

To handling with those cases I'm running a gulp task to copy the files/folders to specific path I defined:

var config =
{
    //...

    vendorNotMinified:
    {
        src: [
            './src/vendors/tinymce/skins'
        ],
        dest: [
            '/plugins/tinymce/'
        ]
    }
};

gulp.task('vendors', function ()
{
    for (var i = 0; i < config.vendorNotMinified.length; i++)    
        gulp.src(config.vendorNotMinified.src[i])
            .pipe(gulp.dest(config.dest + config.vendorNotMinified.dest[i]));
});

But my vendors task isn't creating the plugins folder.

Where is the problem and how can I solve this with a dynamic way?

Note: I already changed TinyMCE line to this:

n = "./plugins/tinymce/skins/" + i, t.skinUiCss = tinymce.Env.documentMode <= 7 ? n + "/skin.ie7.min.css" : n + "/skin.min.css", e.contentCSS.push(n + "/content" + (e.inline ? ".inline" : "") + ".min.css")

Solved! The problem is on the loop for on it's condition to running the loop. So I changed my task code to this and now works:

gulp.task('vendors', function (done)
{    
    for (var i = 0; i < config.vendorNotMinified.src.length; i++)    
        gulp.src(config.vendorNotMinified.src[i])
            .pipe(gulp.dest(config.dest + config.vendorNotMinified.dest[i]));

    return gulp.src(config.vendorNotMinified.src);
});

I needed to return gulp.src() because like Sindre Sorhus said in this post this is needed to make task async.

For copy all files and folders correctly I needed to add another paths to my config.vendorNotMinified :

var config =
{
    //...
    vendorNotMinified:
    {
        src: [
            './src/vendors/tinymce/skins',
            './src/vendors/tinymce/skins/**'
        ],
        dest: [
            '/plugins/tinymce/',
            '/plugins/tinymce/skins/'
        ]
    },
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM