Concatenate bower components with gulp

0

Good afternoon everyone,

I have a problem trying to concatenate all my bower components in a single file called vendor.js.

This is my gulp task:

gulp.task('bower', function() {
    var jsFilter = gulpFilter('**/*.js', {
        restore: true
    })
    var cssFilter = gulpFilter('**/*.css', {
        restore: true
    })
    return gulp.src(bower(), {
            base: 'bower_components'
        })
        .pipe(jsFilter)
        .pipe(order([
            "bower_components/jquery/**/*.js",
            "bower_components/angular/**/*.js",
            "bower_components/moment/**/*.js",
            "bower_components/**/*.js"
        ], {
            base: './'
        }))
        /*.pipe(babel({
            presets: ['es2015']
        }))*/
        .pipe(concat('vendor.js'))
        .pipe(gulp.dest(dist.js))
        .pipe(jsFilter.restore)
        .pipe(cssFilter)
        .pipe(concat('vendor.css'))
        .pipe(gulp.dest(dist.css))
        .pipe(cssFilter.restore)
        .pipe(rename(function(path) {
            if (~path.dirname.indexOf('fonts')) {
                path.dirname = '/fonts'
            }
        }))
        .pipe(gulp.dest(dist.vendor))
})

When I run I receive the following error:

Uncaught ReferenceError: require is not defined

To solve the error as you see, in the commented line I tried to port to ES5 with babel, but if it is not an error it throws me another one.

How do you manage to combine all the components in a css and js file without errors? Is this crazy? My goal is not to have to include each and every one of the bower components by hand.

    
asked by 50l3r 20.04.2017 в 21:26
source

1 answer

0

I believe that your problem is in the part where you define your require, that is to say to use a plugin of gulp, gulp must be installed and also the plugin, if you are detecting the require it is because either you lack something in its syntax or you do not have installed gulp or any plugin of it, I recommend you edit and put all your gulpfile.js

    
answered by 28.04.2017 в 19:02