捆绑时的 jspm 预处理(为目标环境注入设置)

jspm preprocessing (injecting settings for the targeted environment) when bundling

有没有办法在使用 buildStatic 进行捆绑时预处理 .js 文件(即注入环境特定设置)?

我不知道在捆绑期间预处理 js 文件的方法,但您可以针对不同的环境使用不同的 files/modules,并使用 JS API 将您的开发版本与生产版本交换一:

gulp.task('jspm', function() {
  var builder = new jspm.Builder();

  function production(builder) {
    var systemNormalize = builder.loader.normalize;
    builder.loader.normalize = function(name, parentName, parentAddress) {
      if (name === 'ember') name = 'ember/ember.prod';
      if (name === './app-config.dev') name = './app-config.prod';

      return systemNormalize.call(this, name, parentName, parentAddress);
    };
  }

  production(builder);

  return builder.loadConfig('./config.js')
    .then(function() {
      return builder.buildStatic('app/main', 'dist/app.min.js', { sourceMaps: false, minify: false, mangle: false});
    });
});

app-config.dev.js 和 app-config.prod.js 是您在整个应用程序中使用的模块,它们提供特定于环境的设置。在您的代码中,您应该始终导入 app-config.dev。在我的博客 post 中阅读有关此工作流程的更多信息:How to Use SystemJS Hooks for Building a Production Version of Your App