SystemJS Builder + Babel issue

SystemJS Builder + Babel issue

本文关键字:issue Babel Builder SystemJS      更新时间:2023-09-26

我正在尝试SystemJS,并在尝试将构建器与babel一起使用时遇到问题。

这是一个简单的ES2015项目,所以不会让你厌烦它的细节,但我的捆绑设置如下所示。

配置.js:

System.config({
    transpiler: 'babel',
    paths: {
        'babel': './node_modules/babel-core/lib/api/browser.js'
    }
});

建造者.js:

var path = require("path");
var Builder = require('systemjs-builder');
var builder = new Builder('.', 'config.js');
builder
    .buildStatic('./src/app.js', './dist/index.js')
    .then(function() {
        console.log('Build complete');
    })
    .catch(function(err) {
        console.log('Build error');
        console.log(err);
    });

我收到以下错误:ReferenceError: require is not defined babel 的browser.js文件。在添加 babel 路径之前,我收到一个错误,即 SystemJS 试图相对于我的源目录定位babel.js

我显然在这里错过了一些简单的东西,但文档并不完全直截了当,而且在 babel 方面似乎有点过时了。在与 SystemJS 捆绑之前,我是否需要在文件上运行 babel 以便 require 可用或其他什么?

对此并不乐观,因为我使用 jspm,所以我不必手动设置它,但看起来 babel-core 的正确主文件是 ./node_modules/babel-core/browser.js 它具有"格式全局"; 而不是"格式化 cjs"; 这将解释您的错误。