0

我在我的应用程序中这样做

System.import('lib/bootstrap.js').then(m => {
   this.socket = m.io("http://localhost:3000");
})

这是bootstrap.js

import io from 'socket.io-client';
export { io };

我通过jspm bundle lib/bootstrap.js outfile.js.

当我尝试System.import('outfile.js')解决的 Promisem只是一个空对象。我在这里做错了什么?

System.import('outfile.js').then(m => {
   this.socket = m.io("http://localhost:3000");
})
4

1 回答 1

1

您不想导入捆绑的文件。您需要做的是将捆绑配置注入到您的config.js文件中。例如添加jspm bundle lib/bootstrap bootstrap-bundle.js --inject将添加

"bundles": {
    "bootstrap-bundle": [
    "socket.io-client.js",
    "lib/bootstrap.js"
  ]
}

到您的 config.js 文件。然后你只需要像往常一样导入你的文件:

System.import('lib/bootstrap.js').then(m => {
   this.socket = m.io("http://localhost:3000");
})

请参阅此处的文档

于 2015-12-17T08:50:07.453 回答