【问题标题】:Gulp concat plugins errorGulp concat插件错误
【发布时间】:2018-02-25 07:57:12
【问题描述】:

我正在使用 gulp 将我的插件(bootstrap、jquery 等)合并到一个大文件中,这是我的代码:

const gulp = require('gulp');
const csso = require('gulp-csso');
const concat = require('gulp-concat');
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');

gulp.task('build', function() {

gulp.src(["./bower_components/bootstrap/dist/css/bootstrap.min.css", 
         "./bower_components/ekko-lightbox/dist/ekko-lightbox.css",
         "./bower_components/owl.carousel/dist/assets/owl.carousel.min.css",
         "./bower_components/owl.carousel/dist/assets/owl.theme.default.css",
         "./client/css/core.css",
         "./client/css/responsive.css"])
.pipe(csso())
.pipe(concat("main.css"))
.pipe(gulp.dest("./build"));

gulp.src(["./bower_components/jquery/dist/jquery.js",
          "./bower_components/bootstrap/dist/js/bootstrap.bundle.js",
          "./bower_components/ekko-lightbox/dist/ekko-lightbox.min.js",
          "./bower_components/lazysizes/lazysizes.min.js",
          "./bower_components/owl.carousel/dist/owl.carousel.min.js",
          "./bower_components/moment/min/moment.min.js",
          "./bower_components/moment/min/locales.min.js",
          "./client/js/script.js" ])    
.pipe(babel({
        presets: ['es2015']
    }))
.pipe(uglify())
.pipe(concat("main.js"))
.pipe(gulp.dest('./build'));

});

而且一切正常。但是当我在我的项目中包含这个脚本时,控制台会抛出我的错误:Uncaught TypeError: Cannot set property 'bootstrap' of undefined。 我尝试在没有es2015uglify 的情况下连接它,但这个错误(或另一个,如moment is not defined)仍然存在。我做错了什么?

【问题讨论】:

    标签: javascript css gulp


    【解决方案1】:

    好的,我知道了。

    npm install --save-dev babel-plugin-proposal-object-rest-spread
    npm install --save-dev babel-plugin-transform-object-rest-spread
    

    然后管道

    .pipe(babel({
        presets: [['env', {
            loose: true,
            modules: false,
            exclude: ['transform-es2015-typeof-symbol']
        }]],
        plugins: ['transform-es2015-modules-strip', 'transform-object-rest-spread']
    }))
    

    它有效

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      相关资源
      最近更新 更多