我有非常简单的ES6代码(init.js
):
import App from '../vendor/app';
window.init = function() {
let app = new App();
app.hello(); // prints "hello" to console
}
app
模块(app.js
)是ES5之一,我不想修改此文件:
function App() {
}
App.prototype.hello = function() {
console.log('hello from vendor module');
}
上面的代码不起作用,因为我需要添加
export default App;
到app.js
的结尾。但我想保持供应商文件的清洁,尽可能不做任何修改。棘手的部分是app.js
取决于其他ES5模块,例如:
App.prototype.hello2 = function() {
dialog.show('hello from vendor app module, but using another vendor "dialog" module');
}
dialog
变量在ES5 dialog.js
中定义。
将脚本标记添加到html页面时效果很好。我也想避免这种情况。理想情况下,我只想修改init.js.使用某种导入,因此它会自动将所有供应商模块附加到我的init.js
。