首页 > System.js 使用gulp打包 什么方法可以让config中有bundles配置

System.js 使用gulp打包 什么方法可以让config中有bundles配置

var gulp = require('gulp');
var clean = require('gulp-clean');
var concat  = require('gulp-concat');
var uglify  = require('gulp-uglify');
var htmlreplace = require('gulp-html-replace');//页面替换
var jspm = require('jspm');

//清空dist
gulp.task('clean', function() {
    return gulp.src(['./dist'], {read: false})
        .pipe(clean({force: true}));
});

gulp.task('public',['clean'],function(){
    gulp.src('./public/**').pipe(gulp.dest('./dist/public'));
})

gulp.task('jspm',['public'],function(){
    jspm.setPackagePath('.');
    jspm.bundle('source/app','./dist/build.js',{
        sourceMaps:false,
        minify:true,

    }).then(function(){
        gulp.src([
            './jspm_packages/system.js',
            './config.js'
        ])
            .pipe(concat('system.min.js'))
            .pipe(uglify())
            .pipe(gulp.dest('./dist'))


        gulp.src('./public/index.html')
            .pipe(htmlreplace({
                system_js:'../system.min.js',
            }))
            .pipe(gulp.dest('./dist/public'))

        console.log('执行成功!');
    })
});

怎么让config.js有下面这个代码

  bundles: {
    "build.js": [
      "source/app.js",
      "npm:jquery@2.1.4",
      "github:angular/bower-angular@1.4.6",
      "source/core/core-module.js",
      "npm:jquery@2.1.4/dist/jquery",
      "source/service/ApiConfig.js",
      "source/env.js"
      ]
  }

已解决
打包使用 jspm.bundleSFX()方法

gulp.task('weixin',['weinxinclean'],function(){
    var v = new Date().getTime();
    console.log('开始任务');
    jspm.setPackagePath('./');
    console.log('设置包路径');
    jspm.bundleSFX('./source/app-weixin.js','./dist/weixin/weixin-'+v+'.js',{
        sourceMaps:false,
        minify:true
    }).then(function(){
        console.log('打包weixin.js完成');

        gulp.src('./public/index.html')
            .pipe(htmlreplace({
                app_js:{
                    src: null,
                    tpl: '<script src="/chat/dist/weixin/weixin-'+v+'.js">            </script>'
                }
            }))
            .pipe(gulp.dest('./dist/weixin'))

        console.log('执行成功!');
    })
});
【热门文章】
【热门文章】