Concatenate imports in modules in babeljs

爱⌒轻易说出口 提交于 2019-12-22 14:04:47

问题


I am new to all ES6 transpiling and I was planning on using BabelJS.

Is there a way to concatenate scripts with there imports in babelJS

I have the following

home.js imports home/home-navbar and home/home-slider

I want the output to contain both home/home-navbar and home/home-slider but put them all in one file home.js

Can I do this in BabelJS? and if not what would be the proper way to do it?


回答1:


Can I do this in BabelJS?

No, not yet.

what would the proper way to do it?

Not sure about the proper way, but there are alternatives. Tools like browserify and esperanto compute module dependencies and bundle them into a single files (or multiple if desired).

Depending on your specific use case you could also write a simple script that concatenates all files.




回答2:


Babel runs in the client, and it doesn't actually alter system files, which you would need a server for.

If you want to share resources, you can always transport objects via the shared window object

class MyClass {
    constructor (config) {
        super(config);
        this.config = config;
    }
}

window.MyClass = MyClass;

var MyClass = window.MyClass;

class ExtendedClass extends MyClass {
    constructor (config) {
        super(config);
        console.log(this.config); // from MyClass
    }
}


来源:https://stackoverflow.com/questions/31015250/concatenate-imports-in-modules-in-babeljs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!